Package net.solarnetwork.web.security
Class AuthenticationDataTokenAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
net.solarnetwork.web.security.AuthenticationDataTokenAuthenticationFilter
- 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.EnvironmentAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class AuthenticationDataTokenAuthenticationFilter
extends org.springframework.web.filter.OncePerRequestFilter
Authentication filter for
AuthenticationData style token
authentication.
This filter supports the SolarNetworkWS and SNWS2 HTTP
authorization schemes. In addition, a JWT encoded cookie named
sntoken can be generated if a request parameter
sntoken-cookie=true is passed with the request. That cookie can
then be presented on subsequent requests instead of the HTTP authorization.- Version:
- 2.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the cookie used for cookie based tokens.static final StringA request parameter to signal that an authentication cookie should be set on the response.Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.AuthenticationDataTokenAuthenticationFilter(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Construct with aUserDetailsService. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain) voidsetAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set the details source to use.voidsetAuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint) Set anAuthenticationEntryPointto handle authentication errors.voidsetMaxDateSkew(long maxDateSkew) Set the maximum amount of difference in the supplied HTTPDate(or X-SN-Date) header value with the current time as reported by the system.voidsetUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Set the details service.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
REQUEST_PARAM_SET_COOKIE
A request parameter to signal that an authentication cookie should be set on the response.- See Also:
-
COOKIE_NAME_AUTH_TOKEN
The name of the cookie used for cookie based tokens.- See Also:
-
-
Constructor Details
-
AuthenticationDataTokenAuthenticationFilter
public AuthenticationDataTokenAuthenticationFilter()Default constructor. -
AuthenticationDataTokenAuthenticationFilter
public AuthenticationDataTokenAuthenticationFilter(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Construct with aUserDetailsService.- Parameters:
userDetailsService- The service to use.
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain) throws javax.servlet.ServletException, IOException - Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Throws:
javax.servlet.ServletExceptionIOException
-
setUserDetailsService
public void setUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Set the details service. The service must return users with valid token identifiers and plain-text token secret passwords viaUserDetails.getUsername()andUserDetails.getPassword(), respectfully. After validating the request authentication, this filter will authorize the user with Spring Security by callingSecurityContextHolder.getContext().setAuthentication().- Parameters:
userDetailsService- the user details service to use
-
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set the details source to use. This defaults to aWebAuthenticationDetailsSource.- Parameters:
authenticationDetailsSource- the details source to use
-
setMaxDateSkew
public void setMaxDateSkew(long maxDateSkew) Set the maximum amount of difference in the supplied HTTPDate(or X-SN-Date) header value with the current time as reported by the system. If this difference is exceeded, authorization fails.- Parameters:
maxDateSkew- the maximum allowable skew, in milliseconds
-
setAuthenticationEntryPoint
public void setAuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint) Set anAuthenticationEntryPointto handle authentication errors. If this is configured, anyAuthenticationExceptionthrown during processing will be directed to the configured instance. Otherwise those exceptions will be re-thrown.- Parameters:
authenticationEntryPoint- the authenticationEntryPoint to set
-