Add HttpSecurity.oauth2AuthorizationServer()

Issue gh-17880
This commit is contained in:
Joe Grandja 2025-09-12 04:29:52 -04:00
parent 098574c50e
commit 7ef25cc101
17 changed files with 73 additions and 240 deletions

View File

@ -71,6 +71,7 @@ import org.springframework.security.config.annotation.web.configurers.X509Config
import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2ClientConfigurer; import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2ClientConfigurer;
import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer; import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer;
import org.springframework.security.config.annotation.web.configurers.oauth2.client.OidcLogoutConfigurer; import org.springframework.security.config.annotation.web.configurers.oauth2.client.OidcLogoutConfigurer;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer; import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.config.annotation.web.configurers.ott.OneTimeTokenLoginConfigurer; import org.springframework.security.config.annotation.web.configurers.ott.OneTimeTokenLoginConfigurer;
import org.springframework.security.config.annotation.web.configurers.saml2.Saml2LoginConfigurer; import org.springframework.security.config.annotation.web.configurers.saml2.Saml2LoginConfigurer;
@ -1552,6 +1553,23 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
return HttpSecurity.this; return HttpSecurity.this;
} }
/**
* Configures OAuth 2.1 Authorization Server support.
* @param oauth2AuthorizationServerCustomizer the {@link Customizer} providing access
* to the {@link OAuth2AuthorizationServerConfigurer} for further customizations
* @return the {@link HttpSecurity} for further customizations
* @throws Exception
* @since 7.0
* @see <a target="_blank" href=
* "https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-13.html">OAuth 2.1
* Authorization Framework</a>
*/
public HttpSecurity oauth2AuthorizationServer(
Customizer<OAuth2AuthorizationServerConfigurer> oauth2AuthorizationServerCustomizer) throws Exception {
oauth2AuthorizationServerCustomizer.customize(getOrApply(new OAuth2AuthorizationServerConfigurer()));
return HttpSecurity.this;
}
/** /**
* Configures One-Time Token Login Support. * Configures One-Time Token Login Support.
* *

View File

@ -40,7 +40,7 @@ import org.springframework.security.oauth2.server.authorization.settings.Authori
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
/** /**
* {@link Configuration} for OAuth 2.0 Authorization Server support. * {@link Configuration} for OAuth 2.1 Authorization Server support.
* *
* @author Joe Grandja * @author Joe Grandja
* @since 7.0 * @since 7.0
@ -53,11 +53,8 @@ public class OAuth2AuthorizationServerConfiguration {
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer(Customizer.withDefaults())
.with(authorizationServerConfigurer, Customizer.withDefaults())
.authorizeHttpRequests((authorize) -> .authorizeHttpRequests((authorize) ->
authorize.anyRequest().authenticated() authorize.anyRequest().authenticated()
); );

View File

@ -60,7 +60,7 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* An {@link AbstractHttpConfigurer} for OAuth 2.0 Authorization Server support. * An {@link AbstractHttpConfigurer} for OAuth 2.1 Authorization Server support.
* *
* @author Joe Grandja * @author Joe Grandja
* @author Daniel Garnier-Moiroux * @author Daniel Garnier-Moiroux
@ -91,16 +91,6 @@ public final class OAuth2AuthorizationServerConfigurer
private RequestMatcher endpointsMatcher; private RequestMatcher endpointsMatcher;
/**
* Returns a new instance of {@link OAuth2AuthorizationServerConfigurer} for
* configuring.
* @return a new instance of {@link OAuth2AuthorizationServerConfigurer} for
* configuring
*/
public static OAuth2AuthorizationServerConfigurer authorizationServer() {
return new OAuth2AuthorizationServerConfigurer();
}
/** /**
* Sets the repository of registered clients. * Sets the repository of registered clients.
* @param registeredClientRepository the repository of registered clients * @param registeredClientRepository the repository of registered clients
@ -383,6 +373,8 @@ public final class OAuth2AuthorizationServerConfigurer
new OrRequestMatcher(preferredMatchers)); new OrRequestMatcher(preferredMatchers));
} }
httpSecurity.securityMatchers((securityMatchers) -> securityMatchers.requestMatchers(this.endpointsMatcher));
httpSecurity.csrf((csrf) -> csrf.ignoringRequestMatchers(this.endpointsMatcher)); httpSecurity.csrf((csrf) -> csrf.ignoringRequestMatchers(this.endpointsMatcher));
OidcConfigurer oidcConfigurer = getConfigurer(OidcConfigurer.class); OidcConfigurer oidcConfigurer = getConfigurer(OidcConfigurer.class);

View File

@ -1271,11 +1271,8 @@ public class OAuth2AuthorizationCodeGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer(Customizer.withDefaults())
.with(authorizationServerConfigurer, Customizer.withDefaults())
.authorizeHttpRequests((authorize) -> .authorizeHttpRequests((authorize) ->
authorize.anyRequest().authenticated() authorize.anyRequest().authenticated()
) )
@ -1331,11 +1328,8 @@ public class OAuth2AuthorizationCodeGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationEndpoint((authorizationEndpoint) -> .authorizationEndpoint((authorizationEndpoint) ->
authorizationEndpoint.consentPage(consentPage)) authorizationEndpoint.consentPage(consentPage))
@ -1359,11 +1353,8 @@ public class OAuth2AuthorizationCodeGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationEndpoint((authorizationEndpoint) -> .authorizationEndpoint((authorizationEndpoint) ->
authorizationEndpoint.authenticationProviders(configureAuthenticationProviders())) authorizationEndpoint.authenticationProviders(configureAuthenticationProviders()))
@ -1446,11 +1437,8 @@ public class OAuth2AuthorizationCodeGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationEndpoint((authorizationEndpoint) -> .authorizationEndpoint((authorizationEndpoint) ->
authorizationEndpoint authorizationEndpoint
@ -1490,11 +1478,8 @@ public class OAuth2AuthorizationCodeGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.pushedAuthorizationRequestEndpoint(Customizer.withDefaults()) .pushedAuthorizationRequestEndpoint(Customizer.withDefaults())
) )

View File

@ -193,11 +193,8 @@ public class OAuth2AuthorizationServerMetadataTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationServerMetadataEndpoint((authorizationServerMetadataEndpoint) -> .authorizationServerMetadataEndpoint((authorizationServerMetadataEndpoint) ->
authorizationServerMetadataEndpoint authorizationServerMetadataEndpoint

View File

@ -596,11 +596,8 @@ public class OAuth2ClientCredentialsGrantTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenEndpoint((tokenEndpoint) -> .tokenEndpoint((tokenEndpoint) ->
tokenEndpoint tokenEndpoint
@ -640,11 +637,8 @@ public class OAuth2ClientCredentialsGrantTests {
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
authenticationSuccessHandler = spy(authenticationSuccessHandler()); authenticationSuccessHandler = spy(authenticationSuccessHandler());
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.clientAuthentication((clientAuthentication) -> .clientAuthentication((clientAuthentication) ->
clientAuthentication clientAuthentication

View File

@ -542,11 +542,8 @@ public class OAuth2RefreshTokenGrantTests {
SecurityFilterChain authorizationServerSecurityFilterChain( SecurityFilterChain authorizationServerSecurityFilterChain(
HttpSecurity http, RegisteredClientRepository registeredClientRepository) throws Exception { HttpSecurity http, RegisteredClientRepository registeredClientRepository) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.clientAuthentication((clientAuthentication) -> .clientAuthentication((clientAuthentication) ->
clientAuthentication clientAuthentication

View File

@ -575,11 +575,8 @@ public class OAuth2TokenIntrospectionTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenIntrospectionEndpoint((tokenIntrospectionEndpoint) -> .tokenIntrospectionEndpoint((tokenIntrospectionEndpoint) ->
tokenIntrospectionEndpoint tokenIntrospectionEndpoint

View File

@ -375,11 +375,8 @@ public class OAuth2TokenRevocationTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenRevocationEndpoint((tokenRevocationEndpoint) -> .tokenRevocationEndpoint((tokenRevocationEndpoint) ->
tokenRevocationEndpoint tokenRevocationEndpoint

View File

@ -650,11 +650,8 @@ public class OidcClientRegistrationTests {
@Bean @Bean
@Override @Override
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc oidc
@ -686,11 +683,8 @@ public class OidcClientRegistrationTests {
@Bean @Bean
@Override @Override
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc oidc
@ -730,11 +724,8 @@ public class OidcClientRegistrationTests {
@Bean @Bean
@Override @Override
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc oidc
@ -771,11 +762,8 @@ public class OidcClientRegistrationTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc oidc

View File

@ -230,12 +230,9 @@ public class OidcProviderConfigurationTests {
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = OAuth2AuthorizationServerConfigurer
.authorizationServer();
// @formatter:off // @formatter:off
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0 .oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0
); );
@ -285,11 +282,8 @@ public class OidcProviderConfigurationTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc.providerConfigurationEndpoint((providerConfigurationEndpoint) -> oidc.providerConfigurationEndpoint((providerConfigurationEndpoint) ->
@ -317,11 +311,8 @@ public class OidcProviderConfigurationTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc.clientRegistrationEndpoint(Customizer.withDefaults()) oidc.clientRegistrationEndpoint(Customizer.withDefaults())

View File

@ -600,11 +600,8 @@ public class OidcTests {
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0 .oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0
); );
@ -702,11 +699,8 @@ public class OidcTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenGenerator(tokenGenerator()) .tokenGenerator(tokenGenerator())
.oidc(Customizer.withDefaults()) .oidc(Customizer.withDefaults())
@ -743,11 +737,8 @@ public class OidcTests {
// @formatter:off // @formatter:off
@Bean @Bean
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenGenerator(tokenGenerator()) .tokenGenerator(tokenGenerator())
.oidc(Customizer.withDefaults()) .oidc(Customizer.withDefaults())

View File

@ -406,11 +406,8 @@ public class OidcUserInfoTests {
@Override @Override
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc((oidc) -> .oidc((oidc) ->
oidc oidc
@ -442,11 +439,8 @@ public class OidcUserInfoTests {
@Override @Override
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) .oidc(Customizer.withDefaults())
) )
@ -469,11 +463,8 @@ public class OidcUserInfoTests {
@Bean @Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) .oidc(Customizer.withDefaults())
) )

View File

@ -55,11 +55,8 @@ https://openid.net/specs/openid-connect-core-1_0.html[OpenID Connect 1.0] is dis
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) // Initialize `OidcConfigurer` .oidc(Customizer.withDefaults()) // Initialize `OidcConfigurer`
); );
@ -104,12 +101,8 @@ Furthermore, it lets you customize the request processing logic for the protocol
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.registeredClientRepository(registeredClientRepository) <1> .registeredClientRepository(registeredClientRepository) <1>
.authorizationService(authorizationService) <2> .authorizationService(authorizationService) <2>
@ -238,12 +231,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.clientAuthentication(clientAuthentication -> .clientAuthentication(clientAuthentication ->
clientAuthentication clientAuthentication
@ -297,12 +286,8 @@ The following example shows how to configure `JwtClientAssertionAuthenticationPr
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.clientAuthentication(clientAuthentication -> .clientAuthentication(clientAuthentication ->
clientAuthentication clientAuthentication
@ -351,12 +336,8 @@ If you need to verify another attribute of the client `X509Certificate`, for exa
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.clientAuthentication(clientAuthentication -> .clientAuthentication(clientAuthentication ->
clientAuthentication clientAuthentication

View File

@ -122,12 +122,8 @@ Alternatively, you can configure the `RegisteredClientRepository` through the xr
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.registeredClientRepository(registeredClientRepository) .registeredClientRepository(registeredClientRepository)
) )
@ -219,12 +215,8 @@ Alternatively, you can configure the `OAuth2AuthorizationService` through the xr
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationService(authorizationService) .authorizationService(authorizationService)
) )
@ -293,12 +285,8 @@ Alternatively, you can configure the `OAuth2AuthorizationConsentService` through
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationConsentService(authorizationConsentService) .authorizationConsentService(authorizationConsentService)
) )
@ -406,12 +394,8 @@ Alternatively, you can configure the `OAuth2TokenGenerator` through the xref:ser
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenGenerator(tokenGenerator) .tokenGenerator(tokenGenerator)
) )

View File

@ -129,13 +129,10 @@ public class SecurityConfig {
@Order(1) @Order(1)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http)
throws Exception { throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
// @formatter:off // @formatter:off
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0 .oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0
) )

View File

@ -13,12 +13,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationEndpoint(authorizationEndpoint -> .authorizationEndpoint(authorizationEndpoint ->
authorizationEndpoint authorizationEndpoint
@ -76,12 +72,8 @@ The following example shows how to configure `OAuth2AuthorizationCodeRequestAuth
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationEndpoint(authorizationEndpoint -> .authorizationEndpoint(authorizationEndpoint ->
authorizationEndpoint authorizationEndpoint
@ -138,12 +130,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint -> .pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
pushedAuthorizationRequestEndpoint pushedAuthorizationRequestEndpoint
@ -199,12 +187,8 @@ The following example shows how to configure `OAuth2PushedAuthorizationRequestAu
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint -> .pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
pushedAuthorizationRequestEndpoint pushedAuthorizationRequestEndpoint
@ -261,12 +245,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.deviceAuthorizationEndpoint(deviceAuthorizationEndpoint -> .deviceAuthorizationEndpoint(deviceAuthorizationEndpoint ->
deviceAuthorizationEndpoint deviceAuthorizationEndpoint
@ -313,12 +293,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.deviceVerificationEndpoint(deviceVerificationEndpoint -> .deviceVerificationEndpoint(deviceVerificationEndpoint ->
deviceVerificationEndpoint deviceVerificationEndpoint
@ -364,12 +340,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenEndpoint(tokenEndpoint -> .tokenEndpoint(tokenEndpoint ->
tokenEndpoint tokenEndpoint
@ -425,12 +397,8 @@ The following example shows how to configure `OAuth2ClientCredentialsAuthenticat
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenEndpoint(tokenEndpoint -> .tokenEndpoint(tokenEndpoint ->
tokenEndpoint tokenEndpoint
@ -616,12 +584,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenIntrospectionEndpoint(tokenIntrospectionEndpoint -> .tokenIntrospectionEndpoint(tokenIntrospectionEndpoint ->
tokenIntrospectionEndpoint tokenIntrospectionEndpoint
@ -666,12 +630,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.tokenRevocationEndpoint(tokenRevocationEndpoint -> .tokenRevocationEndpoint(tokenRevocationEndpoint ->
tokenRevocationEndpoint tokenRevocationEndpoint
@ -716,12 +676,8 @@ It defines an extension point that lets you customize the https://datatracker.ie
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint -> .authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint ->
authorizationServerMetadataEndpoint authorizationServerMetadataEndpoint
@ -760,12 +716,8 @@ It defines an extension point that lets you customize the https://openid.net/spe
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(oidc -> .oidc(oidc ->
oidc oidc
@ -796,12 +748,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(oidc -> .oidc(oidc ->
oidc oidc
@ -864,12 +812,8 @@ The following example shows how to configure `OidcLogoutAuthenticationProvider`
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(oidc -> .oidc(oidc ->
oidc oidc
@ -919,12 +863,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(oidc -> .oidc(oidc ->
oidc oidc
@ -982,12 +922,8 @@ It defines extension points that let you customize the pre-processing, main proc
---- ----
@Bean @Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) .oauth2AuthorizationServer((authorizationServer) ->
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer authorizationServer
.oidc(oidc -> .oidc(oidc ->
oidc oidc