getProducts(HttpServletRequest req) {
- SkeletonKeySession session = (SkeletonKeySession)req.getAttribute(SkeletonKeySession.class.getName());
- HttpClient client = new HttpClientBuilder()
- .trustStore(session.getMetadata().getTruststore())
- .hostnameVerification(HttpClientBuilder.HostnameVerificationPolicy.ANY).build();
- try {
- HttpGet get = new HttpGet("http://localhost:8080/database/products");
- get.addHeader("Authorization", "Bearer " + session.getTokenString());
- try {
- HttpResponse response = client.execute(get);
- HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- try {
- return JsonSerialization.readValue(is, TypedList.class);
- } finally {
- is.close();
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } finally {
- client.getConnectionManager().shutdown();
- }
- }
-
-}
diff --git a/examples/wildfly-demo/product-app/src/main/webapp/admin/admin.jsp b/examples/wildfly-demo/product-app/src/main/webapp/admin/admin.jsp
deleted file mode 100644
index b6448d7738..0000000000
--- a/examples/wildfly-demo/product-app/src/main/webapp/admin/admin.jsp
+++ /dev/null
@@ -1,11 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-
-
- Product Admin Interface
-
-
-Product Admin Interface
-User <%=request.getUserPrincipal().getName()%> made this request.
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/product-app/src/main/webapp/index.html b/examples/wildfly-demo/product-app/src/main/webapp/index.html
deleted file mode 100644
index e30ebc5c1c..0000000000
--- a/examples/wildfly-demo/product-app/src/main/webapp/index.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-Product Portal
-
-Product Listing
-Admin Interface
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/product-app/src/main/webapp/products/view.jsp b/examples/wildfly-demo/product-app/src/main/webapp/products/view.jsp
deleted file mode 100755
index f476872a99..0000000000
--- a/examples/wildfly-demo/product-app/src/main/webapp/products/view.jsp
+++ /dev/null
@@ -1,31 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-<%@ page import="org.keycloak.example.oauth.ProductDatabaseClient" %>
-<%@ page import="org.keycloak.util.KeycloakUriBuilder" %>
-
-
- Product View Page
-
-
-<%
- String logoutUri = KeycloakUriBuilder.fromUri("http://localhost:8080/auth/rest/realms/demo/tokens/logout")
- .queryParam("redirect_uri", "http://localhost:8080/product-portal").build().toString();
- String acctUri = "http://localhost:8080/auth/rest/realms/demo/account";
-%>
-
-Goto: customers | logout | manage acct
-User <%=request.getUserPrincipal().getName()%> made this request.
-Product Listing
-<%
-java.util.List list = ProductDatabaseClient.getProducts(request);
-for (String cust : list)
-{
- out.print("");
- out.print(cust);
- out.println("
");
-
-}
-%>
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party-cdi/pom.xml b/examples/wildfly-demo/third-party-cdi/pom.xml
deleted file mode 100755
index 27784e333d..0000000000
--- a/examples/wildfly-demo/third-party-cdi/pom.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
- keycloak-parent
- org.keycloak
- 1.0-alpha-1-SNAPSHOT
- ../../../pom.xml
-
- 4.0.0
- org.keycloak.example.wildfly.demo
- oauth-client-cdi-example
- war
- Simple OAuth Client Using CDI and JSF
-
-
-
-
- org.jboss.spec.javax.servlet
- jboss-servlet-api_3.0_spec
- 1.0.1.Final
- provided
-
-
- javax.enterprise
- cdi-api
- 1.0-SP4
- provided
-
-
- org.jboss.spec.javax.faces
- jboss-jsf-api_2.1_spec
- 2.0.1.Final
- provided
-
-
- org.jboss.logging
- jboss-logging
- 3.1.2.GA
- provided
-
-
- org.keycloak
- keycloak-servlet-oauth-client
- ${project.version}
-
-
-
-
- oauth-client-cdi
-
-
- org.jboss.as.plugins
- jboss-as-maven-plugin
- 7.4.Final
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
- true
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 1.6
- 1.6
-
-
-
-
-
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java
deleted file mode 100644
index f84019e530..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.keycloak.example.oauth;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.annotation.WebListener;
-
-import org.jboss.logging.Logger;
-import org.keycloak.servlet.ServletOAuthClient;
-import org.keycloak.servlet.ServletOAuthClientConfigLoader;
-
-/**
- * @author Marek Posolda
- */
-@WebListener
-public class AppContextListener implements ServletContextListener {
-
- private static final Logger logger = Logger.getLogger(AppContextListener.class);
-
- @Inject
- private ServletOAuthClient oauthClient;
-
- @Override
- public void contextInitialized(ServletContextEvent sce) {
- ServletContext context = sce.getServletContext();
-
- InputStream is = null;
- String path = context.getInitParameter("keycloak.config.file");
- if (path == null) {
- is = context.getResourceAsStream("/WEB-INF/keycloak.json");
- } else {
- try {
- is = new FileInputStream(path);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- ServletOAuthClientConfigLoader loader = new ServletOAuthClientConfigLoader(is);
- loader.initOAuthClientConfiguration(true);
- loader.configureServletOAuthClient(oauthClient);
-
- oauthClient.start();
- logger.info("OAuth client configured and started");
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent sce) {
- oauthClient.stop();
- logger.info("OAuth client stopped");
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/CDIResourcesProducer.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/CDIResourcesProducer.java
deleted file mode 100644
index fd5e45843e..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/CDIResourcesProducer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.keycloak.example.oauth;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.inject.Produces;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.keycloak.servlet.ServletOAuthClient;
-
-/**
- * @author Marek Posolda
- */
-public class CDIResourcesProducer {
-
- @Produces
- @RequestScoped
- public FacesContext produceFacesContext() {
- return FacesContext.getCurrentInstance();
- }
-
- @Produces
- @RequestScoped
- @ServletRequestQualifier
- public HttpServletRequest produceServletRequest() {
- return (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
- }
-
- @Produces
- @RequestScoped
- public HttpServletResponse produceServletResponse() {
- return (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
- }
-
- @Produces
- @ApplicationScoped
- public ServletOAuthClient produceOAuthClient() {
- return new ServletOAuthClient();
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java
deleted file mode 100755
index 17f7fd2832..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.keycloak.example.oauth;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.jboss.logging.Logger;
-import org.keycloak.adapters.TokenGrantRequest;
-import org.keycloak.servlet.ServletOAuthClient;
-import org.keycloak.util.JsonSerialization;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Bill Burke
- * @author Marek Posolda
- * @version $Revision: 1 $
- */
-@ApplicationScoped
-@Named("databaseClient")
-public class DatabaseClient {
-
- @Inject
- @ServletRequestQualifier
- private HttpServletRequest request;
-
- @Inject
- private HttpServletResponse response;
-
- @Inject
- private FacesContext facesContext;
-
- @Inject
- private ServletOAuthClient oauthClient;
-
- @Inject
- private UserData userData;
-
- private static final Logger logger = Logger.getLogger(DatabaseClient.class);
-
- public void retrieveAccessToken() {
- try {
- oauthClient.redirectRelative("client.jsf", request, response);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- static class TypedList extends ArrayList {}
-
- public void sendCustomersRequest() {
- List customers = sendRequestToDBApplication("http://localhost:8080/database/customers");
- userData.setCustomers(customers);
- }
-
- public void sendProductsRequest() {
- List products = sendRequestToDBApplication("http://localhost:8080/database/products");
- userData.setProducts(products);
- }
-
- protected List sendRequestToDBApplication(String dbUri) {
- HttpClient client = oauthClient.getClient();
- HttpGet get = new HttpGet(dbUri);
- try {
-
- if (userData.isHasAccessToken()) {
- get.addHeader("Authorization", "Bearer " + userData.getAccessToken());
- }
-
- HttpResponse response = client.execute(get);
- switch (response.getStatusLine().getStatusCode()) {
- case 200: HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- try {
- return JsonSerialization.readValue(is, TypedList.class);
- } finally {
- is.close();
- }
- case 401: facesContext.addMessage(null, new FacesMessage("Status: 401. Request not authenticated! You need to retrieve access token first."));
- break;
- case 403: facesContext.addMessage(null, new FacesMessage("Status: 403. Access token has insufficient privileges"));
- break;
- default: facesContext.addMessage(null, new FacesMessage("Status: " + response.getStatusLine() + ". Not able to retrieve data. See log for details"));
- logger.warn("Error occured. Status: " + response.getStatusLine());
- }
-
- return null;
- } catch (IOException e) {
- e.printStackTrace();
- facesContext.addMessage(null, new FacesMessage("Unknown error. See log for details"));
- return null;
- }
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/MessagesChecker.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/MessagesChecker.java
deleted file mode 100644
index e59864f5bf..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/MessagesChecker.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.keycloak.example.oauth;
-
-import javax.enterprise.context.RequestScoped;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * This is needed because Faces context is not available in HTTP filters
- *
- * @author Marek Posolda
- */
-@RequestScoped
-@Named("messagesChecker")
-public class MessagesChecker {
-
- @Inject
- @ServletRequestQualifier
- private HttpServletRequest request;
-
- @Inject
- private FacesContext facesContext;
-
- public String getCheckMessage() {
- String oauthError = (String)request.getAttribute(RefreshTokenFilter.OAUTH_ERROR_ATTR);
- if (oauthError != null) {
- facesContext.addMessage(null, new FacesMessage("OAuth error occured: " + oauthError));
- }
-
- return null;
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/RefreshTokenFilter.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/RefreshTokenFilter.java
deleted file mode 100644
index 7467959298..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/RefreshTokenFilter.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.keycloak.example.oauth;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.annotation.WebFilter;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.keycloak.adapters.TokenGrantRequest;
-import org.keycloak.servlet.ServletOAuthClient;
-
-/**
- * @author Marek Posolda
- */
-@WebFilter(value = "/client.jsf")
-public class RefreshTokenFilter implements Filter {
-
- public static final String OAUTH_ERROR_ATTR = "oauthErrorAttr";
-
- @Inject
- private ServletOAuthClient oauthClient;
-
- @Inject
- private UserData userData;
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- }
-
- @Override
- public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest)req;
- HttpServletResponse response = (HttpServletResponse)resp;
- Map reqParams = request.getParameterMap();
-
- if (reqParams.containsKey("code")) {
- try {
- String accessToken = oauthClient.getBearerToken(request);
- userData.setAccessToken(accessToken);
- } catch (TokenGrantRequest.HttpFailure e) {
- throw new ServletException(e);
- }
- } else if (reqParams.containsKey("error")) {
- String oauthError = reqParams.get("error")[0];
- request.setAttribute(OAUTH_ERROR_ATTR, oauthError);
- }
-
- chain.doFilter(request, response);
- }
-
- @Override
- public void destroy() {
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/ServletRequestQualifier.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/ServletRequestQualifier.java
deleted file mode 100644
index 5f7edca722..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/ServletRequestQualifier.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.keycloak.example.oauth;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * This is needed to have same code working in AS7 and Wildfly. In Wildfly is HttpServletRequest injected automatically, in AS7 it's not
- *
- * @author Marek Posolda
- */
-@Qualifier
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ServletRequestQualifier {
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/UserData.java b/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/UserData.java
deleted file mode 100644
index 6571b18f3a..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/java/org/keycloak/example/oauth/UserData.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.keycloak.example.oauth;
-
-import java.io.Serializable;
-import java.util.List;
-
-import javax.enterprise.context.SessionScoped;
-import javax.inject.Named;
-
-/**
- * @author Marek Posolda
- */
-@SessionScoped
-@Named("userData")
-public class UserData implements Serializable {
-
- private String accessToken;
- private List products;
- private List customers;
-
- public String getAccessToken() {
- return accessToken;
- }
-
- public void setAccessToken(String accessToken) {
- this.accessToken = accessToken;
- }
-
- public boolean isHasAccessToken() {
- return accessToken != null;
- }
-
- public String getAccessTokenAvailabilityMessage() {
- StringBuilder builder = new StringBuilder("Access token ");
- if (!isHasAccessToken()) {
- builder.append("not ");
- }
- return builder.append("available!").toString();
- }
-
- public List getProducts() {
- return products;
- }
-
- public void setProducts(List products) {
- this.products = products;
- }
-
- public boolean isHasProducts() {
- return products != null;
- }
-
- public List getCustomers() {
- return customers;
- }
-
- public void setCustomers(List customers) {
- this.customers = customers;
- }
-
- public boolean isHasCustomers() {
- return customers != null;
- }
-}
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/beans.xml b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/beans.xml
deleted file mode 100644
index c4feade019..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/beans.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/faces-config.xml b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/faces-config.xml
deleted file mode 100644
index 10787a09a9..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/faces-config.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
deleted file mode 100755
index c54e4abec6..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/web.xml b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/web.xml
deleted file mode 100755
index 93e1ef63c4..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- oauth-client-cdi
-
-
-
-
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/client.xhtml b/examples/wildfly-demo/third-party-cdi/src/main/webapp/client.xhtml
deleted file mode 100644
index 7c4a8dd7c2..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/client.xhtml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
- Third Party App That Pulls Data Using OAuth
-
- #{userData.accessTokenAvailabilityMessage}
-
-
-
-
-
-
-
-
- Products data available
-
- #{product}
-
-
-
-
-
- Customers data available
-
- #{customer}
-
-
-
-
- #{messagesChecker.checkMessage}
-
-
-
-
diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/index.html b/examples/wildfly-demo/third-party-cdi/src/main/webapp/index.html
deleted file mode 100644
index 7b641f77fd..0000000000
--- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/index.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party/pom.xml b/examples/wildfly-demo/third-party/pom.xml
deleted file mode 100755
index b708b835a2..0000000000
--- a/examples/wildfly-demo/third-party/pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
- keycloak-parent
- org.keycloak
- 1.0-alpha-1-SNAPSHOT
- ../../../pom.xml
-
- 4.0.0
- org.keycloak.example.wildfly.demo
- oauth-client-example
- war
- Simple OAuth Client
-
-
-
-
- org.jboss.spec.javax.servlet
- jboss-servlet-api_3.0_spec
- 1.0.1.Final
- provided
-
-
- org.keycloak
- keycloak-servlet-oauth-client
- ${project.version}
-
-
-
-
- oauth-client
-
-
- org.jboss.as.plugins
- jboss-as-maven-plugin
- 7.4.Final
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
- true
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 1.6
- 1.6
-
-
-
-
-
diff --git a/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/Bootstrap.java b/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/Bootstrap.java
deleted file mode 100755
index 7b8bec2a16..0000000000
--- a/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/Bootstrap.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.keycloak.example.oauth;
-
-import org.keycloak.servlet.ServletOAuthClient;
-import org.keycloak.servlet.ServletOAuthClientConfigLoader;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.security.KeyStore;
-
-/**
- * Init code to load up the truststore so we can make appropriate SSL connections
- * You really should use a better way of initializing this stuff.
- *
- * @author Bill Burke
- * @version $Revision: 1 $
- */
-public class Bootstrap implements ServletContextListener {
-
- private ServletOAuthClient client;
-
- private static KeyStore loadKeyStore(String filename, String password) throws Exception {
- KeyStore trustStore = KeyStore.getInstance(KeyStore
- .getDefaultType());
- File truststoreFile = new File(filename);
- FileInputStream trustStream = new FileInputStream(truststoreFile);
- trustStore.load(trustStream, password.toCharArray());
- trustStream.close();
- return trustStore;
- }
-
- @Override
- public void contextInitialized(ServletContextEvent sce) {
- client = new ServletOAuthClient();
- ServletContext context = sce.getServletContext();
-
- configureClient(context);
-
- client.start();
- context.setAttribute(ServletOAuthClient.class.getName(), client);
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent sce) {
- client.stop();
- }
-
- private void configureClient(ServletContext context) {
- InputStream is = null;
- String path = context.getInitParameter("keycloak.config.file");
- if (path == null) {
- is = context.getResourceAsStream("/WEB-INF/keycloak.json");
- } else {
- try {
- is = new FileInputStream(path);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- ServletOAuthClientConfigLoader loader = new ServletOAuthClientConfigLoader(is);
- loader.initOAuthClientConfiguration(true);
- loader.configureServletOAuthClient(client);
- }
-}
diff --git a/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java b/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java
deleted file mode 100755
index a1983dc81e..0000000000
--- a/examples/wildfly-demo/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.keycloak.example.oauth;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.keycloak.adapters.TokenGrantRequest;
-import org.keycloak.servlet.ServletOAuthClient;
-import org.keycloak.util.JsonSerialization;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Bill Burke
- * @version $Revision: 1 $
- */
-public class ProductDatabaseClient {
- public static void redirect(HttpServletRequest request, HttpServletResponse response) {
- // The ServletOAuthClient is obtained by getting a context attribute
- // that is set in the Bootstrap context listener in this project.
- // You really should come up with a better way to initialize
- // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code
- // and take a look how it works. You can also take a look at third-party-cdi example
- ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext().getAttribute(ServletOAuthClient.class.getName());
- try {
- oAuthClient.redirectRelative("pull_data.jsp", request, response);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- static class TypedList extends ArrayList {}
-
- public static List getProducts(HttpServletRequest request) {
- // The ServletOAuthClient is obtained by getting a context attribute
- // that is set in the Bootstrap context listener in this project.
- // You really should come up with a better way to initialize
- // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code
- // and take a look how it works. You can also take a look at third-party-cdi example
- ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext().getAttribute(ServletOAuthClient.class.getName());
- String token = null;
- try {
- token = oAuthClient.getBearerToken(request);
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (TokenGrantRequest.HttpFailure failure) {
- throw new RuntimeException(failure);
- }
-
- HttpClient client = oAuthClient.getClient();
-
- HttpGet get = new HttpGet("http://localhost:8080/database/products");
- get.addHeader("Authorization", "Bearer " + token);
- try {
- HttpResponse response = client.execute(get);
- HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- try {
- return JsonSerialization.readValue(is, TypedList.class);
- } finally {
- is.close();
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
deleted file mode 100755
index c54e4abec6..0000000000
--- a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/web.xml b/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/web.xml
deleted file mode 100755
index 958839db9f..0000000000
--- a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
- oauth-client
-
-
- org.keycloak.example.oauth.Bootstrap
-
-
-
-
diff --git a/examples/wildfly-demo/third-party/src/main/webapp/index.html b/examples/wildfly-demo/third-party/src/main/webapp/index.html
deleted file mode 100644
index dbd7d7ac6f..0000000000
--- a/examples/wildfly-demo/third-party/src/main/webapp/index.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-Third Party App That Pulls Data Using OAuth
-Pull Data
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party/src/main/webapp/pull_data.jsp b/examples/wildfly-demo/third-party/src/main/webapp/pull_data.jsp
deleted file mode 100755
index a64f674d50..0000000000
--- a/examples/wildfly-demo/third-party/src/main/webapp/pull_data.jsp
+++ /dev/null
@@ -1,22 +0,0 @@
-<%@ page import="org.keycloak.example.oauth.ProductDatabaseClient" %>
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-
-
- Pull Page
-
-
-Pulled Product Listing
-<%
-java.util.List list = ProductDatabaseClient.getProducts(request);
-for (String prod : list)
-{
- out.print("");
- out.print(prod);
- out.println("
");
-
-}
-%>
-
-
-
\ No newline at end of file
diff --git a/examples/wildfly-demo/third-party/src/main/webapp/redirect.jsp b/examples/wildfly-demo/third-party/src/main/webapp/redirect.jsp
deleted file mode 100755
index c74a9ae9e5..0000000000
--- a/examples/wildfly-demo/third-party/src/main/webapp/redirect.jsp
+++ /dev/null
@@ -1,3 +0,0 @@
-<%@ page import="org.keycloak.example.oauth.ProductDatabaseClient" %><%
- ProductDatabaseClient.redirect(request, response);
-%>
\ No newline at end of file