Class BearerTokenAuthenticationFilter
- 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
Authorization: Bearer <opaque> header
to a Authentication previously issued by AuthWebService.login(AuthWebService.LoginRequest) and stored
in TokenStore.
If the header is present and the token is valid, the corresponding
Authentication is placed on the SecurityContextHolder for the remainder
of the request. If the header is absent or the token is unknown / expired, the filter
is a no-op: the chain continues and the standard
BasicAuthenticationFilter
(registered immediately after this one in RestSecurityConfig) gets a chance to
authenticate via HTTP Basic. This preserves the legacy CLI / script / RClient code paths
that still rely on Basic.
Order: registered via .addFilterBefore(..., BasicAuthenticationFilter.class)
in RestSecurityConfig.
- See Also:
-
Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) static StringextractBearerToken(String headerValue) Extract the bare opaque token from anAuthorizationheader value, ornullif the header is missing / not a Bearer scheme / has an empty token.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, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
BearerTokenAuthenticationFilter
-
-
Method Details
-
extractBearerToken
Extract the bare opaque token from anAuthorizationheader value, ornullif the header is missing / not a Bearer scheme / has an empty token.Public so
AuthWebService.logout(HttpServletRequest)can use the same parsing rule the filter uses (so a logout call with a malformed header still 200s rather than NPE'ing on substring math). -
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException - Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Throws:
jakarta.servlet.ServletExceptionIOException
-