Grails的HttpSecurity - 允许POST
问题描述:
我有一个非常简单的安全配置在我的Grails应用3.0.3:Grails的HttpSecurity - 允许POST
@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()
}
我也有一些DomainClasses其使用@Resource注释
@Resource(uri="/myresource",formats=['json'])
当我打开关闭/ **路径认证 - 一切正常。但是,当我为/ **启用身份验证时,包括/ myresource,它不再接受POST请求。那么返回405方法是不允许的。 如何在Grails 3中使用HttpSecurity允许POST请求?
更新1: GET请求被允许通过验证的用户
答
我刚刚遇到了同样的问题。有两种方法来解决这个问题:通过HttpSecurity http.csrf().disable()
在 配置方法
禁用CSRF保护添加CSRF令牌的JSON。更多关于这个,你可以阅读 this link。
+0
我已禁用csrf - 请参阅问题中的代码片段。 –
你好Piotr你解决了这个问题吗? –