java - 禁用 Spring Security 的 POST 方法

标签 java spring spring-security

我的 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/

相关文章:

java - Spring Integration - 在消息中添加自定义 header

java - Spring mvc Controller jsr 303基本列表验证

java - Spring 4.1.5.RELEASE 中的 ResourceUrlEncodingFilter 启用了 springSecurityFilterChain

grails - 将Grails 2.0.4部署到Glassfish 3.1.2服务器时出错

java - Apache Camel : Why I can't send bean text to jms

显示为 Null 的 Spring 属性

java - Java中如何将十六进制字节转换为Unicode

grails - 禁用 Grails Spring Security 插件

java - Appengine Mapreduce 受限类 ManagementFactory

java - 从其他目录运行 gradle 命令