public class JsonUsernamePasswordAuthenticationFilter
extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
Processes authentication where credentials are sent as a JSON object.
The JSON object must contain two properties: a username and a password. The default properties' names to use are
contained in the static fields UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY and
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY. The JSON object properties' names can
also be changed by setting the usernameParameter and passwordParameter properties. Assuming the
default properties' names were not changed, if the credentials user/pass are to be sent,
the following JSON object is expected:
{
"j_username": "user",
"j_password": "pass",
}
The URL this filter responds to is passed as a constructor parameter.
This authentication filter is intended for One Page Applications which handle a login page/dialog/pop-up on their own. This filter combined with:
AuthenticationSuccessHandlerSendingOkHttpStatusCodeSimpleUrlAuthenticationFailureHandler created using the
default constructor (thus leaving the defaultFailureUrl unset)LogoutSuccessHandlerReturningOkHttpStatusCode| Modifier and Type | Class and Description |
|---|---|
private class |
JsonUsernamePasswordAuthenticationFilter.UsernameAndPasswordParser |
| Modifier and Type | Field and Description |
|---|---|
private com.fasterxml.jackson.databind.ObjectMapper |
objectMapper |
private String |
passwordParameter |
private boolean |
postOnly |
private String |
usernameParameter |
| Constructor and Description |
|---|
JsonUsernamePasswordAuthenticationFilter(org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
org.springframework.security.core.Authentication |
attemptAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
String |
getPasswordParameter() |
String |
getUsernameParameter() |
boolean |
isPostOnly() |
void |
setPasswordParameter(String passwordParameter) |
void |
setPostOnly(boolean postOnly) |
void |
setUsernameParameter(String usernameParameter) |
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy, successfulAuthentication, unsuccessfulAuthenticationprivate String usernameParameter
private String passwordParameter
private boolean postOnly
private com.fasterxml.jackson.databind.ObjectMapper objectMapper
public JsonUsernamePasswordAuthenticationFilter(org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher)
requiresAuthenticationRequestMatcher - the RequestMatcher used to determine if authentication is
required. Cannot be null.public org.springframework.security.core.Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws org.springframework.security.core.AuthenticationException,
IOException,
javax.servlet.ServletException
attemptAuthentication in class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilterorg.springframework.security.core.AuthenticationExceptionIOExceptionjavax.servlet.ServletExceptionpublic String getUsernameParameter()
public void setUsernameParameter(String usernameParameter)
usernameParameter - new value for usernameParameterpublic String getPasswordParameter()
public void setPasswordParameter(String passwordParameter)
passwordParameter - new value for passwordParameterpublic boolean isPostOnly()
public void setPostOnly(boolean postOnly)
postOnly - new value for postOnlyCopyright © 2014–2019 devon4j-Team. All rights reserved.