|
@@ -82,10 +82,10 @@ import org.springframework.security.authentication.AuthenticationManagerResolver
|
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
|
+import org.springframework.security.config.Customizer;
|
|
|
import org.springframework.security.config.ObjectPostProcessor;
|
|
|
import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig;
|
|
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
-import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
|
@@ -163,7 +163,6 @@ import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
import static org.mockito.Mockito.atLeastOnce;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
-import static org.mockito.Mockito.never;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.springframework.security.config.Customizer.withDefaults;
|
|
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
|
@@ -815,15 +814,16 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
@Test
|
|
|
public void getJwtDecoderWhenConfiguredWithDecoderAndJwkSetUriThenLastOneWins() {
|
|
|
ApplicationContext context = mock(ApplicationContext.class);
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
JwtDecoder decoder = mock(JwtDecoder.class);
|
|
|
- jwtConfigurer.jwkSetUri(JWK_SET_URI);
|
|
|
- jwtConfigurer.decoder(decoder);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isEqualTo(decoder);
|
|
|
- jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.decoder(decoder);
|
|
|
- jwtConfigurer.jwkSetUri(JWK_SET_URI);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isInstanceOf(NimbusJwtDecoder.class);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.jwkSetUri(JWK_SET_URI);
|
|
|
+ jwt.decoder(decoder);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isEqualTo(decoder);
|
|
|
+ });
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.decoder(decoder).jwkSetUri(JWK_SET_URI);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isInstanceOf(NimbusJwtDecoder.class);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -832,9 +832,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
JwtDecoder decoder = mock(JwtDecoder.class);
|
|
|
ApplicationContext context = mock(ApplicationContext.class);
|
|
|
given(context.getBean(JwtDecoder.class)).willReturn(decoderBean);
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.decoder(decoder);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isEqualTo(decoder);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.decoder(decoder);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isEqualTo(decoder);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -842,10 +843,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
JwtDecoder decoder = mock(JwtDecoder.class);
|
|
|
ApplicationContext context = mock(ApplicationContext.class);
|
|
|
given(context.getBean(JwtDecoder.class)).willReturn(decoder);
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.jwkSetUri(JWK_SET_URI);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isNotEqualTo(decoder);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isInstanceOf(NimbusJwtDecoder.class);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.jwkSetUri(JWK_SET_URI);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isNotEqualTo(decoder);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isInstanceOf(NimbusJwtDecoder.class);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -856,9 +858,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
context.registerBean("decoderOne", JwtDecoder.class, () -> decoderBean);
|
|
|
context.registerBean("decoderTwo", JwtDecoder.class, () -> decoderBean);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.decoder(decoder);
|
|
|
- assertThat(jwtConfigurer.getJwtDecoder()).isEqualTo(decoder);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.decoder(decoder);
|
|
|
+ assertThat(jwt.getJwtDecoder()).isEqualTo(decoder);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -868,8 +871,9 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
context.registerBean("decoderOne", JwtDecoder.class, () -> decoder);
|
|
|
context.registerBean("decoderTwo", JwtDecoder.class, () -> decoder);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(jwtConfigurer::getJwtDecoder);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context)
|
|
|
+ .jwt((jwt) -> assertThatExceptionOfType(NoUniqueBeanDefinitionException.class)
|
|
|
+ .isThrownBy(jwt::getJwtDecoder));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1152,19 +1156,19 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
@Test
|
|
|
public void getIntrospectionClientWhenConfiguredWithClientAndIntrospectionUriThenLastOneWins() {
|
|
|
ApplicationContext context = mock(ApplicationContext.class);
|
|
|
- OAuth2ResourceServerConfigurer.OpaqueTokenConfigurer opaqueTokenConfigurer = new OAuth2ResourceServerConfigurer(
|
|
|
- context)
|
|
|
- .opaqueToken();
|
|
|
OpaqueTokenIntrospector client = mock(OpaqueTokenIntrospector.class);
|
|
|
- opaqueTokenConfigurer.introspectionUri(INTROSPECTION_URI);
|
|
|
- opaqueTokenConfigurer.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
- opaqueTokenConfigurer.introspector(client);
|
|
|
- assertThat(opaqueTokenConfigurer.getIntrospector()).isEqualTo(client);
|
|
|
- opaqueTokenConfigurer = new OAuth2ResourceServerConfigurer(context).opaqueToken();
|
|
|
- opaqueTokenConfigurer.introspector(client);
|
|
|
- opaqueTokenConfigurer.introspectionUri(INTROSPECTION_URI);
|
|
|
- opaqueTokenConfigurer.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
- assertThat(opaqueTokenConfigurer.getIntrospector()).isNotSameAs(client);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).opaqueToken((opaqueToken) -> {
|
|
|
+ opaqueToken.introspectionUri(INTROSPECTION_URI);
|
|
|
+ opaqueToken.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
+ opaqueToken.introspector(client);
|
|
|
+ assertThat(opaqueToken.getIntrospector()).isEqualTo(client);
|
|
|
+ });
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).opaqueToken((opaqueToken) -> {
|
|
|
+ opaqueToken.introspector(client);
|
|
|
+ opaqueToken.introspectionUri(INTROSPECTION_URI);
|
|
|
+ opaqueToken.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
+ assertThat(opaqueToken.getIntrospector()).isNotSameAs(client);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1172,11 +1176,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
registerMockBean(context, "introspectionClientOne", OpaqueTokenIntrospector.class);
|
|
|
registerMockBean(context, "introspectionClientTwo", OpaqueTokenIntrospector.class);
|
|
|
- OAuth2ResourceServerConfigurer.OpaqueTokenConfigurer opaqueToken = new OAuth2ResourceServerConfigurer(context)
|
|
|
- .opaqueToken();
|
|
|
- opaqueToken.introspectionUri(INTROSPECTION_URI);
|
|
|
- opaqueToken.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
- assertThat(opaqueToken.getIntrospector()).isNotNull();
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).opaqueToken((opaqueToken) -> {
|
|
|
+ opaqueToken.introspectionUri(INTROSPECTION_URI);
|
|
|
+ opaqueToken.introspectionClientCredentials(CLIENT_ID, CLIENT_SECRET);
|
|
|
+ assertThat(opaqueToken.getIntrospector()).isNotNull();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1263,17 +1267,16 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
@Test
|
|
|
public void getAuthenticationManagerWhenConfiguredAuthenticationManagerThenTakesPrecedence() {
|
|
|
ApplicationContext context = mock(ApplicationContext.class);
|
|
|
- HttpSecurityBuilder http = mock(HttpSecurityBuilder.class);
|
|
|
- OAuth2ResourceServerConfigurer oauth2ResourceServer = new OAuth2ResourceServerConfigurer(context);
|
|
|
+ OAuth2ResourceServerConfigurer<HttpSecurity> oauth2ResourceServer = new OAuth2ResourceServerConfigurer<>(
|
|
|
+ context);
|
|
|
AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
|
|
|
- oauth2ResourceServer.jwt().authenticationManager(authenticationManager).decoder(mock(JwtDecoder.class));
|
|
|
- assertThat(oauth2ResourceServer.getAuthenticationManager(http)).isSameAs(authenticationManager);
|
|
|
- oauth2ResourceServer = new OAuth2ResourceServerConfigurer(context);
|
|
|
- oauth2ResourceServer.opaqueToken()
|
|
|
- .authenticationManager(authenticationManager)
|
|
|
- .introspector(mock(OpaqueTokenIntrospector.class));
|
|
|
- assertThat(oauth2ResourceServer.getAuthenticationManager(http)).isSameAs(authenticationManager);
|
|
|
- verify(http, never()).authenticationProvider(any(AuthenticationProvider.class));
|
|
|
+ oauth2ResourceServer
|
|
|
+ .jwt((jwt) -> jwt.authenticationManager(authenticationManager).decoder(mock(JwtDecoder.class)));
|
|
|
+ assertThat(oauth2ResourceServer.getAuthenticationManager(null)).isSameAs(authenticationManager);
|
|
|
+ oauth2ResourceServer = new OAuth2ResourceServerConfigurer<>(context);
|
|
|
+ oauth2ResourceServer.opaqueToken((opaqueToken) -> opaqueToken.authenticationManager(authenticationManager)
|
|
|
+ .introspector(mock(OpaqueTokenIntrospector.class)));
|
|
|
+ assertThat(oauth2ResourceServer.getAuthenticationManager(null)).isSameAs(authenticationManager);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1343,8 +1346,9 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
@Test
|
|
|
public void getJwtAuthenticationConverterWhenNoConverterSpecifiedThenTheDefaultIsUsed() {
|
|
|
ApplicationContext context = this.spring.context(new GenericWebApplicationContext()).getContext();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isInstanceOf(JwtAuthenticationConverter.class);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context)
|
|
|
+ .jwt((jwt) -> assertThat(jwt.getJwtAuthenticationConverter())
|
|
|
+ .isInstanceOf(JwtAuthenticationConverter.class));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1353,8 +1357,8 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
GenericWebApplicationContext context = new GenericWebApplicationContext();
|
|
|
context.registerBean(JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isEqualTo(converterBean);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context)
|
|
|
+ .jwt((jwt) -> assertThat(jwt.getJwtAuthenticationConverter()).isEqualTo(converterBean));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1364,9 +1368,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
GenericWebApplicationContext context = new GenericWebApplicationContext();
|
|
|
context.registerBean(JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.jwtAuthenticationConverter(converter);
|
|
|
- assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isEqualTo(converter);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.jwtAuthenticationConverter(converter);
|
|
|
+ assertThat(jwt.getJwtAuthenticationConverter()).isEqualTo(converter);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1377,9 +1382,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
context.registerBean("converterOne", JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
context.registerBean("converterTwo", JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- jwtConfigurer.jwtAuthenticationConverter(converter);
|
|
|
- assertThat(jwtConfigurer.getJwtAuthenticationConverter()).isEqualTo(converter);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ jwt.jwtAuthenticationConverter(converter);
|
|
|
+ assertThat(jwt.getJwtAuthenticationConverter()).isEqualTo(converter);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1389,9 +1395,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
context.registerBean("converterOne", JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
context.registerBean("converterTwo", JwtAuthenticationConverter.class, () -> converterBean);
|
|
|
this.spring.context(context).autowire();
|
|
|
- OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
|
|
|
- assertThatExceptionOfType(NoUniqueBeanDefinitionException.class)
|
|
|
- .isThrownBy(jwtConfigurer::getJwtAuthenticationConverter);
|
|
|
+ new OAuth2ResourceServerConfigurer<HttpSecurity>(context).jwt((jwt) -> {
|
|
|
+ assertThatExceptionOfType(NoUniqueBeanDefinitionException.class)
|
|
|
+ .isThrownBy(jwt::getJwtAuthenticationConverter);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1550,12 +1557,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
.requestMatchers("/requires-read-scope").access("hasAuthority('SCOPE_message:read')")
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1600,14 +1606,12 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
DefaultBearerTokenResolver defaultBearerTokenResolver = new DefaultBearerTokenResolver();
|
|
|
defaultBearerTokenResolver.setAllowUriQueryParameter(true);
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
.requestMatchers("/requires-read-scope").access("hasAuthority('SCOPE_message:read')")
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
.bearerTokenResolver(defaultBearerTokenResolver)
|
|
|
- .jwt()
|
|
|
- .jwkSetUri(this.jwkSetUri);
|
|
|
+ .jwt((jwt) -> jwt.jwkSetUri(this.jwkSetUri)));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1656,14 +1660,12 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
.requestMatchers("/requires-read-scope").access("hasAuthority('SCOPE_message:read')")
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .csrf().disable()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .jwkSetUri(this.jwkSetUri);
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .csrf((csrf) -> csrf.disable())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt((jwt) -> jwt.jwkSetUri(this.jwkSetUri)));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1678,12 +1680,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .anonymous().disable()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .anonymous((anonymous) -> anonymous.disable())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1699,11 +1700,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1718,10 +1718,9 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer(withDefaults());
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1736,12 +1735,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
.authenticationEntryPoint(authenticationEntryPoint())
|
|
|
- .jwt();
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1762,12 +1760,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().denyAll()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().denyAll())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
.accessDeniedHandler(accessDeniedHandler())
|
|
|
- .jwt();
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1788,16 +1785,13 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().denyAll()
|
|
|
- .and()
|
|
|
- .exceptionHandling()
|
|
|
- .defaultAccessDeniedHandlerFor(new AccessDeniedHandlerImpl(), (request) -> false)
|
|
|
- .and()
|
|
|
- .httpBasic()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().denyAll())
|
|
|
+ .exceptionHandling((handling) -> handling
|
|
|
+ .defaultAccessDeniedHandlerFor(new AccessDeniedHandlerImpl(), (request) -> false))
|
|
|
+ .httpBasic(withDefaults())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1826,12 +1820,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .jwtAuthenticationConverter(getJwtAuthenticationConverter());
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt((jwt) -> jwt
|
|
|
+ .jwtAuthenticationConverter(getJwtAuthenticationConverter())));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1851,12 +1844,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .requestMatchers("/requires-read-scope").access("hasAuthority('message:read')")
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .jwtAuthenticationConverter(getJwtAuthenticationConverter());
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .requestMatchers("/requires-read-scope").access("hasAuthority('message:read')"))
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt((jwt) -> jwt
|
|
|
+ .jwtAuthenticationConverter(getJwtAuthenticationConverter())));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1878,13 +1870,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .httpBasic()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .httpBasic(withDefaults())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1911,13 +1901,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .formLogin()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .formLogin(withDefaults())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1957,11 +1945,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build(); // missing key configuration, e.g. jwkSetUri
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1976,11 +1963,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .sessionManagement()
|
|
|
- .sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .sessionManagement((management) -> management
|
|
|
+ .sessionCreationPolicy(SessionCreationPolicy.ALWAYS))
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -1995,12 +1981,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
.bearerTokenResolver(allowRequestBody())
|
|
|
- .jwt();
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2021,11 +2006,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2047,11 +2031,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2115,12 +2098,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .decoder(decoder());
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt((jwt) -> jwt.decoder(decoder())));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2170,11 +2151,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2194,12 +2174,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .authenticationManager(authenticationProvider()::authenticate);
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt((jwt) -> jwt
|
|
|
+ .authenticationManager(authenticationProvider()::authenticate)));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2260,8 +2239,8 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
this.jwtDecoder.setJwtValidator(this.jwtValidator);
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2288,8 +2267,8 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
this.jwtDecoder.setJwtValidator(jwtValidator);
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2312,8 +2291,8 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
this.jwtDecoder.setJwtValidator(jwtValidator);
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
}
|
|
|
}
|
|
@@ -2333,11 +2312,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2359,11 +2337,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2389,12 +2366,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
.requestMatchers("/requires-read-scope").hasAuthority("SCOPE_message:read")
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .opaqueToken();
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .opaqueToken(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2433,12 +2409,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .opaqueToken()
|
|
|
- .authenticationManager(authenticationProvider()::authenticate);
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .opaqueToken((opaqueToken) -> opaqueToken
|
|
|
+ .authenticationManager(authenticationProvider()::authenticate)));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2523,10 +2498,9 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt()
|
|
|
- .and()
|
|
|
- .opaqueToken();
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults())
|
|
|
+ .opaqueToken(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2541,12 +2515,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .opaqueToken()
|
|
|
- .introspectionUri("https://idp.example.com");
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .opaqueToken((opaqueToken) -> opaqueToken
|
|
|
+ .introspectionUri("https://idp.example.com")));
|
|
|
return http.build(); // missing credentials
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2561,11 +2534,10 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .jwt();
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .jwt(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2605,9 +2577,8 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
issuerOne, issuerTwo);
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .oauth2ResourceServer()
|
|
|
- .authenticationManagerResolver(authenticationManagerResolver)
|
|
|
- .and()
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .authenticationManagerResolver(authenticationManagerResolver))
|
|
|
.anonymous(AbstractHttpConfigurer::disable);
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
@@ -2623,12 +2594,11 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
.authenticationManagerResolver(mock(AuthenticationManagerResolver.class))
|
|
|
- .opaqueToken();
|
|
|
+ .opaqueToken(Customizer.withDefaults()));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|
|
@@ -2644,13 +2614,12 @@ public class OAuth2ResourceServerConfigurerTests {
|
|
|
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeRequests()
|
|
|
+ .authorizeRequests((requests) -> requests
|
|
|
.requestMatchers("/requires-read-scope").hasAuthority("SCOPE_message:read")
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .oauth2ResourceServer()
|
|
|
- .opaqueToken()
|
|
|
- .authenticationConverter(authenticationConverter());
|
|
|
+ .anyRequest().authenticated())
|
|
|
+ .oauth2ResourceServer((server) -> server
|
|
|
+ .opaqueToken((opaqueToken) -> opaqueToken
|
|
|
+ .authenticationConverter(authenticationConverter())));
|
|
|
return http.build();
|
|
|
// @formatter:on
|
|
|
}
|