【问题标题】:Use method security springboot [closed]使用方法安全弹簧靴[关闭]
【发布时间】:2019-10-18 13:10:30
【问题描述】:

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

如何.. tks

【问题讨论】:

    标签: spring-boot jwt jjwt


    【解决方案1】:

    当然。只需在任何 @Configuration bean 上注释 @EnableGlobalMethodSecurity。一个好的方法是在配置安全性的配置 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

    【讨论】:

      猜你喜欢
      • 2018-10-12
      • 2017-12-22
      • 2018-02-14
      • 1970-01-01
      • 2019-05-03
      • 2021-04-20
      • 1970-01-01
      • 2023-01-07
      • 2012-06-05
      相关资源
      最近更新 更多