Class SecurityTokenAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
net.solarnetwork.central.security.web.SecurityTokenAuthenticationFilter
- All Implemented Interfaces:
jakarta.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 SecurityTokenAuthenticationFilter
extends org.springframework.web.filter.OncePerRequestFilter
implements jakarta.servlet.Filter
Authentication filter for "SolarNetworkWS" style authentication.
This authentication method has been modeled after the Amazon Web Service
authentication scheme used by the S3 service
(http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_Authentication2.html).
The auth token is fixed at AUTH_TOKEN_LENGTH characters. All query
parameters (GET or POST) are added to the request path in the message;
parameters are sorted lexicographically and then their keys and
first value is appended to the path following a ? character
and separated by a & character.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe fixed length of the auth token.static final intThe default value for themaxRequestBodySizeproperty.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.SecurityTokenAuthenticationFilter(org.springframework.util.PathMatcher pathMatcher, String pathMatcherPrefixStrip) Construct with aPathMatcher.SecurityTokenAuthenticationFilter(org.springframework.util.PathMatcher pathMatcher, String pathMatcherPrefixStrip, SecurityTokenFilterSettings settings) Construct with aPathMatcher. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, jakarta.servlet.FilterChain chain) Get the filter settings.org.springframework.security.core.userdetails.UserDetailsServiceGet the user details service.voidsetAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set the details source to use.voidsetAuthenticationEntryPoint(net.solarnetwork.web.jakarta.security.SecurityTokenAuthenticationEntryPoint entryPoint) TheSecurityTokenAuthenticationEntryPointto use as the entry point.voidsetMaxDateSkew(long maxDateSkew) Set the maximum amount of difference in the supplied HTTPDate(orX-SN-Date) header value with the current time as reported by the system.voidsetMaxRequestBodySize(int maxRequestBodySize) Set the maximum allowed request body size.voidsetUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Set the details service, which must return users with valid SolarNetwork usernames (email addresses) and plain-text authorization token secret passwords viaUserDetails.getUsername()andUserDetails.getPassword().Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.Filter
destroy, doFilter, init
-
Field Details
-
AUTH_TOKEN_LENGTH
public static final int AUTH_TOKEN_LENGTHThe fixed length of the auth token.- See Also:
-
DEFAULT_MAX_REQUEST_BODY_SIZE
public static final int DEFAULT_MAX_REQUEST_BODY_SIZEThe default value for themaxRequestBodySizeproperty.- Since:
- 1.3
- See Also:
-
-
Constructor Details
-
SecurityTokenAuthenticationFilter
public SecurityTokenAuthenticationFilter()Default constructor. -
SecurityTokenAuthenticationFilter
public SecurityTokenAuthenticationFilter(org.springframework.util.PathMatcher pathMatcher, String pathMatcherPrefixStrip) Construct with aPathMatcher.- Parameters:
pathMatcher- the matcher to use, or null if not supportedpathMatcherPrefixStrip- a path prefix to strip fromHttpServletRequest.getRequestURI()after anyHttpServletRequest.getContextPath()has been removed, before comparing paths, or null to not strip any prefix- Since:
- 1.5
-
SecurityTokenAuthenticationFilter
public SecurityTokenAuthenticationFilter(org.springframework.util.PathMatcher pathMatcher, String pathMatcherPrefixStrip, SecurityTokenFilterSettings settings) Construct with aPathMatcher.- Parameters:
pathMatcher- the matcher to use, or null if not supportedpathMatcherPrefixStrip- a path prefix to strip fromHttpServletRequest.getRequestURI()after anyHttpServletRequest.getContextPath()has been removed, before comparing paths, or null to not strip any prefixsettings- , or null to create a default instance- Since:
- 1.7
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.web.filter.GenericFilterBean
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, jakarta.servlet.FilterChain chain) throws jakarta.servlet.ServletException, IOException - Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Throws:
jakarta.servlet.ServletExceptionIOException
-
getUserDetailsService
public org.springframework.security.core.userdetails.UserDetailsService getUserDetailsService()Get the user details service.- Returns:
- the service
- Since:
- 1.9
-
setUserDetailsService
public void setUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService) Set the details service, which must return users with valid SolarNetwork usernames (email addresses) and plain-text authorization token secret passwords viaUserDetails.getUsername()andUserDetails.getPassword().After validating the request authorization, this filter will authenticate the user with Spring Security.
- Parameters:
userDetailsService- the service
-
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set the details source to use.Defaults to a
WebAuthenticationDetailsSource.- Parameters:
authenticationDetailsSource- the source to use
-
setMaxDateSkew
public void setMaxDateSkew(long maxDateSkew) Set the maximum amount of difference in the supplied HTTPDate(orX-SN-Date) header value with the current time as reported by the system.If this difference is exceeded, authorization fails.
- Parameters:
maxDateSkew- the maximum allowed date skew
-
setAuthenticationEntryPoint
public void setAuthenticationEntryPoint(net.solarnetwork.web.jakarta.security.SecurityTokenAuthenticationEntryPoint entryPoint) TheSecurityTokenAuthenticationEntryPointto use as the entry point.- Parameters:
entryPoint- the entry point to use
-
setMaxRequestBodySize
public void setMaxRequestBodySize(int maxRequestBodySize) Set the maximum allowed request body size.- Parameters:
maxRequestBodySize- the maximum request body size allowed- Since:
- 1.3
-
getSettings
Get the filter settings.- Returns:
- the settings, never null
- Since:
- 1.7
-