[KEYCLOAK-8133] - Can't Sucessfully inject a custom KeycloakSpringBootConfigResolver in the Keycloak Spring Boot Security Adapter

This commit is contained in:
Pedro Igor 2018-08-28 18:49:07 -03:00
parent b748e269ec
commit adf0a19f9d
2 changed files with 21 additions and 6 deletions

View file

@ -32,6 +32,7 @@ import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.keycloak.adapters.KeycloakConfigResolver;
import org.keycloak.adapters.jetty.KeycloakJettyAuthenticator; import org.keycloak.adapters.jetty.KeycloakJettyAuthenticator;
import org.keycloak.adapters.undertow.KeycloakServletExtension; import org.keycloak.adapters.undertow.KeycloakServletExtension;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -54,6 +55,10 @@ public class KeycloakBaseSpringBootConfiguration {
KeycloakSpringBootConfigResolver.setAdapterConfig(keycloakProperties); KeycloakSpringBootConfigResolver.setAdapterConfig(keycloakProperties);
} }
@Autowired (required = false)
public void setKeycloakConfigResolvers(KeycloakConfigResolver configResolver) {
KeycloakSpringBootConfigResolver.setDelegateConfigResolver(configResolver);
}
static class KeycloakBaseUndertowDeploymentInfoCustomizer { static class KeycloakBaseUndertowDeploymentInfoCustomizer {

View file

@ -17,6 +17,7 @@
package org.keycloak.adapters.springboot; package org.keycloak.adapters.springboot;
import org.keycloak.adapters.KeycloakConfigResolver;
import org.keycloak.adapters.KeycloakDeployment; import org.keycloak.adapters.KeycloakDeployment;
import org.keycloak.adapters.KeycloakDeploymentBuilder; import org.keycloak.adapters.KeycloakDeploymentBuilder;
import org.keycloak.adapters.OIDCHttpFacade; import org.keycloak.adapters.OIDCHttpFacade;
@ -24,22 +25,31 @@ import org.keycloak.representations.adapters.config.AdapterConfig;
public class KeycloakSpringBootConfigResolver implements org.keycloak.adapters.KeycloakConfigResolver { public class KeycloakSpringBootConfigResolver implements org.keycloak.adapters.KeycloakConfigResolver {
private KeycloakDeployment keycloakDeployment;
private static AdapterConfig adapterConfig; private static AdapterConfig adapterConfig;
private static KeycloakConfigResolver delegateConfigResolver;
private KeycloakDeployment keycloakDeployment;
@Override @Override
public KeycloakDeployment resolve(OIDCHttpFacade.Request request) { public KeycloakDeployment resolve(OIDCHttpFacade.Request request) {
if (keycloakDeployment != null) { if (delegateConfigResolver == null) {
if (keycloakDeployment != null) {
return keycloakDeployment;
}
keycloakDeployment = KeycloakDeploymentBuilder.build(KeycloakSpringBootConfigResolver.adapterConfig);
return keycloakDeployment; return keycloakDeployment;
} }
keycloakDeployment = KeycloakDeploymentBuilder.build(KeycloakSpringBootConfigResolver.adapterConfig); return delegateConfigResolver.resolve(request);
return keycloakDeployment;
} }
static void setAdapterConfig(AdapterConfig adapterConfig) { static void setAdapterConfig(AdapterConfig adapterConfig) {
KeycloakSpringBootConfigResolver.adapterConfig = adapterConfig; KeycloakSpringBootConfigResolver.adapterConfig = adapterConfig;
} }
static void setDelegateConfigResolver(KeycloakConfigResolver configResolver) {
KeycloakSpringBootConfigResolver.delegateConfigResolver = configResolver;
}
} }