Class OAuth2LoginAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter
- 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.ApplicationEventPublisherAware,org.springframework.context.EnvironmentAware,org.springframework.context.MessageSourceAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class OAuth2LoginAuthenticationFilter
extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
An implementation of an
AbstractAuthenticationProcessingFilter for OAuth 2.0
Login.
This authentication Filter handles the processing of an OAuth 2.0 Authorization
Response for the authorization code grant flow and delegates an
OAuth2LoginAuthenticationToken to the AuthenticationManager to log in
the End-User.
The OAuth 2.0 Authorization Response is processed as follows:
- Assuming the End-User (Resource Owner) has granted access to the Client, the
Authorization Server will append the
codeandstateparameters to theredirect_uri(provided in the Authorization Request) and redirect the End-User's user-agent back to thisFilter(the Client). - This
Filterwill then create anOAuth2LoginAuthenticationTokenwith thecodereceived and delegate it to theAuthenticationManagerto authenticate. - Upon a successful authentication, an
OAuth2AuthenticationTokenis created (representing the End-UserPrincipal) and associated to theAuthorized Clientusing theOAuth2AuthorizedClientRepository. - Finally, the
OAuth2AuthenticationTokenis returned and ultimately stored in theSecurityContextRepositoryto complete the authentication processing.
- Since:
- 5.0
- See Also:
-
AbstractAuthenticationProcessingFilterOAuth2LoginAuthenticationTokenOAuth2AuthenticationTokenOAuth2LoginAuthenticationProviderOAuth2AuthorizationRequestOAuth2AuthorizationResponseAuthorizationRequestRepositoryOAuth2AuthorizationRequestRedirectFilterClientRegistrationRepositoryOAuth2AuthorizedClientOAuth2AuthorizedClientRepository- Section 4.1 Authorization Code Grant
- Section 4.1.2 Authorization Response
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe defaultURIwhere thisFilterprocesses authentication requests.Fields inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
authenticationDetailsSource, eventPublisher, messagesFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
ConstructorsConstructorDescriptionOAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService, String filterProcessesUrl) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository authorizedClientRepository, String filterProcessesUrl) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.AuthenticationattemptAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) final voidsetAuthenticationResultConverter(org.springframework.core.convert.converter.Converter<OAuth2LoginAuthenticationToken, OAuth2AuthenticationToken> authenticationResultConverter) Sets the converter responsible for converting fromOAuth2LoginAuthenticationTokentoOAuth2AuthenticationTokenauthentication result.final voidsetAuthorizationRequestRepository(AuthorizationRequestRepository<org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest> authorizationRequestRepository) Sets the repository for storedOAuth2AuthorizationRequest's.Methods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSecurityContextHolderStrategy, setSecurityContextRepository, setSessionAuthenticationStrategy, successfulAuthentication, unsuccessfulAuthenticationMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
DEFAULT_FILTER_PROCESSES_URI
The defaultURIwhere thisFilterprocesses authentication requests.- See Also:
-
-
Constructor Details
-
OAuth2LoginAuthenticationFilter
public OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.- Parameters:
clientRegistrationRepository- the repository of client registrationsauthorizedClientService- the authorized client service
-
OAuth2LoginAuthenticationFilter
public OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService, String filterProcessesUrl) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.- Parameters:
clientRegistrationRepository- the repository of client registrationsauthorizedClientService- the authorized client servicefilterProcessesUrl- theURIwhere thisFilterwill process the authentication requests
-
OAuth2LoginAuthenticationFilter
public OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository authorizedClientRepository, String filterProcessesUrl) Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.- Parameters:
clientRegistrationRepository- the repository of client registrationsauthorizedClientRepository- the authorized client repositoryfilterProcessesUrl- theURIwhere thisFilterwill process the authentication requests- Since:
- 5.1
-
-
Method Details
-
attemptAuthentication
public org.springframework.security.core.Authentication attemptAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws org.springframework.security.core.AuthenticationException - Specified by:
attemptAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
org.springframework.security.core.AuthenticationException
-
setAuthorizationRequestRepository
public final void setAuthorizationRequestRepository(AuthorizationRequestRepository<org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest> authorizationRequestRepository) Sets the repository for storedOAuth2AuthorizationRequest's.- Parameters:
authorizationRequestRepository- the repository for storedOAuth2AuthorizationRequest's
-
setAuthenticationResultConverter
public final void setAuthenticationResultConverter(org.springframework.core.convert.converter.Converter<OAuth2LoginAuthenticationToken, OAuth2AuthenticationToken> authenticationResultConverter) Sets the converter responsible for converting fromOAuth2LoginAuthenticationTokentoOAuth2AuthenticationTokenauthentication result.- Parameters:
authenticationResultConverter- the converter forOAuth2AuthenticationToken's- Since:
- 5.6
-