[KEYCLOAK-8616] - Process requests only if a deployment can be resolved

This commit is contained in:
Pedro Igor 2019-12-17 17:36:21 -03:00 committed by Stian Thorgersen
parent eed4847469
commit e316e2a2f0
2 changed files with 12 additions and 1 deletions

View file

@ -18,6 +18,7 @@
package org.keycloak.adapters.springsecurity.filter; package org.keycloak.adapters.springsecurity.filter;
import org.keycloak.adapters.AdapterDeploymentContext; import org.keycloak.adapters.AdapterDeploymentContext;
import org.keycloak.adapters.KeycloakDeployment;
import org.keycloak.adapters.NodesRegistrationManagement; import org.keycloak.adapters.NodesRegistrationManagement;
import org.keycloak.adapters.PreAuthActionsHandler; import org.keycloak.adapters.PreAuthActionsHandler;
import org.keycloak.adapters.spi.HttpFacade; import org.keycloak.adapters.spi.HttpFacade;
@ -78,7 +79,16 @@ public class KeycloakPreAuthActionsFilter extends GenericFilterBean implements A
throws IOException, ServletException { throws IOException, ServletException {
HttpFacade facade = new SimpleHttpFacade((HttpServletRequest)request, (HttpServletResponse)response); HttpFacade facade = new SimpleHttpFacade((HttpServletRequest)request, (HttpServletResponse)response);
nodesRegistrationManagement.tryRegister(deploymentContext.resolveDeployment(facade)); KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade);
if (deployment == null) {
return;
}
if (deployment.isConfigured()) {
nodesRegistrationManagement.tryRegister(deploymentContext.resolveDeployment(facade));
}
PreAuthActionsHandler handler = preAuthActionsHandlerFactory.createPreAuthActionsHandler(facade); PreAuthActionsHandler handler = preAuthActionsHandlerFactory.createPreAuthActionsHandler(facade);
if (handler.handleRequest()) { if (handler.handleRequest()) {
log.debug("Pre-auth filter handled request: {}", ((HttpServletRequest) request).getRequestURI()); log.debug("Pre-auth filter handled request: {}", ((HttpServletRequest) request).getRequestURI());

View file

@ -59,6 +59,7 @@ public class KeycloakPreAuthActionsFilterTest {
when(applicationContext.getBean(AdapterDeploymentContext.class)).thenReturn(deploymentContext); when(applicationContext.getBean(AdapterDeploymentContext.class)).thenReturn(deploymentContext);
when(deploymentContext.resolveDeployment(any(HttpFacade.class))).thenReturn(deployment); when(deploymentContext.resolveDeployment(any(HttpFacade.class))).thenReturn(deployment);
when(preAuthActionsHandlerFactory.createPreAuthActionsHandler(any(HttpFacade.class))).thenReturn(preAuthActionsHandler); when(preAuthActionsHandlerFactory.createPreAuthActionsHandler(any(HttpFacade.class))).thenReturn(preAuthActionsHandler);
when(deployment.isConfigured()).thenReturn(true);
filter.initFilterBean(); filter.initFilterBean();
} }