From 84d099e48f95c4ab04abc6b5e215e270627083d0 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Wed, 11 Mar 2020 16:40:12 -0300 Subject: [PATCH] [KEYCLOAK-11282] - Properly resolve config resolver Co-authored-by: mhajas --- .../springboot/KeycloakBaseSpringBootConfiguration.java | 6 ++---- .../KeycloakSpringBootConfigResolverWrapper.java | 8 ++++++++ .../adapters/springboot/KeycloakAutoConfiguration.java | 7 ------- .../config/KeycloakSpringConfigResolverWrapper.java | 4 ++++ 4 files changed, 14 insertions(+), 11 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 e0b2e70273..92234c106b 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 @@ -21,7 +21,6 @@ import io.undertow.servlet.api.DeploymentInfo; import io.undertow.servlet.api.SecurityInfo.EmptyRoleSemantic; import io.undertow.servlet.api.WebResourceCollection; import org.apache.catalina.Context; -import org.apache.log4j.Logger; import org.apache.tomcat.util.descriptor.web.LoginConfig; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; @@ -34,7 +33,6 @@ 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.KeycloakDeploymentBuilder; import org.keycloak.adapters.jetty.KeycloakJettyAuthenticator; import org.keycloak.adapters.undertow.KeycloakServletExtension; import org.springframework.beans.factory.annotation.Autowired; @@ -54,9 +52,9 @@ public class KeycloakBaseSpringBootConfiguration { protected KeycloakSpringBootProperties keycloakProperties; @Autowired - public void setKeycloakSpringBootProperties(KeycloakSpringBootProperties keycloakProperties, KeycloakSpringBootConfigResolver resolver) { + public void setKeycloakSpringBootProperties(KeycloakSpringBootProperties keycloakProperties) { this.keycloakProperties = keycloakProperties; - resolver.setAdapterConfig(keycloakProperties); + KeycloakSpringBootConfigResolverWrapper.setAdapterConfig(keycloakProperties); } @Autowired diff --git a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolverWrapper.java b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolverWrapper.java index 34ae3adefb..c14dbfe6cd 100644 --- a/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolverWrapper.java +++ b/adapters/oidc/spring-boot-adapter-core/src/main/java/org/keycloak/adapters/springboot/KeycloakSpringBootConfigResolverWrapper.java @@ -33,6 +33,7 @@ import org.springframework.context.ApplicationContext; public class KeycloakSpringBootConfigResolverWrapper extends KeycloakSpringConfigResolverWrapper { private static ApplicationContext context; + private static KeycloakSpringBootProperties adapterConfig; public KeycloakSpringBootConfigResolverWrapper() { super(new KeycloakSpringBootConfigResolver()); @@ -40,9 +41,16 @@ public class KeycloakSpringBootConfigResolverWrapper extends KeycloakSpringConfi setDelegate(context.getBean(KeycloakConfigResolver.class)); } catch (NoSuchBeanDefinitionException ignore) { } + if (getDelegate() instanceof KeycloakSpringBootConfigResolver) { + KeycloakSpringBootConfigResolver.class.cast(getDelegate()).setAdapterConfig(adapterConfig); + } } public static void setApplicationContext(ApplicationContext context) { KeycloakSpringBootConfigResolverWrapper.context = context; } + + public static void setAdapterConfig(KeycloakSpringBootProperties adapterConfig) { + KeycloakSpringBootConfigResolverWrapper.adapterConfig = adapterConfig; + } } diff --git a/adapters/oidc/spring-boot/src/main/java/org/keycloak/adapters/springboot/KeycloakAutoConfiguration.java b/adapters/oidc/spring-boot/src/main/java/org/keycloak/adapters/springboot/KeycloakAutoConfiguration.java index 205b04b03d..4214db0b73 100755 --- a/adapters/oidc/spring-boot/src/main/java/org/keycloak/adapters/springboot/KeycloakAutoConfiguration.java +++ b/adapters/oidc/spring-boot/src/main/java/org/keycloak/adapters/springboot/KeycloakAutoConfiguration.java @@ -49,13 +49,6 @@ public class KeycloakAutoConfiguration extends KeycloakBaseSpringBootConfigurati private KeycloakSpringBootProperties keycloakProperties; - @Autowired - public void setKeycloakSpringBootProperties(KeycloakSpringBootProperties keycloakProperties, KeycloakSpringBootConfigResolver resolver) { - this.keycloakProperties = keycloakProperties; - resolver.setAdapterConfig(keycloakProperties); - } - - @Bean public EmbeddedServletContainerCustomizer getKeycloakContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { diff --git a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/config/KeycloakSpringConfigResolverWrapper.java b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/config/KeycloakSpringConfigResolverWrapper.java index d467f320b2..4fa0bba7f6 100644 --- a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/config/KeycloakSpringConfigResolverWrapper.java +++ b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/config/KeycloakSpringConfigResolverWrapper.java @@ -43,4 +43,8 @@ public class KeycloakSpringConfigResolverWrapper implements KeycloakConfigResolv protected void setDelegate(KeycloakConfigResolver delegate) { this.delegate = delegate; } + + protected KeycloakConfigResolver getDelegate() { + return delegate; + } }