|
|
|
@ -15,6 +15,7 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.springframework.boot.autoconfigure.security.oauth2.resource.servlet;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -41,7 +42,11 @@ import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.security.config.BeanIds;
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
|
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.JwtDecoder;
|
|
|
|
|
import org.springframework.security.oauth2.jwt.JwtIssuerValidator;
|
|
|
|
|
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
|
|
|
|
import org.springframework.security.oauth2.server.resource.authentication.OAuth2IntrospectionAuthenticationToken;
|
|
|
|
|
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;
|
|
|
|
@ -320,6 +325,30 @@ class OAuth2ResourceServerAutoConfigurationTests {
|
|
|
|
|
"Only one of jwt.public-key-location and opaquetoken.introspection-uri should be configured."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Test
|
|
|
|
|
void autoConfigurationShouldConfigureResourceServerUsingJwkSetUriAndIssuerUri() 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)
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
assertThat(context).hasSingleBean(JwtDecoder.class);
|
|
|
|
|
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
|
|
|
|
|
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator) ReflectionTestUtils
|
|
|
|
|
.getField(jwtDecoder, "jwtValidator");
|
|
|
|
|
Collection<OAuth2TokenValidator<Jwt>> tokenValidators = (Collection<OAuth2TokenValidator<Jwt>>) ReflectionTestUtils
|
|
|
|
|
.getField(jwtValidator, "tokenValidators");
|
|
|
|
|
assertThat(tokenValidators.stream()).hasAtLeastOneElementOfType(JwtIssuerValidator.class);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Filter getBearerTokenFilter(AssertableWebApplicationContext context) {
|
|
|
|
|
FilterChainProxy filterChain = (FilterChainProxy) context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN);
|
|
|
|
|
List<SecurityFilterChain> filterChains = filterChain.getFilterChains();
|
|
|
|
|