Skip to content

Commit

Permalink
Merge pull request #371 from groldan/bug/pre-auth-gateway-filter-logout
Browse files Browse the repository at this point in the history
Request header pre-auth filter must logout automatically
  • Loading branch information
groldan authored Nov 17, 2023
2 parents 22494f6 + 7838150 commit b435c79
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.geoserver.security.filter.GeoServerSecurityFilter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

import java.io.IOException;

Expand All @@ -36,6 +37,14 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
String principalName = getPreAuthenticatedPrincipalName((HttpServletRequest) request);

Authentication preAuth = SecurityContextHolder.getContext().getAuthentication();

// If a pre-auth token exists but the request has no principal name anymore, clear the
// context, or the user will stay authenticated
if (preAuth instanceof PreAuthenticatedAuthenticationToken && null == principalName) {
SecurityContextHolder.clearContext();
preAuth = null;
}

if (preAuth == null || principalName != null) {
log.debug("Authenticating as {}", principalName);
doAuthenticate((HttpServletRequest) request, (HttpServletResponse) response);
Expand Down

0 comments on commit b435c79

Please sign in to comment.