我稍微更新了一个 Spring Cloud Services 示例来说明我遇到的问题: https ://github.com/spring-cloud-services-samples/greeting/compare/master...timtebeek:master
经过上述更改后,我正在使用:
spring-cloud-services-starter-config-client:1.5.0.RELEASE
spring-cloud-services-starter-service-registry:1.5.0.RELEASE
spring-cloud-starter-oauth2:2.0.14.RELEASE
我还添加了一个最小的ResourceServerConfigurerAdapter
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated();
}
@Override
public void configure(final ResourceServerSecurityConfigurer resources) {
resources.resourceId("greeter");
}
}
以及最低限度的配置设置:
security:
oauth2:
resource:
jwt:
key-uri: https://example.com/oauth/token_key
通过这些更改,我的应用程序无法在 PCF-DEV 中部署;我没有尝试过正确的 PCF,但希望结果是相似的。这是我收到的错误消息:
Method userInfoRestTemplateFactory in org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration required a single bean, but 2 were found: - eurekaOAuth2ResourceDetails: defined by method 'eurekaOAuth2ResourceDetails' in class path resource [io/pivotal/spring/cloud/service/eureka/EurekaOAuth2AutoConfiguration.class] - configClientOAuth2ResourceDetails: defined by method 'configClientOAuth2ResourceDetails' in io.pivotal.spring.cloud.service.config.ConfigClientOAuth2BootstrapConfiguration Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
所以它试图使用OAuth2ProtectedResourceDetails
与 spring-cloud-services-starters 完全分开的东西来设置我的应用程序安全性;我希望它只使用外部 JWT 密钥。
谁能帮助我如何让我的 PCF 部署的应用程序同时使用配置和发现服务也使用外部 JWT 令牌进行身份验证设置?