From 6bc79b590c08546d91fb37cec88e79f7a4824e49 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 15 Jun 2015 09:03:05 +0200 Subject: [PATCH 1/4] Renamed eap6 server overlay poms --- .../server-overlay/eap6/eap6-server-modules/pom.xml | 2 +- .../server-overlay/eap6/eap6-server-overlay/pom.xml | 8 ++++---- distribution/server-overlay/eap6/pom.xml | 4 ++-- pom.xml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/distribution/server-overlay/eap6/eap6-server-modules/pom.xml b/distribution/server-overlay/eap6/eap6-server-modules/pom.xml index 1fc58d1ecf..e66ad80b17 100755 --- a/distribution/server-overlay/eap6/eap6-server-modules/pom.xml +++ b/distribution/server-overlay/eap6/eap6-server-modules/pom.xml @@ -12,7 +12,7 @@ ../../../../pom.xml - keycloak-eap6-server-modules + keycloak-server-modules-eap6 Keycloak EAP 6 Server Modules pom diff --git a/distribution/server-overlay/eap6/eap6-server-overlay/pom.xml b/distribution/server-overlay/eap6/eap6-server-overlay/pom.xml index 2e4907f543..4b5acc7a2d 100755 --- a/distribution/server-overlay/eap6/eap6-server-overlay/pom.xml +++ b/distribution/server-overlay/eap6/eap6-server-overlay/pom.xml @@ -8,15 +8,15 @@ ../../../../pom.xml - keycloak-eap6-server-overlay + keycloak-server-overlay-eap6 pom - Keycloak EAP 6 Server Overlay Distribution + Keycloak Server Overlay EAP 6 Distribution org.keycloak - keycloak-eap6-server-modules + keycloak-server-modules-eap6 zip @@ -39,7 +39,7 @@ org.keycloak - keycloak-eap6-server-modules + keycloak-server-modules-eap6 zip ${project.build.directory}/unpacked/modules diff --git a/distribution/server-overlay/eap6/pom.xml b/distribution/server-overlay/eap6/pom.xml index 2504fceb5b..c784c825b4 100755 --- a/distribution/server-overlay/eap6/pom.xml +++ b/distribution/server-overlay/eap6/pom.xml @@ -8,9 +8,9 @@ ../../../pom.xml - keycloak-eap6-server-overlay-parent + keycloak-server-overlay-eap6-parent pom - Keycloak EAP 6 Server Overlay + Keycloak Server Overlay EAP 6 diff --git a/pom.xml b/pom.xml index 0bb8beb794..a1dc852a79 100755 --- a/pom.xml +++ b/pom.xml @@ -1077,7 +1077,7 @@ org.keycloak - keycloak-eap6-server-modules + keycloak-server-modules-eap6 ${project.version} zip From f846645989d8dd47573b4186b64588b65308725c Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 15 Jun 2015 09:03:20 +0200 Subject: [PATCH 2/4] Update adapter installation docs --- .../reference/en/en-US/modules/MigrationFromOlderVersions.xml | 4 ++++ docbook/reference/en/en-US/modules/jboss-adapter.xml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml b/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml index f4fdec29c8..2815f6f2b3 100755 --- a/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml +++ b/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml @@ -122,6 +122,10 @@ Make sure you grab the correct one. + + You also need to update standalone.xml as the extension module and subsystem definition has changed. + See Adapter Installation for details. +
diff --git a/docbook/reference/en/en-US/modules/jboss-adapter.xml b/docbook/reference/en/en-US/modules/jboss-adapter.xml index 3995447e24..f3794904b6 100755 --- a/docbook/reference/en/en-US/modules/jboss-adapter.xml +++ b/docbook/reference/en/en-US/modules/jboss-adapter.xml @@ -53,12 +53,12 @@ $ unzip keycloak-as7-adapter-dist.zip - + ... - + ... ]]> From 4c98b04ab762cf8a0c259b4969abe62f9b20fb89 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 15 Jun 2015 13:22:21 +0200 Subject: [PATCH 3/4] KEYCLOAK-1447 LinkageError deploying oauth-client-cdi to WildFly 8.2.0.Final --- .../as7-adapter-zip/assembly.xml | 2 +- .../as7-eap6-adapter/as7-modules/build.xml | 10 ++++------ .../as7-eap6-adapter/as7-modules/pom.xml | 8 ++------ .../org/apache/httpcomponents/4.3/module.xml | 14 -------------- .../keycloak-adapter-core/main/module.xml | 2 +- .../keycloak-as7-adapter/main/module.xml | 2 +- .../main/module.xml | 17 +++++++++++++++++ .../eap6-adapter-zip/assembly.xml | 2 +- .../wf8-adapter/wf8-adapter-zip/assembly.xml | 1 + .../adapters/wf8-adapter/wf8-modules/build.xml | 4 ++++ .../adapters/wf8-adapter/wf8-modules/pom.xml | 4 ++++ .../main/module.xml | 17 +++++++++++++++++ .../wf9-adapter/wf9-adapter-zip/assembly.xml | 1 + .../adapters/wf9-adapter/wf9-modules/build.xml | 4 ++++ .../adapters/wf9-adapter/wf9-modules/pom.xml | 4 ++++ .../main/module.xml | 17 +++++++++++++++++ examples/demo-template/third-party-cdi/pom.xml | 1 + .../keycloak/example/oauth/DatabaseClient.java | 3 ++- .../WEB-INF/jboss-deployment-structure.xml | 1 + .../example/oauth/ProductDatabaseClient.java | 3 ++- .../keycloak/servlet/ServletOAuthClient.java | 14 +++++++------- .../servlet/ServletOAuthClientBuilder.java | 3 +-- 22 files changed, 93 insertions(+), 41 deletions(-) delete mode 100644 distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/apache/httpcomponents/4.3/module.xml create mode 100755 distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml create mode 100755 distribution/adapters/wf8-adapter/wf8-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml create mode 100755 distribution/adapters/wf9-adapter/wf9-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml diff --git a/distribution/adapters/as7-eap6-adapter/as7-adapter-zip/assembly.xml b/distribution/adapters/as7-eap6-adapter/as7-adapter-zip/assembly.xml index 814a591b83..094e4268d4 100755 --- a/distribution/adapters/as7-eap6-adapter/as7-adapter-zip/assembly.xml +++ b/distribution/adapters/as7-eap6-adapter/as7-adapter-zip/assembly.xml @@ -13,13 +13,13 @@ org/bouncycastle/** net/iharder/base64/** - org/apache/httpcomponents/** org/keycloak/keycloak-core/** org/keycloak/keycloak-adapter-core/** org/keycloak/keycloak-jboss-adapter-core/** org/keycloak/keycloak-as7-adapter/** org/keycloak/keycloak-as7-subsystem/** org/keycloak/keycloak-adapter-subsystem/** + org/keycloak/keycloak-servlet-oauth-client/** **/*.war diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/build.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/build.xml index d4b4bebd20..9ab6fabade 100755 --- a/distribution/adapters/as7-eap6-adapter/as7-modules/build.xml +++ b/distribution/adapters/as7-eap6-adapter/as7-modules/build.xml @@ -38,12 +38,6 @@ - - - - - - @@ -76,6 +70,10 @@ + + + + diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/pom.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/pom.xml index 6fb1671e3a..809717feab 100755 --- a/distribution/adapters/as7-eap6-adapter/as7-modules/pom.xml +++ b/distribution/adapters/as7-eap6-adapter/as7-modules/pom.xml @@ -42,12 +42,8 @@ keycloak-as7-subsystem - org.apache.httpcomponents - httpmime - - - org.apache.httpcomponents - httpcore + org.keycloak + keycloak-servlet-oauth-client net.iharder diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/apache/httpcomponents/4.3/module.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/apache/httpcomponents/4.3/module.xml deleted file mode 100644 index a3e65f8dd0..0000000000 --- a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/apache/httpcomponents/4.3/module.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-adapter-core/main/module.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-adapter-core/main/module.xml index 1be1486fe2..5e3e5c34f0 100755 --- a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-adapter-core/main/module.xml +++ b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-adapter-core/main/module.xml @@ -11,7 +11,7 @@ - + diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-as7-adapter/main/module.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-as7-adapter/main/module.xml index b5df10afb2..463ff43792 100755 --- a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-as7-adapter/main/module.xml +++ b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-as7-adapter/main/module.xml @@ -12,7 +12,7 @@ - + diff --git a/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml new file mode 100755 index 0000000000..bc489889c9 --- /dev/null +++ b/distribution/adapters/as7-eap6-adapter/as7-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/distribution/adapters/as7-eap6-adapter/eap6-adapter-zip/assembly.xml b/distribution/adapters/as7-eap6-adapter/eap6-adapter-zip/assembly.xml index 84fe8e2153..4e29b1b9c3 100755 --- a/distribution/adapters/as7-eap6-adapter/eap6-adapter-zip/assembly.xml +++ b/distribution/adapters/as7-eap6-adapter/eap6-adapter-zip/assembly.xml @@ -13,13 +13,13 @@ org/bouncycastle/** net/iharder/base64/** - org/apache/httpcomponents/** org/keycloak/keycloak-core/** org/keycloak/keycloak-adapter-core/** org/keycloak/keycloak-jboss-adapter-core/** org/keycloak/keycloak-as7-adapter/** org/keycloak/keycloak-as7-subsystem/** org/keycloak/keycloak-adapter-subsystem/** + org/keycloak/keycloak-servlet-oauth-client/** **/*.war diff --git a/distribution/adapters/wf8-adapter/wf8-adapter-zip/assembly.xml b/distribution/adapters/wf8-adapter/wf8-adapter-zip/assembly.xml index 205ade3640..3f5d8878d9 100755 --- a/distribution/adapters/wf8-adapter/wf8-adapter-zip/assembly.xml +++ b/distribution/adapters/wf8-adapter/wf8-adapter-zip/assembly.xml @@ -20,6 +20,7 @@ org/keycloak/keycloak-wildfly-adapter/** org/keycloak/keycloak-wf8-subsystem/** org/keycloak/keycloak-adapter-subsystem/** + org/keycloak/keycloak-servlet-oauth-client/** **/*.war diff --git a/distribution/adapters/wf8-adapter/wf8-modules/build.xml b/distribution/adapters/wf8-adapter/wf8-modules/build.xml index 0ede555b6e..30e02540e6 100755 --- a/distribution/adapters/wf8-adapter/wf8-modules/build.xml +++ b/distribution/adapters/wf8-adapter/wf8-modules/build.xml @@ -69,6 +69,10 @@ + + + + diff --git a/distribution/adapters/wf8-adapter/wf8-modules/pom.xml b/distribution/adapters/wf8-adapter/wf8-modules/pom.xml index 0f88bb7027..0de89fcaad 100755 --- a/distribution/adapters/wf8-adapter/wf8-modules/pom.xml +++ b/distribution/adapters/wf8-adapter/wf8-modules/pom.xml @@ -41,6 +41,10 @@ org.keycloak keycloak-wf8-subsystem + + org.keycloak + keycloak-servlet-oauth-client + org.apache.httpcomponents httpmime diff --git a/distribution/adapters/wf8-adapter/wf8-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml b/distribution/adapters/wf8-adapter/wf8-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml new file mode 100755 index 0000000000..2d3876e266 --- /dev/null +++ b/distribution/adapters/wf8-adapter/wf8-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/distribution/adapters/wf9-adapter/wf9-adapter-zip/assembly.xml b/distribution/adapters/wf9-adapter/wf9-adapter-zip/assembly.xml index 265264e2d2..e81d4e4e0f 100755 --- a/distribution/adapters/wf9-adapter/wf9-adapter-zip/assembly.xml +++ b/distribution/adapters/wf9-adapter/wf9-adapter-zip/assembly.xml @@ -19,6 +19,7 @@ org/keycloak/keycloak-wildfly-adapter/** org/keycloak/keycloak-wf9-subsystem/** org/keycloak/keycloak-adapter-subsystem/** + org/keycloak/keycloak-servlet-oauth-client/** **/*.war diff --git a/distribution/adapters/wf9-adapter/wf9-modules/build.xml b/distribution/adapters/wf9-adapter/wf9-modules/build.xml index e33da10efc..8c1d41a21b 100755 --- a/distribution/adapters/wf9-adapter/wf9-modules/build.xml +++ b/distribution/adapters/wf9-adapter/wf9-modules/build.xml @@ -69,6 +69,10 @@ + + + + diff --git a/distribution/adapters/wf9-adapter/wf9-modules/pom.xml b/distribution/adapters/wf9-adapter/wf9-modules/pom.xml index b408d53471..f4c63e7a0c 100755 --- a/distribution/adapters/wf9-adapter/wf9-modules/pom.xml +++ b/distribution/adapters/wf9-adapter/wf9-modules/pom.xml @@ -41,6 +41,10 @@ org.keycloak keycloak-wf9-subsystem + + org.keycloak + keycloak-servlet-oauth-client + org.apache.httpcomponents httpmime diff --git a/distribution/adapters/wf9-adapter/wf9-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml b/distribution/adapters/wf9-adapter/wf9-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml new file mode 100755 index 0000000000..bc489889c9 --- /dev/null +++ b/distribution/adapters/wf9-adapter/wf9-modules/src/main/resources/modules/org/keycloak/keycloak-servlet-oauth-client/main/module.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/examples/demo-template/third-party-cdi/pom.xml b/examples/demo-template/third-party-cdi/pom.xml index d2f8da548b..d8b3f44324 100755 --- a/examples/demo-template/third-party-cdi/pom.xml +++ b/examples/demo-template/third-party-cdi/pom.xml @@ -52,6 +52,7 @@ org.keycloak keycloak-servlet-oauth-client + provided org.apache.httpcomponents diff --git a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java index 01ede2eec9..6b96f6a97f 100755 --- a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java +++ b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java @@ -4,6 +4,7 @@ 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.apache.http.impl.client.DefaultHttpClient; import org.jboss.logging.Logger; import org.keycloak.servlet.ServletOAuthClient; import org.keycloak.util.JsonSerialization; @@ -69,7 +70,7 @@ public class DatabaseClient { } protected List sendRequestToDBApplication(String dbUri) { - HttpClient client = oauthClient.getClient(); + HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(dbUri); try { diff --git a/examples/demo-template/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/demo-template/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 9c1bac9b36..2ee04e01a7 100755 --- a/examples/demo-template/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/examples/demo-template/third-party-cdi/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java b/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java index 3f69ef91f1..e47716b616 100755 --- a/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java +++ b/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java @@ -4,6 +4,7 @@ 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.apache.http.impl.client.DefaultHttpClient; import org.keycloak.adapters.ServerRequest; import org.keycloak.representations.AccessTokenResponse; import org.keycloak.servlet.ServletOAuthClient; @@ -76,7 +77,7 @@ public class ProductDatabaseClient { // 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()); - HttpClient client = oAuthClient.getClient(); + HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(getBaseUrl(oAuthClient, request) + "/database/products"); get.addHeader("Authorization", "Bearer " + accessToken); diff --git a/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClient.java b/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClient.java index ad6c327a94..668bb02d3d 100755 --- a/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClient.java +++ b/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClient.java @@ -3,10 +3,12 @@ package org.keycloak.servlet; import org.apache.http.client.HttpClient; import org.keycloak.AbstractOAuthClient; import org.keycloak.OAuth2Constants; +import org.keycloak.adapters.HttpClientBuilder; import org.keycloak.adapters.ServerRequest; import org.keycloak.jose.jws.JWSInput; import org.keycloak.representations.AccessTokenResponse; import org.keycloak.representations.IDToken; +import org.keycloak.representations.adapters.config.AdapterConfig; import org.keycloak.util.KeycloakUriBuilder; import org.keycloak.util.UriUtils; @@ -22,8 +24,10 @@ import java.net.URI; */ public class ServletOAuthClient extends AbstractOAuthClient { protected HttpClient client; + protected AdapterConfig adapterConfig; public void start() { + client = new HttpClientBuilder().build(adapterConfig); } /** @@ -32,13 +36,6 @@ public class ServletOAuthClient extends AbstractOAuthClient { public void stop() { client.getConnectionManager().shutdown(); } - public HttpClient getClient() { - return client; - } - - public void setClient(HttpClient client) { - this.client = client; - } private AccessTokenResponse resolveBearerToken(HttpServletRequest request, String redirectUri, String code) throws IOException, ServerRequest.HttpFailure { // Don't send sessionId in oauth clients for now @@ -171,4 +168,7 @@ public class ServletOAuthClient extends AbstractOAuthClient { } } + public void setAdapterConfig(AdapterConfig adapterConfig) { + this.adapterConfig = adapterConfig; + } } diff --git a/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClientBuilder.java b/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClientBuilder.java index d642e5c78b..d650e93b4a 100755 --- a/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClientBuilder.java +++ b/integration/servlet-oauth-client/src/main/java/org/keycloak/servlet/ServletOAuthClientBuilder.java @@ -42,8 +42,7 @@ public class ServletOAuthClientBuilder { public static void build(AdapterConfig adapterConfig, ServletOAuthClient oauthClient) { - HttpClient client = new HttpClientBuilder().build(adapterConfig); - oauthClient.setClient(client); + oauthClient.setAdapterConfig(adapterConfig); oauthClient.setClientId(adapterConfig.getResource()); oauthClient.setPublicClient(adapterConfig.isPublicClient()); oauthClient.setCredentials(adapterConfig.getCredentials()); From 6e758d721d5c1ce958b84ab9e18d95fa6c92c317 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 15 Jun 2015 14:21:12 +0200 Subject: [PATCH 4/4] Fix CDI examples --- .../example/oauth/AppContextListener.java | 1 + .../keycloak/example/oauth/DatabaseClient.java | 16 ++++------------ examples/demo-template/third-party/pom.xml | 1 + .../example/oauth/ProductDatabaseClient.java | 6 +++++- .../WEB-INF/jboss-deployment-structure.xml | 1 + 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java index 1fe4a2ff71..bd6a395242 100755 --- a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java +++ b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/AppContextListener.java @@ -41,6 +41,7 @@ public class AppContextListener implements ServletContextListener { } ServletOAuthClientBuilder.build(is, oauthClient); logger.info("OAuth client configured and started"); + oauthClient.start(); } @Override diff --git a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java index 6b96f6a97f..0a440374b8 100755 --- a/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java +++ b/examples/demo-template/third-party-cdi/src/main/java/org/keycloak/example/oauth/DatabaseClient.java @@ -6,6 +6,8 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.jboss.logging.Logger; +import org.keycloak.KeycloakSecurityContext; +import org.keycloak.adapters.AdapterUtils; import org.keycloak.servlet.ServletOAuthClient; import org.keycloak.util.JsonSerialization; import org.keycloak.util.UriUtils; @@ -104,18 +106,8 @@ public class DatabaseClient { } public String getBaseUrl() { - switch (oauthClient.getRelativeUrlsUsed()) { - case ALL_REQUESTS: - // Resolve baseURI from the request - return UriUtils.getOrigin(request.getRequestURL().toString()); - case BROWSER_ONLY: - // Resolve baseURI from the codeURL (This is already non-relative and based on our hostname) - return UriUtils.getOrigin(oauthClient.getTokenUrl()); - case NEVER: - return ""; - default: - return ""; - } + KeycloakSecurityContext session = (KeycloakSecurityContext)request.getAttribute(KeycloakSecurityContext.class.getName()); + return AdapterUtils.getOriginForRestCalls(request.getRequestURL().toString(), session); } } diff --git a/examples/demo-template/third-party/pom.xml b/examples/demo-template/third-party/pom.xml index 6ec11d9e81..e5e3ac45a2 100755 --- a/examples/demo-template/third-party/pom.xml +++ b/examples/demo-template/third-party/pom.xml @@ -34,6 +34,7 @@ org.keycloak keycloak-servlet-oauth-client + provided org.apache.httpcomponents diff --git a/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java b/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java index e47716b616..b0e0e00af8 100755 --- a/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java +++ b/examples/demo-template/third-party/src/main/java/org/keycloak/example/oauth/ProductDatabaseClient.java @@ -5,6 +5,8 @@ import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; +import org.keycloak.KeycloakSecurityContext; +import org.keycloak.adapters.AdapterUtils; import org.keycloak.adapters.ServerRequest; import org.keycloak.representations.AccessTokenResponse; import org.keycloak.servlet.ServletOAuthClient; @@ -71,6 +73,8 @@ public class ProductDatabaseClient { } public static List getProducts(HttpServletRequest request, String accessToken) throws Failure { + KeycloakSecurityContext session = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); + // 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 @@ -79,7 +83,7 @@ public class ProductDatabaseClient { ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext().getAttribute(ServletOAuthClient.class.getName()); HttpClient client = new DefaultHttpClient(); - HttpGet get = new HttpGet(getBaseUrl(oAuthClient, request) + "/database/products"); + HttpGet get = new HttpGet(AdapterUtils.getOriginForRestCalls(request.getRequestURL().toString(), session) + "/database/products"); get.addHeader("Authorization", "Bearer " + accessToken); try { HttpResponse response = client.execute(get); diff --git a/examples/demo-template/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/demo-template/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 9c1bac9b36..2ee04e01a7 100755 --- a/examples/demo-template/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/examples/demo-template/third-party/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -4,6 +4,7 @@ + \ No newline at end of file