2015-09-04 57 views
0

我有一個非常簡單的安全配置在我的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請求被允許通過驗證的用戶

+0

你好Piotr你解決了這個問題嗎? –

回答

1

我剛剛遇到了同樣的問題。有兩種方法來解決這個問題:通過HttpSecurity http.csrf().disable()在 配置方法

    1. 禁用CSRF保護添加CSRF令牌的JSON。更多關於這個,你可以閱讀 this link

  • +0

    我已禁用csrf - 請參閱問題中的代碼片段。 –

    相關問題