我有一些像这样的API:api/{id}/action/{action}
并希望将它们添加到安全性中。
@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 :(得分:0)
您应该使用regexp作为路径变量:
@Override
public void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.PUT, "api/{\\d+}/action/**")
.access("hasAnyRole('View_account','Search_account')");
}
在这种情况下,{\\d+}
表示您的ID为数字