Class BearerTokenAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.web.filter.OncePerRequestFilter
-
- org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter
-
- 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 final class BearerTokenAuthenticationFilter extends org.springframework.web.filter.OncePerRequestFilterAuthenticates requests that contain an OAuth 2.0 Bearer Token. This filter should be wired with anAuthenticationManagerthat can authenticate aBearerTokenAuthenticationToken.- Since:
- 5.1
- See Also:
- The OAuth 2.0
Authorization Framework: Bearer Token Usage,
JwtAuthenticationProvider
-
-
Constructor Summary
Constructors Constructor Description BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager)Construct aBearerTokenAuthenticationFilterusing the provided parameter(s)BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManagerResolver<javax.servlet.http.HttpServletRequest> authenticationManagerResolver)Construct aBearerTokenAuthenticationFilterusing the provided parameter(s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain)Extract any Bearer Token from the request and attempt an authentication.voidsetAuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<javax.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.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, shouldNotFilterErrorDispatch
-
-
-
-
Constructor Detail
-
BearerTokenAuthenticationFilter
public BearerTokenAuthenticationFilter(org.springframework.security.authentication.AuthenticationManagerResolver<javax.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 Detail
-
doFilterInternal
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain) throws javax.servlet.ServletException, java.io.IOExceptionExtract any Bearer Token from the request and attempt an authentication.- Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Parameters:
request-response-filterChain-- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
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
public void setBearerTokenResolver(BearerTokenResolver bearerTokenResolver)
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<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
Set theAuthenticationDetailsSourceto use. Defaults toWebAuthenticationDetailsSource.- Parameters:
authenticationDetailsSource- theAuthenticationConverterto use- Since:
- 5.5
-
-