From e0eac89e5a0f5d4634bf304b87b93ca21514f7fe Mon Sep 17 00:00:00 2001 From: Thomas Raehalme Date: Thu, 10 Sep 2015 12:30:07 +0300 Subject: [PATCH] Added check for null authentication on the logout method. --- .../authentication/KeycloakLogoutHandler.java | 7 +++++-- .../authentication/KeycloakLogoutHandlerTest.java | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/integration/spring-security/src/main/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandler.java b/integration/spring-security/src/main/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandler.java index d843aa7d41..27178ca2ad 100644 --- a/integration/spring-security/src/main/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandler.java +++ b/integration/spring-security/src/main/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandler.java @@ -32,8 +32,11 @@ public class KeycloakLogoutHandler implements LogoutHandler { @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { - - if (!KeycloakAuthenticationToken.class.isAssignableFrom(authentication.getClass())) { + if (authentication == null) { + log.warn("Cannot log out without authentication"); + return; + } + else if (!KeycloakAuthenticationToken.class.isAssignableFrom(authentication.getClass())) { log.warn("Cannot log out a non-Keycloak authentication: {}", authentication); return; } diff --git a/integration/spring-security/src/test/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandlerTest.java b/integration/spring-security/src/test/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandlerTest.java index 2ee32af85e..6a035b5c78 100644 --- a/integration/spring-security/src/test/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandlerTest.java +++ b/integration/spring-security/src/test/java/org/keycloak/adapters/springsecurity/authentication/KeycloakLogoutHandlerTest.java @@ -88,6 +88,12 @@ public class KeycloakLogoutHandlerTest { verifyZeroInteractions(session); } + @Test + public void testLogoutNullAuthentication() throws Exception { + keycloakLogoutHandler.logout(request, response, null); + verifyZeroInteractions(session); + } + @Test public void testHandleSingleSignOut() throws Exception { keycloakLogoutHandler.handleSingleSignOut(request, response, keycloakAuthenticationToken);