From e316e2a2f0371ca5ae666d8f3a82a49cc75f11e6 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 17 Dec 2019 17:36:21 -0300 Subject: [PATCH] [KEYCLOAK-8616] - Process requests only if a deployment can be resolved --- .../filter/KeycloakPreAuthActionsFilter.java | 12 +++++++++++- .../filter/KeycloakPreAuthActionsFilterTest.java | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilter.java b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilter.java index b239310c3e..75bc815f27 100755 --- a/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilter.java +++ b/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilter.java @@ -18,6 +18,7 @@ package org.keycloak.adapters.springsecurity.filter; import org.keycloak.adapters.AdapterDeploymentContext; +import org.keycloak.adapters.KeycloakDeployment; import org.keycloak.adapters.NodesRegistrationManagement; import org.keycloak.adapters.PreAuthActionsHandler; import org.keycloak.adapters.spi.HttpFacade; @@ -78,7 +79,16 @@ public class KeycloakPreAuthActionsFilter extends GenericFilterBean implements A throws IOException, ServletException { 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); if (handler.handleRequest()) { log.debug("Pre-auth filter handled request: {}", ((HttpServletRequest) request).getRequestURI()); diff --git a/adapters/oidc/spring-security/src/test/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilterTest.java b/adapters/oidc/spring-security/src/test/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilterTest.java index 650febe74c..d23fd8fea6 100644 --- a/adapters/oidc/spring-security/src/test/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilterTest.java +++ b/adapters/oidc/spring-security/src/test/java/org/keycloak/adapters/springsecurity/filter/KeycloakPreAuthActionsFilterTest.java @@ -59,6 +59,7 @@ public class KeycloakPreAuthActionsFilterTest { when(applicationContext.getBean(AdapterDeploymentContext.class)).thenReturn(deploymentContext); when(deploymentContext.resolveDeployment(any(HttpFacade.class))).thenReturn(deployment); when(preAuthActionsHandlerFactory.createPreAuthActionsHandler(any(HttpFacade.class))).thenReturn(preAuthActionsHandler); + when(deployment.isConfigured()).thenReturn(true); filter.initFilterBean(); }