Class LogoutConfigurer<H extends HttpSecurityBuilder<H>>
java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<LogoutConfigurer<H>,H>
org.springframework.security.config.annotation.web.configurers.LogoutConfigurer<H>
- All Implemented Interfaces:
SecurityConfigurer<DefaultSecurityFilterChain,H>
public final class LogoutConfigurer<H extends HttpSecurityBuilder<H>>
extends AbstractHttpConfigurer<LogoutConfigurer<H>,H>
Adds logout support. Other
SecurityConfigurer instances may invoke
addLogoutHandler(LogoutHandler) in the init(HttpSecurityBuilder)
phase.
Security Filters
The following Filters are populatedShared Objects Created
No shared Objects are createdShared Objects Used
No shared objects are used.- Since:
- 3.2
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddLogoutHandler(LogoutHandler logoutHandler) Adds aLogoutHandler.clearAuthentication(boolean clearAuthentication) Specifies ifSecurityContextLogoutHandlershould clear theAuthenticationat the time of logout.voidConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.defaultLogoutSuccessHandlerFor(LogoutSuccessHandler handler, RequestMatcher preferredMatcher) Sets a defaultLogoutSuccessHandlerto be used which prefers being invoked for the providedRequestMatcher.deleteCookies(String... cookieNamesToClear) Allows specifying the names of cookies to be removed on logout success.Gets theLogoutHandlerinstances that will be used.Gets theLogoutSuccessHandlerif not null, otherwise creates a newSimpleUrlLogoutSuccessHandlerusing thelogoutSuccessUrl(String).voidInitialize theSecurityBuilder.invalidateHttpSession(boolean invalidateHttpSession) ConfiguresSecurityContextLogoutHandlerto invalidate theHttpSessionat the time of logout.logoutRequestMatcher(RequestMatcher logoutRequestMatcher) The RequestMatcher that triggers log out to occur.logoutSuccessHandler(LogoutSuccessHandler logoutSuccessHandler) Sets theLogoutSuccessHandlerto use.logoutSuccessUrl(String logoutSuccessUrl) The URL to redirect to after logout has occurred.The URL that triggers log out to occur (default is "/logout").A shortcut forpermitAll(boolean)withtrueas an argument.permitAll(boolean permitAll) Grants access to thelogoutSuccessUrl(String)and thelogoutUrl(String)for every user.Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, getSecurityContextHolderStrategy, withObjectPostProcessor, withObjectPostProcessorMethods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
Constructor Details
-
LogoutConfigurer
public LogoutConfigurer()Creates a new instance- See Also:
-
-
Method Details
-
addLogoutHandler
Adds aLogoutHandler.SecurityContextLogoutHandlerandLogoutSuccessEventPublishingLogoutHandlerare added as lastLogoutHandlerinstances by default.- Parameters:
logoutHandler- theLogoutHandlerto add- Returns:
- the
LogoutConfigurerfor further customization
-
clearAuthentication
Specifies ifSecurityContextLogoutHandlershould clear theAuthenticationat the time of logout.- Parameters:
clearAuthentication- trueSecurityContextLogoutHandlershould clear theAuthentication(default), or false otherwise.- Returns:
- the
LogoutConfigurerfor further customization
-
invalidateHttpSession
ConfiguresSecurityContextLogoutHandlerto invalidate theHttpSessionat the time of logout.- Parameters:
invalidateHttpSession- true if theHttpSessionshould be invalidated (default), or false otherwise.- Returns:
- the
LogoutConfigurerfor further customization
-
logoutUrl
The URL that triggers log out to occur (default is "/logout"). If CSRF protection is enabled (default), then the request must also be a POST. This means that by default POST "/logout" is required to trigger a log out. If CSRF protection is disabled, then any HTTP method is allowed.It is considered best practice to use an HTTP POST on any action that changes state (i.e. log out) to protect against CSRF attacks. If you really want to use an HTTP GET, you can use
logoutRequestMatcher(PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GEt, logoutUrl));- Parameters:
logoutUrl- the URL that will invoke logout.- Returns:
- the
LogoutConfigurerfor further customization - See Also:
-
logoutRequestMatcher
The RequestMatcher that triggers log out to occur. In most circumstances users will uselogoutUrl(String)which helps enforce good practices.- Parameters:
logoutRequestMatcher- the RequestMatcher used to determine if logout should occur.- Returns:
- the
LogoutConfigurerfor further customization - See Also:
-
logoutSuccessUrl
The URL to redirect to after logout has occurred. The default is "/login?logout". This is a shortcut for invokinglogoutSuccessHandler(LogoutSuccessHandler)with aSimpleUrlLogoutSuccessHandler.- Parameters:
logoutSuccessUrl- the URL to redirect to after logout occurred- Returns:
- the
LogoutConfigurerfor further customization
-
permitAll
A shortcut forpermitAll(boolean)withtrueas an argument.- Returns:
- the
LogoutConfigurerfor further customizations
-
deleteCookies
Allows specifying the names of cookies to be removed on logout success. This is a shortcut to easily invokeaddLogoutHandler(LogoutHandler)with aCookieClearingLogoutHandler.- Parameters:
cookieNamesToClear- the names of cookies to be removed on logout success.- Returns:
- the
LogoutConfigurerfor further customization
-
logoutSuccessHandler
Sets theLogoutSuccessHandlerto use. If this is specified,logoutSuccessUrl(String)is ignored.- Parameters:
logoutSuccessHandler- theLogoutSuccessHandlerto use after a user has been logged out.- Returns:
- the
LogoutConfigurerfor further customizations
-
defaultLogoutSuccessHandlerFor
public LogoutConfigurer<H> defaultLogoutSuccessHandlerFor(LogoutSuccessHandler handler, RequestMatcher preferredMatcher) Sets a defaultLogoutSuccessHandlerto be used which prefers being invoked for the providedRequestMatcher. If noLogoutSuccessHandleris specified aSimpleUrlLogoutSuccessHandlerwill be used. If any defaultLogoutSuccessHandlerinstances are configured, then aDelegatingLogoutSuccessHandlerwill be used that defaults to aSimpleUrlLogoutSuccessHandler.- Parameters:
handler- theLogoutSuccessHandlerto usepreferredMatcher- theRequestMatcherfor this defaultLogoutSuccessHandler- Returns:
- the
LogoutConfigurerfor further customizations
-
permitAll
Grants access to thelogoutSuccessUrl(String)and thelogoutUrl(String)for every user.- Parameters:
permitAll- if true grants access, else nothing is done- Returns:
- the
LogoutConfigurerfor further customization.
-
getLogoutSuccessHandler
Gets theLogoutSuccessHandlerif not null, otherwise creates a newSimpleUrlLogoutSuccessHandlerusing thelogoutSuccessUrl(String).- Returns:
- the
LogoutSuccessHandlerto use
-
init
Description copied from interface:SecurityConfigurerInitialize theSecurityBuilder. Here only shared state should be created and modified, but not properties on theSecurityBuilderused for building the object. This ensures that theSecurityConfigurer.configure(SecurityBuilder)method uses the correct shared objects when building. Configurers should be applied here.- Specified by:
initin interfaceSecurityConfigurer<DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>> - Overrides:
initin classSecurityConfigurerAdapter<DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
configure
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>> - Overrides:
configurein classSecurityConfigurerAdapter<DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>> - Throws:
Exception
-
getLogoutHandlers
Gets theLogoutHandlerinstances that will be used.- Returns:
- the
LogoutHandlerinstances. Cannot be null.
-