public class OAuth2SessionAuthenticationFilter
extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
Cookie
to establish an authentication user.
The way this filter selects the client session Cookie
is by appending the
OAuth2Utils.CLIENT_ID
request parameter to the
StatelessUtil#getSessionCookiePrefix()
, yielding, for example:
BLSID-[client_id].
If the client session Cookie
exists, this filter will extract the Cookie's
value
, which is expected to be a SignedJWT
. The String
token and
the OAuth2Utils.CLIENT_ID
is then used to construct an
OAuth2SessionAuthenticationToken
.
The OAuth2SessionAuthenticationToken
is then passed to
AuthenticationManager.authenticate(Authentication)
, which usually is then handled by
OAuth2SessionAuthenticationProvider
, unless another provider is implemented to handle
authenticating the token.
Upon a successful authentication, this filter will set the Authentication
on the
SecurityContext
, refresh the client session Cookie
, and proceed with the rest of
the FilterChain
.
Upon a failed authentication, this filter will clear the SecurityContext
, and delegate to
the AuthenticationEntryPoint
to redirect the user to an appropriate location.
Constructor and Description |
---|
OAuth2SessionAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager,
StatelessUtil util,
org.springframework.security.web.AuthenticationEntryPoint authenticationEntrypoint) |
Modifier and Type | Method and Description |
---|---|
org.springframework.security.core.Authentication |
attemptAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
refreshSessionCookie(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.security.core.Authentication authResult)
Helper method used to refresh the expiration on the current session cookie up to the max
expiration time.
|
protected void |
successfulAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain chain,
org.springframework.security.core.Authentication authResult) |
protected void |
unsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.security.core.AuthenticationException failed) |
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy
public OAuth2SessionAuthenticationFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, StatelessUtil util, org.springframework.security.web.AuthenticationEntryPoint authenticationEntrypoint)
public org.springframework.security.core.Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws org.springframework.security.core.AuthenticationException
attemptAuthentication
in class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
org.springframework.security.core.AuthenticationException
protected void successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.Authentication authResult) throws IOException, javax.servlet.ServletException
successfulAuthentication
in class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
IOException
javax.servlet.ServletException
protected void refreshSessionCookie(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authResult)
protected void unsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException failed) throws IOException, javax.servlet.ServletException
unsuccessfulAuthentication
in class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
IOException
javax.servlet.ServletException
Copyright © 2021. All rights reserved.