gpt4 book ai didi

grails - Grails HttpSecurity-允许POST

转载 作者:行者123 更新时间:2023-12-02 15:22:50 25 4
gpt4 key购买 nike

我的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请求被允许通过身份验证的用户

最佳答案

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

  • 通过中的HttpSecurity http.csrf().disable()禁用csrf保护
    配置方法
  • 向您的JSON添加一个csrf token 。有关此内容的更多信息,请阅读
    this link
  • 关于grails - Grails HttpSecurity-允许POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32399398/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com