2017-06-16 115 views
0

我正在嘗試爲Gateway,UI,Resource構建完整的sample code。除了當我試圖發佈帖子時,每件事情都很完美。@ EnableOAuth2Sso和csrf

我首先注意到我有兩個來自網關的csrf,一個來自用戶界面。所以我的決定,我不知道是否是正確的是禁用用戶界面上的csrf並將其保留在網關(Zuul Proxy)上,但我無法做到這一點。

我不能告訴WebSecurityConfigurerAdapterResourceServerConfigurerAdapter

一旦我聲明一下適配器我應該程度WebSecurityConfigurerAdapter整個OAuth2Sso停止工作,我得到了拒絕訪問並ResourceServerConfigurerAdapter似乎並沒有做任何事情。

起初,我想在@EnableZuulProxy@EnableOAuth2Sso

回答

0

在此基礎上answer我發現@EnableOAuth2Sso應該是在同一個WebSecurityConfigurerAdapter如果存在,或者我們將最終有2適配器,這樣做禁用CSRF所以固定的每一件事情

@Configuration 
@EnableOAuth2Sso 
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { 


    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .csrf() 
       .disable() 
       //.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) 
       //.and() 
       .authorizeRequests() 
       .anyRequest().authenticated(); 

    } 
} 

在春季啓動1.5.8我也加入到設置security.oauth2.resource.filter-order=3。見https://github.com/spring-projects/spring-security-oauth/issues/1016