仅当令牌包含一个角色时才允许访问资源

时间:2020-04-09 16:33:56

标签: spring spring-security

以我的名义,我有两个角色["ADMIN", "BLOCKED"]。我想拒绝访问资源("/order")的这组角色,并允许访问,如果令牌仅包含一个角色["ADMIN"]

我正在尝试这样的事情:

.antMatchers("/home", "/cart") // allow access to this resources if token contains two roles ["ADMIN", "BLOCKED"]
            .hasAnyAuthority("BLOCKED", "ADMIN")
            .antMatchers("/order")//allow access only if token contain one role ["ADMIN"]
            .hasAuthority("ADMIN") 

但是在此安全配置中,如果令牌包含两个角色["ADMIN", "BLOCKED"],则不会拒绝对/order的许可。如何解决?

0 个答案:

没有答案