From adf0a19f9d42a22f389629dea2d497715b23756b Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 28 Aug 2018 18:49:07 -0300 Subject: [PATCH] [KEYCLOAK-8133] - Can't Sucessfully inject a custom KeycloakSpringBootConfigResolver in the Keycloak Spring Boot Security Adapter --- .../KeycloakBaseSpringBootConfiguration.java | 5 +++++ .../KeycloakSpringBootConfigResolver.java | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakBaseSpringBootConfiguration.java b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakBaseSpringBootConfiguration.java index 517d6c6afa..143368a007 100755 --- a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakBaseSpringBootConfiguration.java +++ b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakBaseSpringBootConfiguration.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.webapp.WebAppContext; +import org.keycloak.adapters.KeycloakConfigResolver; import org.keycloak.adapters.jetty.KeycloakJettyAuthenticator; import org.keycloak.adapters.undertow.KeycloakServletExtension; import org.springframework.beans.factory.annotation.Autowired; @@ -54,6 +55,10 @@ public class KeycloakBaseSpringBootConfiguration { KeycloakSpringBootConfigResolver.setAdapterConfig(keycloakProperties); } + @Autowired (required = false) + public void setKeycloakConfigResolvers(KeycloakConfigResolver configResolver) { + KeycloakSpringBootConfigResolver.setDelegateConfigResolver(configResolver); + } static class KeycloakBaseUndertowDeploymentInfoCustomizer { diff --git a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolver.java b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolver.java index 2f90402cf6..8e809c5480 100755 --- a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolver.java +++ b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolver.java @@ -17,6 +17,7 @@ package org.keycloak.adapters.springboot; +import org.keycloak.adapters.KeycloakConfigResolver; import org.keycloak.adapters.KeycloakDeployment; import org.keycloak.adapters.KeycloakDeploymentBuilder; import org.keycloak.adapters.OIDCHttpFacade; @@ -24,22 +25,31 @@ import org.keycloak.representations.adapters.config.AdapterConfig; public class KeycloakSpringBootConfigResolver implements org.keycloak.adapters.KeycloakConfigResolver { - private KeycloakDeployment keycloakDeployment; - private static AdapterConfig adapterConfig; + private static KeycloakConfigResolver delegateConfigResolver; + + private KeycloakDeployment keycloakDeployment; @Override public KeycloakDeployment resolve(OIDCHttpFacade.Request request) { - if (keycloakDeployment != null) { + if (delegateConfigResolver == null) { + if (keycloakDeployment != null) { + return keycloakDeployment; + } + + keycloakDeployment = KeycloakDeploymentBuilder.build(KeycloakSpringBootConfigResolver.adapterConfig); + return keycloakDeployment; } - keycloakDeployment = KeycloakDeploymentBuilder.build(KeycloakSpringBootConfigResolver.adapterConfig); - - return keycloakDeployment; + return delegateConfigResolver.resolve(request); } static void setAdapterConfig(AdapterConfig adapterConfig) { KeycloakSpringBootConfigResolver.adapterConfig = adapterConfig; } + + static void setDelegateConfigResolver(KeycloakConfigResolver configResolver) { + KeycloakSpringBootConfigResolver.delegateConfigResolver = configResolver; + } } \ No newline at end of file