Spring Security-授权规则中的通配符/匹配器

时间:2020-04-23 13:31:03

标签: java spring security configuration

在配置Spring Boot应用程序的安全性时,我希望根据在此输入的PathVariable来保护API的某些部分。我当前的配置如下:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

//not important

@Override
public void configure(HttpSecurity http) throws Exception {
    http.cors();
    http.authorizeRequests()
            .mvcMatchers("/api").authenticated()
            .mvcMatchers("/api/TEST").hasAuthority("SCOPE_dep:TEST")
            .and().oauth2ResourceServer().jwt();
}
}

在“ api / {PathVariable}”端点中,我要自定义端点,请确保具有权限“ SCOPE_dep:TEST”的人可以访问“ api / TEST”端点,而具有“ SCOPE_dep”的人: TEST2授权可以访问“ api / TEST2”端点,甚至可以为具有多个这些授权的用户提供一个以上的端点。

是否有办法使用我不知道的通配符/匹配器类型,还是唯一可以对所有这些不同权限进行硬编码的方法?

0 个答案:

没有答案