【问题标题】:How do PrePost annotations stack with HttpSecurity configuration?PrePost 注释如何与 HttpSecurity 配置叠加?
【发布时间】:2017-03-07 12:42:39
【问题描述】:

我对 Spring Security 还很陌生,我正在尝试了解 @PreAuthorize@PostAuthorize 的实用性。这些注解采用内置表达式,在配置WebSecurityConfigurerAdapter时都可以放入HttpSecurity

尝试使用以下 Spring Java (Groovy) 配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().anyRequest().authenticated()
}

而控制器方法定义为:

@RequestMapping('/data/{id}')
@PreAuthorize('permitAll')
Data getData(@PathParam('id') String id) {
    //return some data
}

控制器方法似乎没有效果。我一直在阅读 Spring 官方文档,但似乎没有对此进行更详细的讨论。

【问题讨论】:

    标签: spring spring-mvc spring-security


    【解决方案1】:

    这些注释由对 script-security.xml 更改的 EnableGlobalMethodSecurity 配置注释启用(您试图避免)

    @EnableGlobalMethodSecurity(prePostEnabled=true)
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     ...
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-31
      • 2020-03-04
      • 2017-10-18
      • 2016-08-08
      • 2021-06-29
      • 2010-09-15
      • 2012-06-13
      • 1970-01-01
      • 2018-10-25
      相关资源
      最近更新 更多