使用方法安全性springboot

时间:2019-06-02 22:59:55

标签: spring-boot jwt jjwt

我使用此示例(https://www.djamware.com/post/5c819d0180aca754f7a9d1ee/securing-restful-api-with-spring-boot-security-and-data-mongodb#ch5)创建安全的休息Api。但是可以使用@EnableGlobalMethodSecurity在方法级别进行安全保护吗?

如何..tks

1 个答案:

答案 0 :(得分:2)

好的。只需在任何@EnableGlobalMethodSecurity bean上注释@Configuration。一个不错的方法是在配置安全性的配置Bean上添加注释:

@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

}

然后,您可以使用@PreAuthorize@PreFilter@PostAuthorize@PostFilter来配置SpEL以保护bean方法:

@PreAuthorize("hasRole('ADMIN')")
public void create(Contact contact){

}

有关可用于保护方法安全的内置SpEL的可用列表,请参见this

相关问题