Class Overview
Processes an authentication form submission. Called AuthenticationProcessingFilter
prior to Spring Security
3.0.
Login forms must present two parameters to this filter: a username and
password. The default parameter names to use are contained in the
static fields SPRING_SECURITY_FORM_USERNAME_KEY
and SPRING_SECURITY_FORM_PASSWORD_KEY
.
The parameter names can also be changed by setting the usernameParameter
and passwordParameter
properties.
This filter by default responds to the URL /j_spring_security_check
.
Summary
Protected Methods |
String
|
obtainPassword(HttpServletRequest request)
Enables subclasses to override the composition of the password, such as by including additional values
and a separator.
|
String
|
obtainUsername(HttpServletRequest request)
Enables subclasses to override the composition of the username, such as by including additional values
and a separator.
|
void
|
setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest)
Provided so that subclasses may configure what is put into the authentication request's details
property.
|
[Expand]
Inherited Methods |
From class
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
void
|
afterPropertiesSet()
|
abstract
Authentication
|
attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
Performs actual authentication.
|
void
|
doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
Invokes the requiresAuthentication
method to determine whether the request is for authentication and should be handled by this filter.
|
boolean
|
getAllowSessionCreation()
|
AuthenticationManager
|
getAuthenticationManager()
|
AuthenticationFailureHandler
|
getFailureHandler()
|
String
|
getFilterProcessesUrl()
|
RememberMeServices
|
getRememberMeServices()
|
AuthenticationSuccessHandler
|
getSuccessHandler()
|
boolean
|
requiresAuthentication(HttpServletRequest request, HttpServletResponse response)
Indicates whether this filter should attempt to process a login request for the current invocation.
|
void
|
setAllowSessionCreation(boolean allowSessionCreation)
|
void
|
setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
|
void
|
setAuthenticationDetailsSource(AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource)
|
void
|
setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
|
void
|
setAuthenticationManager(AuthenticationManager authenticationManager)
|
void
|
setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler)
Sets the strategy used to handle a successful authentication.
|
void
|
setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication)
|
void
|
setFilterProcessesUrl(String filterProcessesUrl)
|
void
|
setMessageSource(MessageSource messageSource)
|
void
|
setRememberMeServices(RememberMeServices rememberMeServices)
|
void
|
setSessionAuthenticationStrategy(SessionAuthenticationStrategy sessionStrategy)
The session handling strategy which will be invoked immediately after an authentication request is
successfully processed by the AuthenticationManager.
|
void
|
successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult)
Default behaviour for successful authentication.
|
void
|
successfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult)
|
void
|
unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed)
Default behaviour for unsuccessful authentication.
|
|
From class
org.springframework.web.filter.GenericFilterBean
final
void
|
addRequiredProperty(String arg0)
|
void
|
afterPropertiesSet()
|
void
|
destroy()
|
final
FilterConfig
|
getFilterConfig()
|
final
String
|
getFilterName()
|
final
ServletContext
|
getServletContext()
|
final
void
|
init(FilterConfig arg0)
|
void
|
initBeanWrapper(BeanWrapper arg0)
|
void
|
initFilterBean()
|
final
void
|
setBeanName(String arg0)
|
final
void
|
setFilterConfig(FilterConfig arg0)
|
final
void
|
setServletContext(ServletContext arg0)
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
javax.servlet.Filter
abstract
void
|
destroy()
|
abstract
void
|
doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
|
abstract
void
|
init(FilterConfig arg0)
|
|
From interface
org.springframework.beans.factory.BeanNameAware
abstract
void
|
setBeanName(String arg0)
|
|
From interface
org.springframework.beans.factory.DisposableBean
|
From interface
org.springframework.beans.factory.InitializingBean
abstract
void
|
afterPropertiesSet()
|
|
From interface
org.springframework.context.ApplicationEventPublisherAware
abstract
void
|
setApplicationEventPublisher(ApplicationEventPublisher arg0)
|
|
From interface
org.springframework.context.MessageSourceAware
abstract
void
|
setMessageSource(MessageSource arg0)
|
|
From interface
org.springframework.web.context.ServletContextAware
abstract
void
|
setServletContext(ServletContext arg0)
|
|
Constants
public
static
final
String
SPRING_SECURITY_FORM_PASSWORD_KEY
Constant Value:
"j_password"
public
static
final
String
SPRING_SECURITY_FORM_USERNAME_KEY
Constant Value:
"j_username"
public
static
final
String
SPRING_SECURITY_LAST_USERNAME_KEY
This constant is deprecated.
If you want to retain the username, cache it in a customized AuthenticationFailureHandler
Constant Value:
"SPRING_SECURITY_LAST_USERNAME"
Public Constructors
public
UsernamePasswordAuthenticationFilter
()
Public Methods
public
Authentication
attemptAuthentication
(HttpServletRequest request, HttpServletResponse response)
Performs actual authentication.
The implementation should do one of the following:
- Return a populated authentication token for the authenticated user, indicating successful authentication
- Return null, indicating that the authentication process is still in progress. Before returning, the
implementation should perform any additional work required to complete the process.
- Throw an AuthenticationException if the authentication process fails
Parameters
request
| from which to extract parameters and perform the authentication |
response
| the response, which may be needed if the implementation has to do a redirect as part of a
multi-stage authentication process (such as OpenID). |
Returns
- the authenticated user token, or null if authentication is incomplete.
public
final
String
getPasswordParameter
()
public
final
String
getUsernameParameter
()
public
void
setPasswordParameter
(String passwordParameter)
Sets the parameter name which will be used to obtain the password from the login request..
Parameters
passwordParameter
| the parameter name. Defaults to "j_password".
|
public
void
setPostOnly
(boolean postOnly)
Defines whether only HTTP POST requests will be allowed by this filter.
If set to true, and an authentication request is received which is not a POST request, an exception will
be raised immediately and authentication will not be attempted. The unsuccessfulAuthentication() method
will be called as if handling a failed authentication.
Defaults to true but may be overridden by subclasses.
public
void
setUsernameParameter
(String usernameParameter)
Sets the parameter name which will be used to obtain the username from the login request.
Parameters
usernameParameter
| the parameter name. Defaults to "j_username".
|
Protected Methods
protected
String
obtainPassword
(HttpServletRequest request)
Enables subclasses to override the composition of the password, such as by including additional values
and a separator.
This might be used for example if a postcode/zipcode was required in addition to the
password. A delimiter such as a pipe (|) should be used to separate the password and extended value(s). The
AuthenticationDao
will need to generate the expected password in a corresponding manner.
Parameters
request
| so that request attributes can be retrieved |
Returns
- the password that will be presented in the
Authentication
request token to the
AuthenticationManager
protected
String
obtainUsername
(HttpServletRequest request)
Enables subclasses to override the composition of the username, such as by including additional values
and a separator.
Parameters
request
| so that request attributes can be retrieved |
Returns
- the username that will be presented in the
Authentication
request token to the
AuthenticationManager
Provided so that subclasses may configure what is put into the authentication request's details
property.
Parameters
request
| that an authentication request is being created for |
authRequest
| the authentication request object that should have its details set
|