From 6326d5d2b5fce37a817c96b1bf46cb53d3bd66e3 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Wed, 15 Jan 2014 10:02:56 -0500 Subject: [PATCH] auth-server-url and Realm/App name changes --- .../resources/admin/js/controllers/realm.js | 5 ++-- .../resources/admin/partials/menu.html | 2 +- .../org/keycloak/ServiceUrlConstants.java | 11 +++++++++ .../adapters/config/AdapterConfig.java | 2 +- .../adapters/config/BaseAdapterConfig.java | 2 +- .../adapters/config/BaseRealmConfig.java | 24 ++++++------------- .../src/main/webapp/WEB-INF/keycloak.json | 3 +-- .../src/main/webapp/WEB-INF/keycloak.json | 5 ++-- examples/as7-eap-demo/testrealm.json | 2 +- .../src/main/webapp/WEB-INF/keycloak.json | 3 +-- .../src/main/webapp/WEB-INF/keycloak.json | 3 +-- .../src/main/webapp/WEB-INF/keycloak.json | 3 +-- .../src/main/webapp/WEB-INF/keycloak.json | 7 +++--- examples/wildfly-demo/testrealm.json | 2 +- .../src/main/webapp/WEB-INF/keycloak.json | 4 ++-- .../src/main/webapp/WEB-INF/keycloak.json | 4 ++-- .../config/OAuthClientConfigLoader.java | 12 ++++++++-- .../config/RealmConfigurationLoader.java | 12 +++++----- .../java/org/keycloak/models/Constants.java | 6 ++--- .../services/managers/ApplicationManager.java | 3 +-- .../services/managers/OAuthClientManager.java | 4 +--- .../resources/KeycloakApplication.java | 19 ++++++++++++++- .../resources/admin/ApplicationResource.java | 11 ++++++++- .../resources/admin/OAuthClientResource.java | 11 ++++++++- 24 files changed, 97 insertions(+), 63 deletions(-) create mode 100755 core/src/main/java/org/keycloak/ServiceUrlConstants.java mode change 100644 => 100755 integration/adapter-core/src/main/java/org/keycloak/adapters/config/OAuthClientConfigLoader.java diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js index d006c718cc..4b1cb4328d 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js @@ -26,13 +26,12 @@ module.controller('HomeCtrl', function(Realm, $location) { if (realms.length == 1) { realm = realms[0].realm; } else if (realms.length == 2) { - if (realms[0].realm == 'Keycloak Administration') { + if (realms[0].realm == 'keycloak-admin') { realm = realms[1].realm; - } else if (realms[1].realm == 'Keycloak Administration') { + } else if (realms[1].realm == 'keycloak-admin') { realm = realms[0].realm; } } - console.log("****** HomeCtrl ******"); if (realm) { $location.url('/realms/' + realm); } else { diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/menu.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/menu.html index 40fcfe7bd7..2ebeb3e9a6 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/menu.html +++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/menu.html @@ -11,7 +11,7 @@ Icon: user{{auth.user.displayName}} diff --git a/core/src/main/java/org/keycloak/ServiceUrlConstants.java b/core/src/main/java/org/keycloak/ServiceUrlConstants.java new file mode 100755 index 0000000000..b1c9aa4ac0 --- /dev/null +++ b/core/src/main/java/org/keycloak/ServiceUrlConstants.java @@ -0,0 +1,11 @@ +package org.keycloak; + +/** + * @author Bill Burke + * @version $Revision: 1 $ + */ +public interface ServiceUrlConstants { + + public static final String TOKEN_SERVICE_LOGIN_PATH = "/rest/realms/{realm-name}/tokens/login"; + public static final String TOKEN_SERVICE_ACCESS_CODE_PATH = "/rest/realms/{realm-name}/tokens/access/codes"; +} diff --git a/core/src/main/java/org/keycloak/representations/adapters/config/AdapterConfig.java b/core/src/main/java/org/keycloak/representations/adapters/config/AdapterConfig.java index 46117dee09..b51e429f1a 100755 --- a/core/src/main/java/org/keycloak/representations/adapters/config/AdapterConfig.java +++ b/core/src/main/java/org/keycloak/representations/adapters/config/AdapterConfig.java @@ -9,7 +9,7 @@ import org.codehaus.jackson.annotate.JsonPropertyOrder; * @author Bill Burke * @version $Revision: 1 $ */ -@JsonPropertyOrder({"realm", "realm-public-key", "auth-url", "code-url", "ssl-not-required", +@JsonPropertyOrder({"realm", "realm-public-key", "auth-server-url", "ssl-not-required", "resource", "credentials", "use-resource-role-mappings", "enable-cors", "cors-max-age", "cors-allowed-methods", diff --git a/core/src/main/java/org/keycloak/representations/adapters/config/BaseAdapterConfig.java b/core/src/main/java/org/keycloak/representations/adapters/config/BaseAdapterConfig.java index 5ab9a7224c..1e2ffa782c 100755 --- a/core/src/main/java/org/keycloak/representations/adapters/config/BaseAdapterConfig.java +++ b/core/src/main/java/org/keycloak/representations/adapters/config/BaseAdapterConfig.java @@ -13,7 +13,7 @@ import java.util.Map; * @author Bill Burke * @version $Revision: 1 $ */ -@JsonPropertyOrder({"realm", "realm-public-key", "auth-url", "code-url", "ssl-not-required", +@JsonPropertyOrder({"realm", "realm-public-key", "auth-server-url", "ssl-not-required", "resource", "credentials", "use-resource-role-mappings", "enable-cors", "cors-max-age", "cors-allowed-methods", diff --git a/core/src/main/java/org/keycloak/representations/adapters/config/BaseRealmConfig.java b/core/src/main/java/org/keycloak/representations/adapters/config/BaseRealmConfig.java index 948c09a790..f4a25929c7 100755 --- a/core/src/main/java/org/keycloak/representations/adapters/config/BaseRealmConfig.java +++ b/core/src/main/java/org/keycloak/representations/adapters/config/BaseRealmConfig.java @@ -9,16 +9,14 @@ import org.codehaus.jackson.annotate.JsonPropertyOrder; * @author Bill Burke * @version $Revision: 1 $ */ -@JsonPropertyOrder({"realm", "realm-public-key", "auth-url", "code-url", "ssl-not-required"}) +@JsonPropertyOrder({"realm", "realm-public-key", "auth-server-url", "ssl-not-required"}) public class BaseRealmConfig { @JsonProperty("realm") protected String realm; @JsonProperty("realm-public-key") protected String realmKey; - @JsonProperty("auth-url") - protected String authUrl; - @JsonProperty("code-url") - protected String codeUrl; + @JsonProperty("auth-server-url") + protected String authServerUrl; @JsonProperty("ssl-not-required") protected boolean sslNotRequired; @@ -46,19 +44,11 @@ public class BaseRealmConfig { this.realmKey = realmKey; } - public String getAuthUrl() { - return authUrl; + public String getAuthServerUrl() { + return authServerUrl; } - public void setAuthUrl(String authUrl) { - this.authUrl = authUrl; - } - - public String getCodeUrl() { - return codeUrl; - } - - public void setCodeUrl(String codeUrl) { - this.codeUrl = codeUrl; + public void setAuthServerUrl(String authServerUrl) { + this.authServerUrl = authServerUrl; } } diff --git a/examples/as7-eap-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json b/examples/as7-eap-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json index c0c1c44219..644d621063 100755 --- a/examples/as7-eap-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/as7-eap-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json @@ -2,8 +2,7 @@ "realm" : "demo", "resource" : "customer-portal", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "expose-token" : true, "credentials" : { diff --git a/examples/as7-eap-demo/product-app/src/main/webapp/WEB-INF/keycloak.json b/examples/as7-eap-demo/product-app/src/main/webapp/WEB-INF/keycloak.json index c4f16a9205..1077ac2118 100755 --- a/examples/as7-eap-demo/product-app/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/as7-eap-demo/product-app/src/main/webapp/WEB-INF/keycloak.json @@ -2,9 +2,8 @@ "realm" : "demo", "resource" : "product-portal", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", - "ssl-not-required" : true, + "auth-server-url" : "http://localhost:8080/auth", + "ssl-not-required" : true, "credentials" : { "password" : "password" } diff --git a/examples/as7-eap-demo/testrealm.json b/examples/as7-eap-demo/testrealm.json index 7b45c2b192..dab68ee01a 100755 --- a/examples/as7-eap-demo/testrealm.json +++ b/examples/as7-eap-demo/testrealm.json @@ -96,7 +96,7 @@ } ], "applicationRoleMappings": { - "Account": [ + "account": [ { "username": "bburke@redhat.com", "roles": ["manage-account"] diff --git a/examples/as7-eap-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json b/examples/as7-eap-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json index 2bd3f82546..3128adf7cc 100755 --- a/examples/as7-eap-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/as7-eap-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json @@ -1,7 +1,6 @@ { "resource" : "third-party", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "credentials" : { "password" : "password" diff --git a/examples/as7-eap-demo/third-party/src/main/webapp/WEB-INF/keycloak.json b/examples/as7-eap-demo/third-party/src/main/webapp/WEB-INF/keycloak.json index 2bd3f82546..3128adf7cc 100755 --- a/examples/as7-eap-demo/third-party/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/as7-eap-demo/third-party/src/main/webapp/WEB-INF/keycloak.json @@ -1,7 +1,6 @@ { "resource" : "third-party", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "credentials" : { "password" : "password" diff --git a/examples/wildfly-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json b/examples/wildfly-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json index c0c1c44219..644d621063 100755 --- a/examples/wildfly-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/wildfly-demo/customer-app/src/main/webapp/WEB-INF/keycloak.json @@ -2,8 +2,7 @@ "realm" : "demo", "resource" : "customer-portal", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "expose-token" : true, "credentials" : { diff --git a/examples/wildfly-demo/product-app/src/main/webapp/WEB-INF/keycloak.json b/examples/wildfly-demo/product-app/src/main/webapp/WEB-INF/keycloak.json index c4f16a9205..7df8edba1b 100755 --- a/examples/wildfly-demo/product-app/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/wildfly-demo/product-app/src/main/webapp/WEB-INF/keycloak.json @@ -2,10 +2,9 @@ "realm" : "demo", "resource" : "product-portal", "realm-public-key" : "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", - "ssl-not-required" : true, - "credentials" : { + "auth-server-url" : "http://localhost:8080/auth", + "ssl-not-required" : true, + "credentials" : { "password" : "password" } } diff --git a/examples/wildfly-demo/testrealm.json b/examples/wildfly-demo/testrealm.json index 7b45c2b192..dab68ee01a 100755 --- a/examples/wildfly-demo/testrealm.json +++ b/examples/wildfly-demo/testrealm.json @@ -96,7 +96,7 @@ } ], "applicationRoleMappings": { - "Account": [ + "account": [ { "username": "bburke@redhat.com", "roles": ["manage-account"] diff --git a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json index 2bd3f82546..80c6a3ba74 100755 --- a/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/wildfly-demo/third-party-cdi/src/main/webapp/WEB-INF/keycloak.json @@ -1,7 +1,7 @@ { + "realm" : "demo", "resource" : "third-party", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "credentials" : { "password" : "password" diff --git a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/keycloak.json b/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/keycloak.json index 2bd3f82546..80c6a3ba74 100755 --- a/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/keycloak.json +++ b/examples/wildfly-demo/third-party/src/main/webapp/WEB-INF/keycloak.json @@ -1,7 +1,7 @@ { + "realm" : "demo", "resource" : "third-party", - "auth-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/login", - "code-url" : "http://localhost:8080/auth/rest/realms/demo/tokens/access/codes", + "auth-server-url" : "http://localhost:8080/auth", "ssl-not-required" : true, "credentials" : { "password" : "password" diff --git a/integration/adapter-core/src/main/java/org/keycloak/adapters/config/OAuthClientConfigLoader.java b/integration/adapter-core/src/main/java/org/keycloak/adapters/config/OAuthClientConfigLoader.java old mode 100644 new mode 100755 index 98101b2e0d..db9d2d5956 --- a/integration/adapter-core/src/main/java/org/keycloak/adapters/config/OAuthClientConfigLoader.java +++ b/integration/adapter-core/src/main/java/org/keycloak/adapters/config/OAuthClientConfigLoader.java @@ -3,6 +3,8 @@ package org.keycloak.adapters.config; import java.io.InputStream; import org.keycloak.AbstractOAuthClient; +import org.keycloak.ServiceUrlConstants; +import org.keycloak.util.KeycloakUriBuilder; /** * @author Marek Posolda @@ -27,8 +29,14 @@ public abstract class OAuthClientConfigLoader extends RealmConfigurationLoader { public void configureOAuthClient(AbstractOAuthClient oauthClient) { oauthClient.setClientId(adapterConfig.getResource()); oauthClient.setPassword(adapterConfig.getCredentials().get("password")); - oauthClient.setAuthUrl(adapterConfig.getAuthUrl()); - oauthClient.setCodeUrl(adapterConfig.getCodeUrl()); + if (adapterConfig.getAuthServerUrl() == null) { + throw new RuntimeException("You must specify auth-url"); + } + KeycloakUriBuilder serverBuilder = KeycloakUriBuilder.fromUri(adapterConfig.getAuthServerUrl()); + String authUrl = serverBuilder.clone().path(ServiceUrlConstants.TOKEN_SERVICE_LOGIN_PATH).build(adapterConfig.getRealm()).toString(); + String tokenUrl = serverBuilder.clone().path(ServiceUrlConstants.TOKEN_SERVICE_ACCESS_CODE_PATH).build(adapterConfig.getRealm()).toString(); + oauthClient.setAuthUrl(authUrl); + oauthClient.setCodeUrl(tokenUrl); oauthClient.setTruststore(truststore); if (adapterConfig.getScope() != null) { String scope = encodeScope(adapterConfig.getScope()); diff --git a/integration/adapter-core/src/main/java/org/keycloak/adapters/config/RealmConfigurationLoader.java b/integration/adapter-core/src/main/java/org/keycloak/adapters/config/RealmConfigurationLoader.java index 8d311d746e..264fb6bd4e 100755 --- a/integration/adapter-core/src/main/java/org/keycloak/adapters/config/RealmConfigurationLoader.java +++ b/integration/adapter-core/src/main/java/org/keycloak/adapters/config/RealmConfigurationLoader.java @@ -1,6 +1,7 @@ package org.keycloak.adapters.config; import org.apache.http.client.HttpClient; +import org.keycloak.ServiceUrlConstants; import org.keycloak.adapters.HttpClientBuilder; import org.keycloak.util.KeycloakUriBuilder; @@ -30,14 +31,13 @@ public class RealmConfigurationLoader extends AdapterConfigLoader { if (!setupClient || adapterConfig.isBearerOnly()) return; initClient(); realmConfiguration = new RealmConfiguration(); - String authUrl = adapterConfig.getAuthUrl(); - if (authUrl == null) { + if (adapterConfig.getAuthServerUrl() == null) { throw new RuntimeException("You must specify auth-url"); } - String tokenUrl = adapterConfig.getCodeUrl(); - if (tokenUrl == null) { - throw new RuntimeException("You mut specify code-url"); - } + KeycloakUriBuilder serverBuilder = KeycloakUriBuilder.fromUri(adapterConfig.getAuthServerUrl()); + String authUrl = serverBuilder.clone().path(ServiceUrlConstants.TOKEN_SERVICE_LOGIN_PATH).build(adapterConfig.getRealm()).toString(); + String tokenUrl = serverBuilder.clone().path(ServiceUrlConstants.TOKEN_SERVICE_ACCESS_CODE_PATH).build(adapterConfig.getRealm()).toString(); + realmConfiguration.setMetadata(resourceMetadata); realmConfiguration.setSslRequired(!adapterConfig.isSslNotRequired()); realmConfiguration.setResourceCredentials(adapterConfig.getCredentials()); diff --git a/model/api/src/main/java/org/keycloak/models/Constants.java b/model/api/src/main/java/org/keycloak/models/Constants.java index fb29037288..c2051df421 100755 --- a/model/api/src/main/java/org/keycloak/models/Constants.java +++ b/model/api/src/main/java/org/keycloak/models/Constants.java @@ -6,13 +6,13 @@ package org.keycloak.models; */ public interface Constants { String INTERNAL_ROLE = "KEYCLOAK_"; - String ADMIN_REALM = "Keycloak Administration"; - String ADMIN_CONSOLE_APPLICATION = "Admin Console"; + String ADMIN_REALM = "keycloak-admin"; + String ADMIN_CONSOLE_APPLICATION = "admin-console"; String ADMIN_CONSOLE_ADMIN_ROLE = "admin"; String APPLICATION_ROLE = INTERNAL_ROLE + "_APPLICATION"; String IDENTITY_REQUESTER_ROLE = INTERNAL_ROLE + "_IDENTITY_REQUESTER"; - String ACCOUNT_APPLICATION = "Account"; + String ACCOUNT_APPLICATION = "account"; String ACCOUNT_PROFILE_ROLE = "view-profile"; String ACCOUNT_MANAGE_ROLE = "manage-account"; } diff --git a/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java b/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java index 4260d5057b..72ea03b1cb 100755 --- a/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java +++ b/services/src/main/java/org/keycloak/services/managers/ApplicationManager.java @@ -181,8 +181,7 @@ public class ApplicationManager { rep.setRealmKey(realmModel.getPublicKeyPem()); rep.setSslNotRequired(realmModel.isSslNotRequired()); - rep.setAuthUrl(Urls.realmLoginPage(baseUri, realmModel.getName()).toString()); - rep.setCodeUrl(Urls.realmCode(baseUri, realmModel.getName()).toString()); + rep.setAuthServerUrl(baseUri.toString()); rep.setUseResourceRoleMappings(applicationModel.getRoles().size() > 0); rep.setResource(applicationModel.getName()); diff --git a/services/src/main/java/org/keycloak/services/managers/OAuthClientManager.java b/services/src/main/java/org/keycloak/services/managers/OAuthClientManager.java index f543771cc7..c02a74cf4e 100755 --- a/services/src/main/java/org/keycloak/services/managers/OAuthClientManager.java +++ b/services/src/main/java/org/keycloak/services/managers/OAuthClientManager.java @@ -88,9 +88,7 @@ public class OAuthClientManager { rep.setRealm(realmModel.getName()); rep.setRealmKey(realmModel.getPublicKeyPem()); rep.setSslNotRequired(realmModel.isSslNotRequired()); - - rep.setAuthUrl(Urls.realmLoginPage(baseUri, realmModel.getName()).toString()); - rep.setCodeUrl(Urls.realmCode(baseUri, realmModel.getName()).toString()); + rep.setAuthServerUrl(baseUri.toString()); rep.setUseResourceRoleMappings(false); rep.setResource(model.getOAuthAgent().getLoginName()); diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index 0ad2bda27e..e41cfc6128 100755 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -12,6 +12,8 @@ import org.keycloak.services.resources.admin.AdminService; import javax.servlet.ServletContext; import javax.ws.rs.core.Application; import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; +import java.net.URI; import java.util.HashSet; import java.util.ServiceLoader; import java.util.Set; @@ -31,10 +33,11 @@ public class KeycloakApplication extends Application { protected Set> classes = new HashSet>(); protected KeycloakSessionFactory factory; + protected String contextPath; public KeycloakApplication(@Context ServletContext context) { this.factory = createSessionFactory(); - + this.contextPath = context.getContextPath(); context.setAttribute(KeycloakSessionFactory.class.getName(), factory); //classes.add(KeycloakSessionCleanupFilter.class); @@ -49,6 +52,20 @@ public class KeycloakApplication extends Application { setupDefaultRealm(); } + public String getContextPath() { + return contextPath; + } + + /** + * Get base URI of WAR distribution, not JAX-RS + * + * @param uriInfo + * @return + */ + public URI getBaseUri(UriInfo uriInfo) { + return uriInfo.getBaseUriBuilder().replacePath(getContextPath()).build(); + } + protected void setupDefaultRealm() { new ApplianceBootstrap().bootstrap(factory); } diff --git a/services/src/main/java/org/keycloak/services/resources/admin/ApplicationResource.java b/services/src/main/java/org/keycloak/services/resources/admin/ApplicationResource.java index 66cc4b72e6..a64b45dc1a 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/ApplicationResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/ApplicationResource.java @@ -11,6 +11,7 @@ import org.keycloak.representations.idm.ApplicationRepresentation; import org.keycloak.representations.idm.CredentialRepresentation; import org.keycloak.services.managers.ApplicationManager; import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.resources.KeycloakApplication; import org.keycloak.util.JsonSerialization; import javax.ws.rs.Consumes; @@ -19,6 +20,7 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.Application; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; @@ -38,6 +40,13 @@ public class ApplicationResource extends RoleContainerResource { @Context protected UriInfo uriInfo; + @Context + protected Application keycloak; + + protected KeycloakApplication getKeycloakApplication() { + return (KeycloakApplication)keycloak; + } + public ApplicationResource(RealmModel realm, ApplicationModel applicationModel, KeycloakSession session) { super(applicationModel); this.realm = realm; @@ -68,7 +77,7 @@ public class ApplicationResource extends RoleContainerResource { @Produces(MediaType.APPLICATION_JSON) public String getInstallation() throws IOException { ApplicationManager applicationManager = new ApplicationManager(new RealmManager(session)); - BaseAdapterConfig rep = applicationManager.toInstallationRepresentation(realm, application, uriInfo.getBaseUri()); + BaseAdapterConfig rep = applicationManager.toInstallationRepresentation(realm, application, getKeycloakApplication().getBaseUri(uriInfo)); // TODO Temporary solution to pretty-print return JsonSerialization.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rep); diff --git a/services/src/main/java/org/keycloak/services/resources/admin/OAuthClientResource.java b/services/src/main/java/org/keycloak/services/resources/admin/OAuthClientResource.java index 4cafbc7621..46cce261a1 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/OAuthClientResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/OAuthClientResource.java @@ -12,6 +12,7 @@ import org.keycloak.representations.idm.OAuthClientRepresentation; import org.keycloak.services.managers.ApplicationManager; import org.keycloak.services.managers.OAuthClientManager; import org.keycloak.services.managers.RealmManager; +import org.keycloak.services.resources.KeycloakApplication; import org.keycloak.util.JsonSerialization; import javax.ws.rs.Consumes; @@ -20,6 +21,7 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.Application; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; @@ -38,6 +40,13 @@ public class OAuthClientResource { @Context protected UriInfo uriInfo; + @Context + protected Application application; + + protected KeycloakApplication getApplication() { + return (KeycloakApplication)application; + } + public OAuthClientResource(RealmModel realm, OAuthClientModel oauthClient, KeycloakSession session) { this.realm = realm; this.oauthClient = oauthClient; @@ -65,7 +74,7 @@ public class OAuthClientResource { @Produces(MediaType.APPLICATION_JSON) public String getInstallation() throws IOException { OAuthClientManager manager = new OAuthClientManager(realm); - BaseAdapterConfig rep = manager.toInstallationRepresentation(realm, oauthClient, uriInfo.getBaseUri()); + BaseAdapterConfig rep = manager.toInstallationRepresentation(realm, oauthClient, getApplication().getBaseUri(uriInfo)); // TODO Temporary solution to pretty-print return JsonSerialization.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rep);