【问题标题】:Allow get, but not post, put for some role允许获取,但不允许发布,放置一些角色
【发布时间】:2016-10-19 10:11:40
【问题描述】:

我使用 spring boot 和 spring security。

我像这样基于 url 添加安全性

http
    .authorizeRequests()                                                                
        .antMatchers("/resources/**", "/signup", "/about").permitAll()                  
        .antMatchers("/admin/**").hasRole("ADMIN")                                      
        .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")            
        .anyRequest().authenticated()                                                   
        .and()
    // ...
    .formLogin();

有没有办法只授权某个角色在 url 上获取、发布、放置...?

【问题讨论】:

    标签: spring spring-security


    【解决方案1】:

    您可以将方法作为antMatchers() 方法的第一个参数传递:

    http.authorizeRequests()
        .antMatchers(HttpMethod.GET, "/admin/**").hasRole("ADMIN")
    

    链接到API for AbstractRequestMatcherRegistry.antMatchers()

    附:类似问题:Spring security authorize request for url & method using HttpSecurity

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 2013-03-23
      • 2016-11-02
      • 1970-01-01
      • 2017-08-08
      • 2015-08-15
      • 2015-03-09
      相关资源
      最近更新 更多