2017-07-20 43 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

工作。谢谢。 –