2014-11-05 120 views
8

我試圖設置一個資源服務器使用彈簧安全oauth使用單獨的授權服務器。我正在使用RemoteTokenServices,這需要/check_token端點。春季安全OAuth2 check_token終點

我可以看到/oauth/check_token當使用@EnableAuthorizationServer時,默認啓用端點。但是,端點默認情況下不可訪問。

是否應手動添加以下條目以將此端點列入白名單?

http.authorizeRequests().antMatchers("/oauth/check_token").permitAll(); 

這將使所有人都可以訪問此端點,這是所需的行爲嗎?或者我錯過了什麼。

由於提前,

回答

13

你必須

@Override 
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception 
{ 
    oauthServer.checkTokenAccess("permitAll()");  
} 

欲瞭解更多有關這::

How to use RemoteTokenService?

+3

不會 「isAuthenticated()」 比 「permitAll()」 更好? – 2014-11-07 07:43:34

+0

我寫了這個,因爲他試圖在上面的代碼中實現這一點。 – 2014-11-07 08:46:15

0

首先,配置訪問令牌表達:

@Override 
public void configure(AuthorizationServerSecurityConfigurer securityConfigurer) throws Exception { 
    securityConfigurer 
      .allowFormAuthenticationForClients() 
      .checkTokenAccess("isAuthenticated()") 
      .addTokenEndpointAuthenticationFilter(checkTokenEndpointFilter()); 
} 

然後,我們需要定義一個過濾器來處理客戶端身份驗證:

@Bean 
public ClientCredentialsTokenEndpointFilter checkTokenEndpointFilter() { 
    ClientCredentialsTokenEndpointFilter filter = new ClientCredentialsTokenEndpointFilter("/oauth/check_token"); 
    filter.setAuthenticationManager(authenticationManager); 
    filter.setAllowOnlyPost(true); 
    return filter; 
}