【问题标题】:Grails HttpSecurity - allowing POSTGrails HttpSecurity - 允许 POST
【发布时间】:2015-11-30 16:35:38
【问题描述】:

我的 Grails 3.0.3 应用程序中有一个相当简单的安全配置:

@Configuration
@EnableWebSecurity
class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers('/admin/**').hasAnyRole('ADMIN')
            .antMatchers('/**').hasAnyRole('USER', 'ADMIN')
            //.antMatchers('/').permitAll()
            .and()
        .formLogin().permitAll()
            .and()
        .logout().permitAll()

    http.headers().frameOptions().disable()

    http.csrf().disable()
}

我还有一些使用 @Resource 注释的 DomainClasses

@Resource(uri="/myresource",formats=['json'])

当我关闭 /** 路径的身份验证时 - 一切正常。但是当我为 /** 保留身份验证时,包括 /myresource,它不再接受 POST 请求。然后返回不允许的 405 方法。 如何在 Grails 3 中使用 HttpSecurity 允许 POST 请求?

更新 1: 经过身份验证的用户允许 GET 请求

【问题讨论】:

  • 你好 Piotr 问题解决了吗?

标签: grails spring-security grails-3.0


【解决方案1】:

我刚刚遇到了同样的问题。解决方法有两种:

  1. 通过HttpSecurity http.csrf().disable()禁用csrf保护 配置方法

  2. 向您的 JSON 添加一个 csrf 令牌。有关此的更多信息,您可以阅读 this link

【讨论】:

  • 我已经禁用了 csrf - 请参阅问题中的代码 sn-p。
猜你喜欢
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 2022-10-24
  • 2013-08-09
  • 2015-10-04
相关资源
最近更新 更多