2017-06-20 1293 views
0

我有一些這樣的API:api/{id}/action/{action}並希望將它們添加到安全性。Spring:使用ResourceServerConfigurerAdapter配置API

@Override 
    public void configure(HttpSecurity http) throws Exception { 
.antMatchers(HttpMethod.PUT, "api/*/action/*").access("hasAnyRole('View_account','Search_account')"); 
} 

當我使用沒有角色的帳戶:View_account和Search_account。這個API仍然運行良好,不響應403.請告訴我如何配置多路徑變量的安全性。

回答

0

您應該使用正則表達式的路徑變量:

@Override 
public void configure(HttpSecurity http) throws Exception { 
    .antMatchers(HttpMethod.PUT, "api/{\\d+}/action/**") 
    .access("hasAnyRole('View_account','Search_account')"); 
} 

在這種情況下{\\d+}意味着你的ID是數字

+0

試試這個{\\ W +} –

相關問題