[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,12 +25,14 @@ 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 (delegateConfigResolver == null) {
if (keycloakDeployment != null) { if (keycloakDeployment != null) {
return keycloakDeployment; return keycloakDeployment;
} }
@ -39,7 +42,14 @@ public class KeycloakSpringBootConfigResolver implements org.keycloak.adapters.K
return keycloakDeployment; return keycloakDeployment;
} }
return delegateConfigResolver.resolve(request);
}
static void setAdapterConfig(AdapterConfig adapterConfig) { static void setAdapterConfig(AdapterConfig adapterConfig) {
KeycloakSpringBootConfigResolver.adapterConfig = adapterConfig; KeycloakSpringBootConfigResolver.adapterConfig = adapterConfig;
} }
static void setDelegateConfigResolver(KeycloakConfigResolver configResolver) {
KeycloakSpringBootConfigResolver.delegateConfigResolver = configResolver;
}
} }