Class BearerTokenAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.security.oauth2.server.resource.web.authentication.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
- Direct Known Subclasses:
BearerTokenAuthenticationFilter
public class BearerTokenAuthenticationFilter
extends org.springframework.web.filter.OncePerRequestFilter
Authenticates requests that contain an OAuth 2.0
Bearer
Token.
This filter should be wired with an
AuthenticationManager that can authenticate
a BearerTokenAuthenticationToken.- Since:
- 5.1
- 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
ConstructorsConstructorDescriptionBearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Construct aBearerTokenAuthenticationFilterusing the provided parameter(s)BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManagerResolver<jakarta.servlet.http.HttpServletRequest> authenticationManagerResolver) Construct aBearerTokenAuthenticationFilterusing the provided parameter(s) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) Extract any Bearer Token from the request and attempt an authentication.voidsetAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set theAuthenticationDetailsSourceto use.voidsetAuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint) Set theAuthenticationEntryPointto use.voidsetAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler authenticationFailureHandler) Set theAuthenticationFailureHandlerto use.voidsetBearerTokenResolver(BearerTokenResolver bearerTokenResolver) Set theBearerTokenResolverto use.voidsetSecurityContextHolderStrategy(org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.voidsetSecurityContextRepository(org.springframework.security.web.context.SecurityContextRepository securityContextRepository) Sets theSecurityContextRepositoryto save theSecurityContexton authentication success.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
public BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManagerResolver<jakarta.servlet.http.HttpServletRequest> authenticationManagerResolver) Construct aBearerTokenAuthenticationFilterusing the provided parameter(s)- Parameters:
authenticationManagerResolver-
-
BearerTokenAuthenticationFilter
public BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Construct aBearerTokenAuthenticationFilterusing the provided parameter(s)- Parameters:
authenticationManager-
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException Extract any Bearer Token from the request and attempt an authentication.- Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Parameters:
request-response-filterChain-- Throws:
jakarta.servlet.ServletExceptionIOException
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
setSecurityContextRepository
public void setSecurityContextRepository(org.springframework.security.web.context.SecurityContextRepository securityContextRepository) Sets theSecurityContextRepositoryto save theSecurityContexton authentication success. The default action is not to save theSecurityContext.- Parameters:
securityContextRepository- theSecurityContextRepositoryto use. Cannot be null.
-
setBearerTokenResolver
Set theBearerTokenResolverto use. Defaults toDefaultBearerTokenResolver.- Parameters:
bearerTokenResolver- theBearerTokenResolverto use
-
setAuthenticationEntryPoint
public void setAuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint) Set theAuthenticationEntryPointto use. Defaults toBearerTokenAuthenticationEntryPoint.- Parameters:
authenticationEntryPoint- theAuthenticationEntryPointto use
-
setAuthenticationFailureHandler
public void setAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler authenticationFailureHandler) Set theAuthenticationFailureHandlerto use. Default implementation invokesAuthenticationEntryPoint.- Parameters:
authenticationFailureHandler- theAuthenticationFailureHandlerto use- Since:
- 5.2
-
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) Set theAuthenticationDetailsSourceto use. Defaults toWebAuthenticationDetailsSource.- Parameters:
authenticationDetailsSource- theAuthenticationConverterto use- Since:
- 5.5
-