Class SecurityContextLogoutHandler
java.lang.Object
org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler
- All Implemented Interfaces:
LogoutHandler
Performs a logout by modifying the
SecurityContextHolder.
Will also invalidate the HttpSession if isInvalidateHttpSession() is
true and the session is not null.
Will also remove the Authentication from the current SecurityContext if
clearAuthentication is set to true (default).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidlogout(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Authentication authentication) Requires the request to be passed in.voidsetClearAuthentication(boolean clearAuthentication) If true, removes theAuthenticationfrom theSecurityContextto prevent issues with concurrent requests.voidsetInvalidateHttpSession(boolean invalidateHttpSession) Causes theHttpSessionto be invalidated when thisLogoutHandleris invoked.voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.voidsetSecurityContextRepository(SecurityContextRepository securityContextRepository) Sets theSecurityContextRepositoryto use.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
SecurityContextLogoutHandler
public SecurityContextLogoutHandler()
-
-
Method Details
-
logout
public void logout(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Authentication authentication) Requires the request to be passed in.- Specified by:
logoutin interfaceLogoutHandler- Parameters:
request- from which to obtain a HTTP session (cannot be null)response- not used (can benull)authentication- not used (can benull)
-
isInvalidateHttpSession
public boolean isInvalidateHttpSession() -
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
setInvalidateHttpSession
public void setInvalidateHttpSession(boolean invalidateHttpSession) Causes theHttpSessionto be invalidated when thisLogoutHandleris invoked. Defaults to true.- Parameters:
invalidateHttpSession- true if you wish the session to be invalidated (default) or false if it should not be.
-
setClearAuthentication
public void setClearAuthentication(boolean clearAuthentication) If true, removes theAuthenticationfrom theSecurityContextto prevent issues with concurrent requests.- Parameters:
clearAuthentication- true if you wish to clear theAuthenticationfrom theSecurityContext(default) or false if theAuthenticationshould not be removed.
-
setSecurityContextRepository
Sets theSecurityContextRepositoryto use. Default isHttpSessionSecurityContextRepository.- Parameters:
securityContextRepository- theSecurityContextRepositoryto use.
-