Class RememberMeConfigurer<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<RememberMeConfigurer<H>,H>
-
- org.springframework.security.config.annotation.web.configurers.RememberMeConfigurer<H>
-
- All Implemented Interfaces:
SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H>
public final class RememberMeConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<RememberMeConfigurer<H>,H>
Configures Remember Me authentication. This typically involves the user checking a box when they enter their username and password that states to "Remember Me".Security Filters
The following Filters are populatedRememberMeAuthenticationFilter
Shared Objects Created
The following shared objects are populated-
HttpSecurity.authenticationProvider(org.springframework.security.authentication.AuthenticationProvider)is populated with aRememberMeAuthenticationProvider RememberMeServicesis populated as a shared object and available onAbstractConfiguredSecurityBuilder.getSharedObject(Class)LogoutConfigurer.addLogoutHandler(LogoutHandler)is used to add a logout handler to clean up the remember me authentication.
Shared Objects Used
The following shared objects are used:AuthenticationManagerUserDetailsServiceif nouserDetailsService(UserDetailsService)was specified.DefaultLoginPageGeneratingFilter- if present will be populated with information from the configuration
- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description RememberMeConfigurer()Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RememberMeConfigurer<H>alwaysRemember(boolean alwaysRemember)Whether the cookie should always be created even if the remember-me parameter is not set.RememberMeConfigurer<H>authenticationSuccessHandler(org.springframework.security.web.authentication.AuthenticationSuccessHandler authenticationSuccessHandler)Allows control over the destination a remembered user is sent to when they are successfully authenticated.voidconfigure(H http)Configure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.voidinit(H http)Initialize theSecurityBuilder.RememberMeConfigurer<H>key(java.lang.String key)Sets the key to identify tokens created for remember me authentication.RememberMeConfigurer<H>rememberMeCookieDomain(java.lang.String rememberMeCookieDomain)The domain name within which the remember me cookie is visible.RememberMeConfigurer<H>rememberMeCookieName(java.lang.String rememberMeCookieName)The name of cookie which store the token for remember me authentication.RememberMeConfigurer<H>rememberMeParameter(java.lang.String rememberMeParameter)The HTTP parameter used to indicate to remember the user at time of login.RememberMeConfigurer<H>rememberMeServices(org.springframework.security.web.authentication.RememberMeServices rememberMeServices)Specify theRememberMeServicesto use.RememberMeConfigurer<H>tokenRepository(org.springframework.security.web.authentication.rememberme.PersistentTokenRepository tokenRepository)Specifies thePersistentTokenRepositoryto use.RememberMeConfigurer<H>tokenValiditySeconds(int tokenValiditySeconds)Allows specifying how long (in seconds) a token is valid forRememberMeConfigurer<H>userDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService)Specifies theUserDetailsServiceused to look up theUserDetailswhen a remember me token is valid.RememberMeConfigurer<H>useSecureCookie(boolean useSecureCookie)Whether the cookie should be flagged as secure or not.-
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, withObjectPostProcessor
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
-
-
-
Method Detail
-
tokenValiditySeconds
public RememberMeConfigurer<H> tokenValiditySeconds(int tokenValiditySeconds)
Allows specifying how long (in seconds) a token is valid for- Parameters:
tokenValiditySeconds-- Returns:
RememberMeConfigurerfor further customization- See Also:
AbstractRememberMeServices.setTokenValiditySeconds(int)
-
useSecureCookie
public RememberMeConfigurer<H> useSecureCookie(boolean useSecureCookie)
Whether the cookie should be flagged as secure or not. Secure cookies can only be sent over an HTTPS connection and thus cannot be accidentally submitted over HTTP where they could be intercepted.By default the cookie will be secure if the request is secure. If you only want to use remember-me over HTTPS (recommended) you should set this property to
true.- Parameters:
useSecureCookie- set totrueto always user secure cookies,falseto disable their use.- Returns:
- the
RememberMeConfigurerfor further customization - See Also:
AbstractRememberMeServices.setUseSecureCookie(boolean)
-
userDetailsService
public RememberMeConfigurer<H> userDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService)
Specifies theUserDetailsServiceused to look up theUserDetailswhen a remember me token is valid. When using aSecurityFilterChainbean, the default is to look for aUserDetailsServicebean. Alternatively, one can populaterememberMeServices(RememberMeServices).- Parameters:
userDetailsService- theUserDetailsServiceto configure- Returns:
- the
RememberMeConfigurerfor further customization - See Also:
AbstractRememberMeServices
-
tokenRepository
public RememberMeConfigurer<H> tokenRepository(org.springframework.security.web.authentication.rememberme.PersistentTokenRepository tokenRepository)
Specifies thePersistentTokenRepositoryto use. The default is to useTokenBasedRememberMeServicesinstead.- Parameters:
tokenRepository- thePersistentTokenRepositoryto use- Returns:
- the
RememberMeConfigurerfor further customization
-
key
public RememberMeConfigurer<H> key(java.lang.String key)
Sets the key to identify tokens created for remember me authentication. Default is a secure randomly generated key. IfrememberMeServices(RememberMeServices)is specified and is of typeAbstractRememberMeServices, then the default is the key set inAbstractRememberMeServices.- Parameters:
key- the key to identify tokens created for remember me authentication- Returns:
- the
RememberMeConfigurerfor further customization
-
rememberMeParameter
public RememberMeConfigurer<H> rememberMeParameter(java.lang.String rememberMeParameter)
The HTTP parameter used to indicate to remember the user at time of login.- Parameters:
rememberMeParameter- the HTTP parameter used to indicate to remember the user- Returns:
- the
RememberMeConfigurerfor further customization
-
rememberMeCookieName
public RememberMeConfigurer<H> rememberMeCookieName(java.lang.String rememberMeCookieName)
The name of cookie which store the token for remember me authentication. Defaults to 'remember-me'.- Parameters:
rememberMeCookieName- the name of cookie which store the token for remember me authentication- Returns:
- the
RememberMeConfigurerfor further customization - Since:
- 4.0.1
-
rememberMeCookieDomain
public RememberMeConfigurer<H> rememberMeCookieDomain(java.lang.String rememberMeCookieDomain)
The domain name within which the remember me cookie is visible.- Parameters:
rememberMeCookieDomain- the domain name within which the remember me cookie is visible.- Returns:
- the
RememberMeConfigurerfor further customization - Since:
- 4.1.0
-
authenticationSuccessHandler
public RememberMeConfigurer<H> authenticationSuccessHandler(org.springframework.security.web.authentication.AuthenticationSuccessHandler authenticationSuccessHandler)
Allows control over the destination a remembered user is sent to when they are successfully authenticated. By default, the filter will just allow the current request to proceed, but if anAuthenticationSuccessHandleris set, it will be invoked and thedoFilter()method will return immediately, thus allowing the application to redirect the user to a specific URL, regardless of what the original request was for.- Parameters:
authenticationSuccessHandler- the strategy to invoke immediately before returning fromdoFilter().- Returns:
RememberMeConfigurerfor further customization- See Also:
RememberMeAuthenticationFilter.setAuthenticationSuccessHandler(AuthenticationSuccessHandler)
-
rememberMeServices
public RememberMeConfigurer<H> rememberMeServices(org.springframework.security.web.authentication.RememberMeServices rememberMeServices)
Specify theRememberMeServicesto use.- Parameters:
rememberMeServices- theRememberMeServicesto use- Returns:
- the
RememberMeConfigurerfor further customizations - See Also:
RememberMeServices
-
alwaysRemember
public RememberMeConfigurer<H> alwaysRemember(boolean alwaysRemember)
Whether the cookie should always be created even if the remember-me parameter is not set.By default this will be set to
false.- Parameters:
alwaysRemember- set totrueto always trigger remember me,falseto use the remember-me parameter.- Returns:
- the
RememberMeConfigurerfor further customization - See Also:
AbstractRememberMeServices.setAlwaysRemember(boolean)
-
init
public void init(H http) throws java.lang.Exception
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>>- Throws:
java.lang.Exception
-
configure
public void configure(H http)
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>>
-
-