禁用POST方法的spring安全性

Pas*_*kam 2 java spring spring-security

我有一个如下的弹簧安全配置.

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");     
Run Code Online (Sandbox Code Playgroud)

我想允许/updatepassPOST方法允许任何请求,即使它不是一个autherized请求.我尝试了以下注释配置,但它仍然是我的登录页面.

我要打开的目标POST URL是一个可以接收JSON请求的API.并且/updatepass我尝试添加完整的URL /**无效.请不要建议XML配置.请只提供Java配置.

sha*_*zin 9

尝试configure(WebSecurity web)使用以下实现添加重载方法.

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