|
|
|
@ -58,7 +58,10 @@ import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
|
|
|
|
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.store.jwk.JwkTokenStore;
|
|
|
|
|
import org.springframework.social.connect.ConnectionFactoryLocator;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
@ -261,6 +264,27 @@ public class ResourceServerTokenServicesConfigurationTests {
|
|
|
|
|
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void jwkTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class,
|
|
|
|
|
ResourceConfiguration.class)
|
|
|
|
|
.environment(this.environment).web(false).run();
|
|
|
|
|
assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY)
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class)
|
|
|
|
|
.environment(this.environment).web(false).run();
|
|
|
|
|
assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@Import({ ResourceServerTokenServicesConfiguration.class,
|
|
|
|
|
ResourceServerPropertiesConfiguration.class,
|
|
|
|
@ -385,6 +409,26 @@ public class ResourceServerTokenServicesConfigurationTests {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class JwtTokenStoreConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public TokenStore tokenStore(JwtAccessTokenConverter jwtTokenEnhancer) {
|
|
|
|
|
return new JwtTokenStore(jwtTokenEnhancer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class JwkTokenStoreConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public TokenStore tokenStore() {
|
|
|
|
|
return new JwkTokenStore("http://my.key-set.uri");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class MockRestCallCustomizer
|
|
|
|
|
implements JwtAccessTokenConverterRestTemplateCustomizer {
|
|
|
|
|
|
|
|
|
|