1
我想用單個Auth服務器來訪問多個客戶端的多個資源服務器。Spring Security中的多資源服務器配置OAuth
我試圖從相同的auth服務器訪問兩個資源服務器,並且我的資源服務器配置如下所示。
@Bean
@Scope("prototype")
protected ResourceServerConfiguration resource1() {
ResourceServerConfiguration resource = new ResourceServerConfiguration();
resource.setConfigurers(Arrays.<ResourceServerConfigurer> asList(new ResourceServerConfigurerAdapter() {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId(RESOURCE_ID1).tokenStore(tokenStore);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.requestMatchers().antMatchers("/greeting")
.and()
.authorizeRequests()
.antMatchers("/users").hasRole("ADMIN");
}
}
resource.setOrder(4);
return resource;
}
@Bean
@Scope("prototype")
protected ResourceServerConfiguration resource2() {
ResourceServerConfiguration resource = new ResourceServerConfiguration();
resource.setConfigurers(Arrays.<ResourceServerConfigurer> asList(new ResourceServerConfigurerAdapter() {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId(RESOURCE_ID2).tokenStore(tokenStore);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.requestMatchers().antMatchers("/welcome")
.and()
.authorizeRequests()
.antMatchers("/users").hasRole("ADMIN");
}
}
resource.setOrder(5);
return resource;
}
由於WebSecurityConfigurerAdapter的默認順序爲3,因此我已將資源服務器順序分別配置爲4和5。
但配置豆類越來越無效,我可以訪問的資源擁有5階,如果我嘗試訪問資源「/問候語」,我得到以下錯誤「/歡迎」,
{ "timestamp": 1444400211270, "status": 403, "error": "Forbidden", "message": "Expected CSRF token not found. Has your session expired?", "path": "/greeting"}
如果我互換資源之間的順序,我可以訪問具有最高價值5
注意資源:我有兩個客戶,使人們可以訪問資源1,另一個可以訪問資源2。
請指教我失蹤的事情。