Class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>
java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<T,B>
org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer<B,OAuth2LoginConfigurer<B>,org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter>
org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer<B>
- All Implemented Interfaces:
SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B>
public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>
extends AbstractAuthenticationFilterConfigurer<B,OAuth2LoginConfigurer<B>,org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter>
An
AbstractHttpConfigurer for OAuth 2.0 Login, which leverages the OAuth 2.0
Authorization Code Grant Flow.
OAuth 2.0 Login provides an application with the capability to have users log in by using their existing account at an OAuth 2.0 or OpenID Connect 1.0 Provider.
Defaults are provided for all configuration options with the only required
configuration being
clientRegistrationRepository(ClientRegistrationRepository). Alternatively, a
ClientRegistrationRepository @Bean may be registered instead.
Security Filters
The followingFilter's are populated:
OAuth2AuthorizationRequestRedirectFilterOAuth2LoginAuthenticationFilter
Shared Objects Created
The following shared objects are populated:ClientRegistrationRepository(required)OAuth2AuthorizedClientRepository(optional)GrantedAuthoritiesMapper(optional)
Shared Objects Used
The following shared objects are used:ClientRegistrationRepositoryOAuth2AuthorizedClientRepositoryGrantedAuthoritiesMapperDefaultLoginPageGeneratingFilter- ifloginPage(String)is not configured andDefaultLoginPageGeneratingFilteris available, then a default login page will be made availableOidcSessionRegistry
- Since:
- 5.0
- See Also:
-
HttpSecurity.oauth2Login()OAuth2AuthorizationRequestRedirectFilterOAuth2LoginAuthenticationFilterClientRegistrationRepositoryOAuth2AuthorizedClientRepositoryAbstractAuthenticationFilterConfigurer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classConfiguration options for the Authorization Server's Authorization Endpoint.final classConfiguration options for the Client's Redirection Endpoint.final classConfiguration options for the Authorization Server's Token Endpoint.final classConfiguration options for the Authorization Server's UserInfo Endpoint. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDeprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0.authorizationEndpoint(Customizer<OAuth2LoginConfigurer<B>.AuthorizationEndpointConfig> authorizationEndpointCustomizer) Configures the Authorization Server's Authorization Endpoint.authorizedClientRepository(org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository) Sets the repository for authorized client(s).authorizedClientService(org.springframework.security.oauth2.client.OAuth2AuthorizedClientService authorizedClientService) Sets the service for authorized client(s).clientRegistrationRepository(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository) Sets the repository of client registrations.voidConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.protected org.springframework.security.web.util.matcher.RequestMatchercreateLoginProcessingUrlMatcher(String loginProcessingUrl) Create theRequestMatchergiven a loginProcessingUrlvoidInitialize theSecurityBuilder.Specifies the URL to send users to if login is required.loginProcessingUrl(String loginProcessingUrl) Specifies the URL to validate the credentials.oidcSessionRegistry(org.springframework.security.oauth2.client.oidc.session.OidcSessionRegistry oidcSessionRegistry) Sets the registry for managing the OIDC client-provider session linkDeprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0.redirectionEndpoint(Customizer<OAuth2LoginConfigurer<B>.RedirectionEndpointConfig> redirectionEndpointCustomizer) Configures the Client's Redirection Endpoint.Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0.tokenEndpoint(Customizer<OAuth2LoginConfigurer<B>.TokenEndpointConfig> tokenEndpointCustomizer) Configures the Authorization Server's Token Endpoint.Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0.userInfoEndpoint(Customizer<OAuth2LoginConfigurer<B>.UserInfoEndpointConfig> userInfoEndpointCustomizer) Configures the Authorization Server's UserInfo Endpoint.Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer
authenticationDetailsSource, defaultSuccessUrl, defaultSuccessUrl, failureHandler, failureUrl, getAuthenticationEntryPoint, getAuthenticationEntryPointMatcher, getAuthenticationFilter, getFailureUrl, getLoginPage, getLoginProcessingUrl, isCustomLoginPage, permitAll, permitAll, registerAuthenticationEntryPoint, registerDefaultAuthenticationEntryPoint, securityContextRepository, setAuthenticationFilter, successHandler, updateAccessDefaults, updateAuthenticationDefaultsMethods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, getSecurityContextHolderStrategy, withObjectPostProcessor, withObjectPostProcessorMethods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
Constructor Details
-
OAuth2LoginConfigurer
public OAuth2LoginConfigurer()
-
-
Method Details
-
clientRegistrationRepository
public OAuth2LoginConfigurer<B> clientRegistrationRepository(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository) Sets the repository of client registrations.- Parameters:
clientRegistrationRepository- the repository of client registrations- Returns:
- the
OAuth2LoginConfigurerfor further configuration
-
authorizedClientRepository
public OAuth2LoginConfigurer<B> authorizedClientRepository(org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository) Sets the repository for authorized client(s).- Parameters:
authorizedClientRepository- the authorized client repository- Returns:
- the
OAuth2LoginConfigurerfor further configuration - Since:
- 5.1
-
authorizedClientService
public OAuth2LoginConfigurer<B> authorizedClientService(org.springframework.security.oauth2.client.OAuth2AuthorizedClientService authorizedClientService) Sets the service for authorized client(s).- Parameters:
authorizedClientService- the authorized client service- Returns:
- the
OAuth2LoginConfigurerfor further configuration
-
loginPage
Description copied from class:AbstractAuthenticationFilterConfigurerSpecifies the URL to send users to if login is required. If used with
EnableWebSecuritya default login page will be generated when this attribute is not specified.If a URL is specified or this is not being used in conjunction with
EnableWebSecurity, users are required to process the specified URL to generate a login page.- Overrides:
loginPagein classAbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter>
-
loginProcessingUrl
Description copied from class:AbstractAuthenticationFilterConfigurerSpecifies the URL to validate the credentials.- Overrides:
loginProcessingUrlin classAbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter> - Parameters:
loginProcessingUrl- the URL to validate username and password- Returns:
- the
FormLoginConfigurerfor additional customization
-
oidcSessionRegistry
public OAuth2LoginConfigurer<B> oidcSessionRegistry(org.springframework.security.oauth2.client.oidc.session.OidcSessionRegistry oidcSessionRegistry) Sets the registry for managing the OIDC client-provider session link- Parameters:
oidcSessionRegistry- theOidcSessionRegistryto use- Returns:
- the
OAuth2LoginConfigurerfor further configuration - Since:
- 6.2
-
authorizationEndpoint
@Deprecated(since="6.1", forRemoval=true) public OAuth2LoginConfigurer<B>.AuthorizationEndpointConfig authorizationEndpoint()Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0. UseauthorizationEndpoint(Customizer)insteadReturns theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationEndpointConfigfor configuring the Authorization Server's Authorization Endpoint.- Returns:
- the
OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationEndpointConfig
-
authorizationEndpoint
public OAuth2LoginConfigurer<B> authorizationEndpoint(Customizer<OAuth2LoginConfigurer<B>.AuthorizationEndpointConfig> authorizationEndpointCustomizer) Configures the Authorization Server's Authorization Endpoint.- Parameters:
authorizationEndpointCustomizer- theCustomizerto provide more options for theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationEndpointConfig- Returns:
- the
OAuth2LoginConfigurerfor further customizations
-
tokenEndpoint
@Deprecated(since="6.1", forRemoval=true) public OAuth2LoginConfigurer<B>.TokenEndpointConfig tokenEndpoint()Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0. UsetokenEndpoint(Customizer)ortokenEndpoint(Customizer.withDefaults())to stick with defaults. See the documentation for more details.Returns theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.TokenEndpointConfigfor configuring the Authorization Server's Token Endpoint.- Returns:
- the
OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.TokenEndpointConfig
-
tokenEndpoint
public OAuth2LoginConfigurer<B> tokenEndpoint(Customizer<OAuth2LoginConfigurer<B>.TokenEndpointConfig> tokenEndpointCustomizer) Configures the Authorization Server's Token Endpoint.- Parameters:
tokenEndpointCustomizer- theCustomizerto provide more options for theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.TokenEndpointConfig- Returns:
- the
OAuth2LoginConfigurerfor further customizations - Throws:
Exception
-
redirectionEndpoint
@Deprecated(since="6.1", forRemoval=true) public OAuth2LoginConfigurer<B>.RedirectionEndpointConfig redirectionEndpoint()Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0. UseredirectionEndpoint(Customizer)insteadReturns theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.RedirectionEndpointConfigfor configuring the Client's Redirection Endpoint.- Returns:
- the
OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.RedirectionEndpointConfig
-
redirectionEndpoint
public OAuth2LoginConfigurer<B> redirectionEndpoint(Customizer<OAuth2LoginConfigurer<B>.RedirectionEndpointConfig> redirectionEndpointCustomizer) Configures the Client's Redirection Endpoint.- Parameters:
redirectionEndpointCustomizer- theCustomizerto provide more options for theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.RedirectionEndpointConfig- Returns:
- the
OAuth2LoginConfigurerfor further customizations
-
userInfoEndpoint
@Deprecated(since="6.1", forRemoval=true) public OAuth2LoginConfigurer<B>.UserInfoEndpointConfig userInfoEndpoint()Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0. UseuserInfoEndpoint(Customizer)oruserInfoEndpoint(Customizer.withDefaults())to stick with defaults. See the documentation for more details.Returns theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.UserInfoEndpointConfigfor configuring the Authorization Server's UserInfo Endpoint.- Returns:
- the
OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.UserInfoEndpointConfig
-
userInfoEndpoint
public OAuth2LoginConfigurer<B> userInfoEndpoint(Customizer<OAuth2LoginConfigurer<B>.UserInfoEndpointConfig> userInfoEndpointCustomizer) Configures the Authorization Server's UserInfo Endpoint.- Parameters:
userInfoEndpointCustomizer- theCustomizerto provide more options for theOAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>.UserInfoEndpointConfig- Returns:
- the
OAuth2LoginConfigurerfor further customizations
-
init
Description copied from interface:SecurityConfigurerInitialize theSecurityBuilder. Here only shared state should be created and modified, but not properties on theSecurityBuilderused for building the object. This ensures that theSecurityConfigurer.configure(SecurityBuilder)method uses the correct shared objects when building. Configurers should be applied here.- Specified by:
initin interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>> - Overrides:
initin classAbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter> - Throws:
Exception
-
configure
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>> - Overrides:
configurein classAbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter> - Throws:
Exception
-
createLoginProcessingUrlMatcher
protected org.springframework.security.web.util.matcher.RequestMatcher createLoginProcessingUrlMatcher(String loginProcessingUrl) Description copied from class:AbstractAuthenticationFilterConfigurerCreate theRequestMatchergiven a loginProcessingUrl- Specified by:
createLoginProcessingUrlMatcherin classAbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>, org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter> - Parameters:
loginProcessingUrl- creates theRequestMatcherbased upon the loginProcessingUrl- Returns:
- the
RequestMatcherto use based upon the loginProcessingUrl
-