Class JsonUsernamePasswordAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
- com.devonfw.module.security.common.impl.rest.JsonUsernamePasswordAuthenticationFilter
-
- 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.context.MessageSourceAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class JsonUsernamePasswordAuthenticationFilter extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilterProcesses 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_KEYandUsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY. The JSON object properties' names can also be changed by setting theusernameParameterandpasswordParameterproperties. Assuming the default properties' names were not changed, if the credentialsuser/passare 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:
AuthenticationSuccessHandlerSendingOkHttpStatusCodeSimpleUrlAuthenticationFailureHandlercreated using the default constructor (thus leaving thedefaultFailureUrlunset)LogoutSuccessHandlerReturningOkHttpStatusCode
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJsonUsernamePasswordAuthenticationFilter.UsernameAndPasswordParser
-
Field Summary
Fields Modifier and Type Field Description private com.fasterxml.jackson.databind.ObjectMapperobjectMapperprivate StringpasswordParameterprivate booleanpostOnlyprivate StringusernameParameter
-
Constructor Summary
Constructors Constructor Description JsonUsernamePasswordAuthenticationFilter(org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher)The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.security.core.AuthenticationattemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)StringgetPasswordParameter()StringgetUsernameParameter()booleanisPostOnly()voidsetPasswordParameter(String passwordParameter)voidsetPostOnly(boolean postOnly)voidsetUsernameParameter(String usernameParameter)-
Methods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy, successfulAuthentication, unsuccessfulAuthentication
-
-
-
-
Constructor Detail
-
JsonUsernamePasswordAuthenticationFilter
public JsonUsernamePasswordAuthenticationFilter(org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher)
The constructor.- Parameters:
requiresAuthenticationRequestMatcher- theRequestMatcherused to determine if authentication is required. Cannot be null.
-
-
Method Detail
-
attemptAuthentication
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- Specified by:
attemptAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
org.springframework.security.core.AuthenticationExceptionIOExceptionjavax.servlet.ServletException
-
getUsernameParameter
public String getUsernameParameter()
- Returns:
- Value of usernameParameter
-
setUsernameParameter
public void setUsernameParameter(String usernameParameter)
- Parameters:
usernameParameter- new value for usernameParameter
-
getPasswordParameter
public String getPasswordParameter()
- Returns:
- Value of passwordParameter
-
setPasswordParameter
public void setPasswordParameter(String passwordParameter)
- Parameters:
passwordParameter- new value for passwordParameter
-
isPostOnly
public boolean isPostOnly()
- Returns:
- value of postOnly
-
setPostOnly
public void setPostOnly(boolean postOnly)
- Parameters:
postOnly- new value for postOnly
-
-