@ -1339,10 +1339,18 @@ public class OAuth2ResourceServerConfigurerTests {
@@ -1339,10 +1339,18 @@ public class OAuth2ResourceServerConfigurerTests {
}
@Test
public void configureWhenUsingBothAuthenticationManagerResolverAndOpaqueThenWiringException ( ) {
assertThatExceptionOfType ( BeanCreationException . class )
. isThrownBy ( ( ) - > this . spring . register ( AuthenticationManagerResolverPlusOtherConfig . class ) . autowire ( ) )
. withMessageContaining ( "authenticationManagerResolver" ) ;
public void configureWhenUsingBothAuthenticationManagerResolverAndOpaqueThenAuthenticationManagerResolverTakesPrecedence ( ) {
// authenticationManagerResolver should take precedence over opaqueToken
// configuration
this . spring . register ( AuthenticationManagerResolverPlusOtherConfig . class ) . autowire ( ) ;
// No exception should be thrown
}
@Test
public void configureWhenUsingBothAuthenticationManagerResolverAndJwtThenAuthenticationManagerResolverTakesPrecedence ( ) {
// authenticationManagerResolver should take precedence over jwt configuration
this . spring . register ( AuthenticationManagerResolverPlusJwtConfig . class ) . autowire ( ) ;
// No exception should be thrown
}
@Test
@ -2605,6 +2613,11 @@ public class OAuth2ResourceServerConfigurerTests {
@@ -2605,6 +2613,11 @@ public class OAuth2ResourceServerConfigurerTests {
@EnableWebSecurity
static class AuthenticationManagerResolverPlusOtherConfig {
@Bean
OpaqueTokenIntrospector opaqueTokenIntrospector ( ) {
return mock ( OpaqueTokenIntrospector . class ) ;
}
@Bean
SecurityFilterChain filterChain ( HttpSecurity http ) throws Exception {
// @formatter:off
@ -2612,8 +2625,8 @@ public class OAuth2ResourceServerConfigurerTests {
@@ -2612,8 +2625,8 @@ public class OAuth2ResourceServerConfigurerTests {
. authorizeHttpRequests ( ( requests ) - > requests
. anyRequest ( ) . authenticated ( ) )
. oauth2ResourceServer ( ( server ) - > server
. authenticationManagerResolver ( mock ( AuthenticationManagerResolver . class ) )
. opaqueToken ( Customizer . withDefaults ( ) ) ) ;
. opaqueToken ( Customizer . withDefaults ( ) )
. authenticationManagerResolver ( mock ( AuthenticationManagerResolver . class ) ) ) ;
return http . build ( ) ;
// @formatter:on
}
@ -2793,4 +2806,28 @@ public class OAuth2ResourceServerConfigurerTests {
@@ -2793,4 +2806,28 @@ public class OAuth2ResourceServerConfigurerTests {
}
@Configuration
@EnableWebSecurity
static class AuthenticationManagerResolverPlusJwtConfig {
@Bean
JwtDecoder jwtDecoder ( ) {
return mock ( JwtDecoder . class ) ;
}
@Bean
SecurityFilterChain filterChain ( HttpSecurity http ) throws Exception {
// @formatter:off
http
. authorizeHttpRequests ( ( requests ) - > requests
. anyRequest ( ) . authenticated ( ) )
. oauth2ResourceServer ( ( server ) - > server
. jwt ( Customizer . withDefaults ( ) )
. authenticationManagerResolver ( mock ( AuthenticationManagerResolver . class ) ) ) ;
return http . build ( ) ;
// @formatter:on
}
}
}