|
|
|
|
@ -50,7 +50,9 @@ import org.springframework.security.core.userdetails.MapReactiveUserDetailsServi
@@ -50,7 +50,9 @@ import org.springframework.security.core.userdetails.MapReactiveUserDetailsServi
|
|
|
|
|
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator; |
|
|
|
|
import org.springframework.security.oauth2.core.OAuth2TokenValidator; |
|
|
|
|
import org.springframework.security.oauth2.jwt.Jwt; |
|
|
|
|
import org.springframework.security.oauth2.jwt.JwtClaimValidator; |
|
|
|
|
import org.springframework.security.oauth2.jwt.JwtIssuerValidator; |
|
|
|
|
import org.springframework.security.oauth2.jwt.JwtTimestampValidator; |
|
|
|
|
import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder; |
|
|
|
|
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder; |
|
|
|
|
import org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder; |
|
|
|
|
@ -74,6 +76,7 @@ import static org.mockito.Mockito.mock;
@@ -74,6 +76,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
* @author Artsiom Yudovin |
|
|
|
|
* @author HaiTao Zhang |
|
|
|
|
* @author Anastasiia Losieva |
|
|
|
|
* @author Mushtaq Ahmed |
|
|
|
|
*/ |
|
|
|
|
class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
@ -387,6 +390,56 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests {
@@ -387,6 +390,56 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
@Test |
|
|
|
|
void autoConfigurationShouldNotConfigureIssuerUriAndAudienceJwtValidatorIfPropertyNotConfigured() throws Exception { |
|
|
|
|
this.server = new MockWebServer(); |
|
|
|
|
this.server.start(); |
|
|
|
|
String path = "test"; |
|
|
|
|
String issuer = this.server.url(path).toString(); |
|
|
|
|
String cleanIssuerPath = cleanIssuerPath(issuer); |
|
|
|
|
setupMockResponse(cleanIssuerPath); |
|
|
|
|
this.contextRunner |
|
|
|
|
.withPropertyValues("spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com") |
|
|
|
|
.run((context) -> { |
|
|
|
|
assertThat(context).hasSingleBean(ReactiveJwtDecoder.class); |
|
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = context.getBean(ReactiveJwtDecoder.class); |
|
|
|
|
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator<Jwt>) ReflectionTestUtils |
|
|
|
|
.getField(reactiveJwtDecoder, "jwtValidator"); |
|
|
|
|
Collection<OAuth2TokenValidator<Jwt>> tokenValidators = (Collection<OAuth2TokenValidator<Jwt>>) ReflectionTestUtils |
|
|
|
|
.getField(jwtValidator, "tokenValidators"); |
|
|
|
|
assertThat(tokenValidators).hasExactlyElementsOfTypes(JwtTimestampValidator.class); |
|
|
|
|
assertThat(tokenValidators).doesNotHaveAnyElementsOfTypes(JwtClaimValidator.class); |
|
|
|
|
assertThat(tokenValidators).doesNotHaveAnyElementsOfTypes(JwtIssuerValidator.class); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
@Test |
|
|
|
|
void autoConfigurationShouldConfigureIssuerAndAudienceJwtValidatorIfPropertyProvided() throws Exception { |
|
|
|
|
this.server = new MockWebServer(); |
|
|
|
|
this.server.start(); |
|
|
|
|
String path = "test"; |
|
|
|
|
String issuer = this.server.url(path).toString(); |
|
|
|
|
String cleanIssuerPath = cleanIssuerPath(issuer); |
|
|
|
|
setupMockResponse(cleanIssuerPath); |
|
|
|
|
this.contextRunner |
|
|
|
|
.withPropertyValues("spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com", |
|
|
|
|
"spring.security.oauth2.resourceserver.jwt.issuer-uri=http://" + this.server.getHostName() + ":" |
|
|
|
|
+ this.server.getPort() + "/" + path, |
|
|
|
|
"spring.security.oauth2.resourceserver.jwt.audience=http://test-audience.com") |
|
|
|
|
.run((context) -> { |
|
|
|
|
assertThat(context).hasSingleBean(ReactiveJwtDecoder.class); |
|
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = context.getBean(ReactiveJwtDecoder.class); |
|
|
|
|
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator<Jwt>) ReflectionTestUtils |
|
|
|
|
.getField(reactiveJwtDecoder, "jwtValidator"); |
|
|
|
|
Collection<OAuth2TokenValidator<Jwt>> tokenValidators = (Collection<OAuth2TokenValidator<Jwt>>) ReflectionTestUtils |
|
|
|
|
.getField(jwtValidator, "tokenValidators"); |
|
|
|
|
assertThat(tokenValidators).hasAtLeastOneElementOfType(JwtIssuerValidator.class); |
|
|
|
|
assertThat(tokenValidators).hasAtLeastOneElementOfType(JwtClaimValidator.class); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertFilterConfiguredWithJwtAuthenticationManager(AssertableReactiveWebApplicationContext context) { |
|
|
|
|
MatcherSecurityWebFilterChain filterChain = (MatcherSecurityWebFilterChain) context |
|
|
|
|
.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); |
|
|
|
|
|