繁体   English   中英

为POST方法禁用Spring Security

[英]Disable spring security for POST method

我有一个如下的spring安全配置。

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 POST方法用于任何请求,即使它不是经过身份验证的请求也是如此。 我尝试了以下注释配置,但仍然使我无法登录页面。

我要打开的目标POST URL是一个可以接收JSON请求的API。 完整的URL是/updatepass我尝试添加/** /updatepass 请不要建议XML配置。 请仅Java配置。

尝试通过以下实现添加configure(WebSecurity web)的重载方法。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM