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:
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.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.AbstractAuthenticationProcessingFilterAn implementation of anAbstractAuthenticationProcessingFilterfor OAuth 2.0 Login.This authentication
Filterhandles the processing of an OAuth 2.0 Authorization Response for the authorization code grant flow and delegates anOAuth2LoginAuthenticationTokento theAuthenticationManagerto 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:
AbstractAuthenticationProcessingFilter,OAuth2LoginAuthenticationToken,OAuth2AuthenticationToken,OAuth2LoginAuthenticationProvider,OAuth2AuthorizationRequest,OAuth2AuthorizationResponse,AuthorizationRequestRepository,OAuth2AuthorizationRequestRedirectFilter,ClientRegistrationRepository,OAuth2AuthorizedClient,OAuth2AuthorizedClientRepository, Section 4.1 Authorization Code Grant, Section 4.1.2 Authorization Response
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_FILTER_PROCESSES_URIThe defaultURIwhere thisFilterprocesses authentication requests.
-
Constructor Summary
Constructors Constructor Description OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService)Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientService authorizedClientService, java.lang.String filterProcessesUrl)Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository, OAuth2AuthorizedClientRepository authorizedClientRepository, java.lang.String filterProcessesUrl)Constructs anOAuth2LoginAuthenticationFilterusing the provided parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.security.core.AuthenticationattemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)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, setSessionAuthenticationStrategy, successfulAuthentication, unsuccessfulAuthentication
-
-
-
-
Field Detail
-
DEFAULT_FILTER_PROCESSES_URI
public static final java.lang.String DEFAULT_FILTER_PROCESSES_URI
The defaultURIwhere thisFilterprocesses authentication requests.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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, java.lang.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, java.lang.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 Detail
-
attemptAuthentication
public org.springframework.security.core.Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.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
-
-