Merge branch '1.5.x'

pull/9748/merge
Madhura Bhave 7 years ago
commit 39ec335d41

@ -222,13 +222,14 @@ public class ResourceServerTokenServicesConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(ResourceServerTokenServices.class) @ConditionalOnMissingBean(ResourceServerTokenServices.class)
public DefaultTokenServices jwkTokenServices() { public DefaultTokenServices jwkTokenServices(TokenStore jwkTokenStore) {
DefaultTokenServices services = new DefaultTokenServices(); DefaultTokenServices services = new DefaultTokenServices();
services.setTokenStore(jwkTokenStore()); services.setTokenStore(jwkTokenStore);
return services; return services;
} }
@Bean @Bean
@ConditionalOnMissingBean(TokenStore.class)
public TokenStore jwkTokenStore() { public TokenStore jwkTokenStore() {
return new JwkTokenStore(this.resource.getJwk().getKeySetUri()); return new JwkTokenStore(this.resource.getJwk().getKeySetUri());
} }
@ -254,13 +255,14 @@ public class ResourceServerTokenServicesConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(ResourceServerTokenServices.class) @ConditionalOnMissingBean(ResourceServerTokenServices.class)
public DefaultTokenServices jwtTokenServices() { public DefaultTokenServices jwtTokenServices(TokenStore jwtTokenStore) {
DefaultTokenServices services = new DefaultTokenServices(); DefaultTokenServices services = new DefaultTokenServices();
services.setTokenStore(jwtTokenStore()); services.setTokenStore(jwtTokenStore);
return services; return services;
} }
@Bean @Bean
@ConditionalOnMissingBean(TokenStore.class)
public TokenStore jwtTokenStore() { public TokenStore jwtTokenStore() {
return new JwtTokenStore(jwtTokenEnhancer()); return new JwtTokenStore(jwtTokenEnhancer());
} }

@ -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.client.token.grant.code.AuthorizationCodeResourceDetails;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices; import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices; 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.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.social.connect.ConnectionFactoryLocator;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -261,6 +264,27 @@ public class ResourceServerTokenServicesConfigurationTests {
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1); 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 @Configuration
@Import({ ResourceServerTokenServicesConfiguration.class, @Import({ ResourceServerTokenServicesConfiguration.class,
ResourceServerPropertiesConfiguration.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 private static class MockRestCallCustomizer
implements JwtAccessTokenConverterRestTemplateCustomizer { implements JwtAccessTokenConverterRestTemplateCustomizer {

Loading…
Cancel
Save