2017-07-20 40 views
2

我有一個如下的彈簧安全配置。禁用POST方法的彈簧安全性

http.authorizeRequests().antMatchers("/css/**").permitAll().and().authorizeRequests().antMatchers("/imgs/**").permitAll().anyRequest() 
    .fullyAuthenticated().and() 
    //.csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/updatepass/**").permitAll().anyRequest().fullyAuthenticated().and() 
    .formLogin().loginPage("/login") 
    .failureUrl("/login?error=401").permitAll().and() 
    //.csrf().ignoringAntMatchers("/updatepass").and() 
    .logout().permitAll().and().csrf().disable() 
    .authorizeRequests().antMatchers("/register").hasRole("ADMIN").and() 
    .authorizeRequests().antMatchers("/registeruser").hasRole("ADMIN");  

我想允許/updatepass允許,即使它不是一個autherized請求的任何請求POST方法。我嘗試了下面的評論配置,但它仍然在扔我登錄頁面。

我要打開的目標POST URL是一個接收JSON請求的API。和完整的網址是/updatepass我試着加入/**沒有什麼效果。請不要建議XML配置。只有Java配置請。

+0

您可以使用這樣的: <攔截的URL模式= 「/客戶/編輯」 訪問= 「isAuthenticated」 方法= 「GET」/> <攔截網址模式=「/客戶端/編輯」訪問=「hasRole('EDITOR')」方法=「POST」/> –

+0

謝謝@FadySaad,但我不想使用XML。完整的Java配置。 –

回答

4

嘗試在以下實施中添加configure(WebSecurity web)的重載方法。

public void configure(WebSecurity web) 
       throws Exception { 
    web.ignoring().antMatchers(HttpMethod.POST, "/updatepass/**"); 
} 
+0

工作。謝謝。 –