我的 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
我尝试添加 /**
没有效果。请不要建议 XML 配置。请仅使用 Java 配置。
最佳答案
尝试使用以下实现添加 configure(WebSecurity web)
的重载方法。
public void configure(WebSecurity web)
throws Exception {
web.ignoring().antMatchers(HttpMethod.POST, "/updatepass/**");
}
关于java - 禁用 Spring Security 的 POST 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45204710/