Class LogoutConfigurer<H extends HttpSecurityBuilder<H>>
- java.lang.Object
-
- org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.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<org.springframework.security.web.DefaultSecurityFilterChain,H>
public final class LogoutConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<LogoutConfigurer<H>,H>
Adds logout support. OtherSecurityConfigurerinstances may invokeaddLogoutHandler(LogoutHandler)in theinit(HttpSecurityBuilder)phase.Security Filters
The following Filters are populatedLogoutFilter
Shared Objects Created
No shared Objects are createdShared Objects Used
No shared objects are used.- Since:
- 3.2
- See Also:
RememberMeConfigurer
-
-
Constructor Summary
Constructors Constructor Description LogoutConfigurer()Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LogoutConfigurer<H>addLogoutHandler(org.springframework.security.web.authentication.logout.LogoutHandler logoutHandler)Adds aLogoutHandler.LogoutConfigurer<H>clearAuthentication(boolean clearAuthentication)Specifies ifSecurityContextLogoutHandlershould clear theAuthenticationat the time of logout.voidconfigure(H http)Configure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.LogoutConfigurer<H>defaultLogoutSuccessHandlerFor(org.springframework.security.web.authentication.logout.LogoutSuccessHandler handler, org.springframework.security.web.util.matcher.RequestMatcher preferredMatcher)Sets a defaultLogoutSuccessHandlerto be used which prefers being invoked for the providedRequestMatcher.LogoutConfigurer<H>deleteCookies(java.lang.String... cookieNamesToClear)Allows specifying the names of cookies to be removed on logout success.java.util.List<org.springframework.security.web.authentication.logout.LogoutHandler>getLogoutHandlers()Gets theLogoutHandlerinstances that will be used.org.springframework.security.web.authentication.logout.LogoutSuccessHandlergetLogoutSuccessHandler()Gets theLogoutSuccessHandlerif not null, otherwise creates a newSimpleUrlLogoutSuccessHandlerusing thelogoutSuccessUrl(String).voidinit(H http)Initialize theSecurityBuilder.LogoutConfigurer<H>invalidateHttpSession(boolean invalidateHttpSession)ConfiguresSecurityContextLogoutHandlerto invalidate theHttpSessionat the time of logout.LogoutConfigurer<H>logoutRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher logoutRequestMatcher)The RequestMatcher that triggers log out to occur.LogoutConfigurer<H>logoutSuccessHandler(org.springframework.security.web.authentication.logout.LogoutSuccessHandler logoutSuccessHandler)Sets theLogoutSuccessHandlerto use.LogoutConfigurer<H>logoutSuccessUrl(java.lang.String logoutSuccessUrl)The URL to redirect to after logout has occurred.LogoutConfigurer<H>logoutUrl(java.lang.String logoutUrl)The URL that triggers log out to occur (default is "/logout").LogoutConfigurer<H>permitAll()A shortcut forpermitAll(boolean)withtrueas an argument.LogoutConfigurer<H>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
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
-
-
-
Constructor Detail
-
LogoutConfigurer
public LogoutConfigurer()
Creates a new instance- See Also:
HttpSecurity.logout()
-
-
Method Detail
-
addLogoutHandler
public LogoutConfigurer<H> addLogoutHandler(org.springframework.security.web.authentication.logout.LogoutHandler logoutHandler)
Adds aLogoutHandler.SecurityContextLogoutHandlerandLogoutSuccessEventPublishingLogoutHandlerare added as lastLogoutHandlerinstances by default.- Parameters:
logoutHandler- theLogoutHandlerto add- Returns:
- the
LogoutConfigurerfor further customization
-
clearAuthentication
public LogoutConfigurer<H> clearAuthentication(boolean clearAuthentication)
Specifies ifSecurityContextLogoutHandlershould clear theAuthenticationat the time of logout.- Parameters:
clearAuthentication- trueSecurityContextLogoutHandlershould clear theAuthentication(default), or false otherwise.- Returns:
- the
LogoutConfigurerfor further customization
-
invalidateHttpSession
public LogoutConfigurer<H> invalidateHttpSession(boolean 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
public LogoutConfigurer<H> logoutUrl(java.lang.String 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(new AntPathRequestMatcher(logoutUrl, "GET"));- Parameters:
logoutUrl- the URL that will invoke logout.- Returns:
- the
LogoutConfigurerfor further customization - See Also:
logoutRequestMatcher(RequestMatcher),HttpSecurity.csrf()
-
logoutRequestMatcher
public LogoutConfigurer<H> logoutRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher 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:
logoutUrl(String)
-
logoutSuccessUrl
public LogoutConfigurer<H> logoutSuccessUrl(java.lang.String 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
public LogoutConfigurer<H> permitAll()
A shortcut forpermitAll(boolean)withtrueas an argument.- Returns:
- the
LogoutConfigurerfor further customizations
-
deleteCookies
public LogoutConfigurer<H> deleteCookies(java.lang.String... cookieNamesToClear)
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
public LogoutConfigurer<H> logoutSuccessHandler(org.springframework.security.web.authentication.logout.LogoutSuccessHandler 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(org.springframework.security.web.authentication.logout.LogoutSuccessHandler handler, org.springframework.security.web.util.matcher.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
public LogoutConfigurer<H> permitAll(boolean 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
public org.springframework.security.web.authentication.logout.LogoutSuccessHandler getLogoutSuccessHandler()
Gets theLogoutSuccessHandlerif not null, otherwise creates a newSimpleUrlLogoutSuccessHandlerusing thelogoutSuccessUrl(String).- Returns:
- the
LogoutSuccessHandlerto use
-
init
public void init(H http)
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<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
initin classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
configure
public void configure(H http) throws java.lang.Exception
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
configurein classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Throws:
java.lang.Exception
-
getLogoutHandlers
public java.util.List<org.springframework.security.web.authentication.logout.LogoutHandler> getLogoutHandlers()
Gets theLogoutHandlerinstances that will be used.- Returns:
- the
LogoutHandlerinstances. Cannot be null.
-
-