1

我稍微更新的春天雲服務爲例,說明我有一個問題: https://github.com/spring-cloud-services-samples/greeting/compare/master...timtebeek:masterUserInfoRestTemplateFactory安裝失敗ResourceServerConfigurerAdapter和兩個彈簧雲服務起動器

上述改變我後使用:

  • 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從春季雲服務起動器設置我的應用程序的安全性;我希望它只使用外部JWT密鑰。

任何人都可以幫助我如何使用配置和發現服務同時使用外部JWT令牌進行身份驗證設置嗎?

回答

1

我跑進一樣的東西。幾個月前我看到了這個線程。我也升級到1.5.4的春季啓動和雲Dalston.SR4,並讓我過了駝峯。謝謝。

I was shownhttp://start.spring.io正在使用彈簧靴1.5.9。它運行在PivotalWS上,所以我知道有一個解決方案。

試試這個變化:

security: 
    oauth2: 
    client: 
     client-id: someclient 
     client-secret: someclientpass 
    resource: 
     jwt: 
     key-uri: https://example.com/oauth/token_key 

客戶端識別和客戶端祕密在我的情況下,虛值。我假設您也使用JWT令牌,您的資源不需要使用JWT令牌提供程序驗證令牌,只需要簽名(key-uri)。所以通過添加client-id和client-secret,我猜測(完全猜測)它創建了具有更好(更近)範圍的必需OAuth2ProtectedResourceDetails。

當我們不需要查找用戶信息時,它正在查找「userInfoRestTemplateFactory」的事實正是我在這個方向上指出的。

我的服務使用spring boot 1.5.9和Dalton.SR4與io.pivotal.spring一起在PivotalWS(run.pivotal.io)上成功部署。雲:spring-cloud-services-dependencies:1.5.0.RELEASE

1

改變彈簧引導啓動父是1.5.2.RELEASE,彈簧雲的依賴是Dalston.RC1,彈簧雲服務依賴性1.5.0.RELEASE

+0

其實,只有將父母改回1.5.4纔夠好; Dalston.SR4正常工作。非常感謝! – Tim

+0

或者,如果您傾向於:'op.spring.platform:platform-b​​om:Brussels-SR3'作爲父項。 – Tim

+0

關鍵團隊正在研究新版本的'spring-boot-starter-parent'。一旦這些可用,我會回答這個問題與相應的細節。 – Tim