Class RememberMeAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter
-
- All Implemented Interfaces:
javax.servlet.Filter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.EnvironmentAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class RememberMeAuthenticationFilter extends org.springframework.web.filter.GenericFilterBean implements org.springframework.context.ApplicationEventPublisherAwareDetects if there is noAuthenticationobject in theSecurityContext, and populates the context with a remember-me authentication token if aRememberMeServicesimplementation so requests.Concrete
RememberMeServicesimplementations will have theirRememberMeServices.autoLogin(HttpServletRequest, HttpServletResponse)method called by this filter. If this method returns a non-nullAuthenticationobject, it will be passed to theAuthenticationManager, so that any authentication-specific behaviour can be achieved. The resultingAuthentication(if successful) will be placed into theSecurityContext.If authentication is successful, an
InteractiveAuthenticationSuccessEventwill be published to the application context. No events will be published if authentication was unsuccessful, because this would generally be recorded via anAuthenticationManager-specific application event.Normally the request will be allowed to proceed regardless of whether authentication succeeds or fails. If some control over the destination for authenticated users is required, an
AuthenticationSuccessHandlercan be injected
-
-
Constructor Summary
Constructors Constructor Description RememberMeAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, RememberMeServices rememberMeServices)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)RememberMeServicesgetRememberMeServices()protected voidonSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authResult)Called if a remember-me token is presented and successfully authenticated by theRememberMeServicesautoLoginmethod and theAuthenticationManager.protected voidonUnsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException failed)Called if theAuthenticationManagerrejects the authentication object returned from theRememberMeServicesautoLoginmethod.voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)voidsetAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler)Allows control over the destination a remembered user is sent to when they are successfully authenticated.
-
-
-
Constructor Detail
-
RememberMeAuthenticationFilter
public RememberMeAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, RememberMeServices rememberMeServices)
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.web.filter.GenericFilterBean
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
onSuccessfulAuthentication
protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authResult)Called if a remember-me token is presented and successfully authenticated by theRememberMeServicesautoLoginmethod and theAuthenticationManager.
-
onUnsuccessfulAuthentication
protected void onUnsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException failed)Called if theAuthenticationManagerrejects the authentication object returned from theRememberMeServicesautoLoginmethod. This method will not be called when no remember-me token is present in the request andautoLoginreurns null.
-
getRememberMeServices
public RememberMeServices getRememberMeServices()
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
- Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
setAuthenticationSuccessHandler
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler)
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 whatthe original request was for.- Parameters:
successHandler- the strategy to invoke immediately before returning fromdoFilter().
-
-