Spring Boot 2.0:如何禁用特定端点的安全性

kyc*_*w32 4 security authentication spring-boot

我需要完全绕过 Spring Boot 2.0 应用程序中某些端点的安全性(身份验证/授权)——端点如“/version”和“/robots.txt”——但为所有其他端点保持安全。

更复杂的是,我正在从事一个项目,该项目是一个更大项目的一部分。我公司有另一个小组提供了一个利用 spring 安全性的库。这只是相关的,因为这意味着我不能简单地覆盖一个 spring 安全类来完成这项工作——那些类已经被我无法控制的代码覆盖了。

有没有办法配置 spring boot 2.0 来绕过某些端点的身份验证?

在 sprint boot 1.5 中,我们可以在 application.yml 文件中指定:security.ignored: /version 但在 spring boot 2.0 中这不再有效。

kyc*_*w32 6

费德里科的回答是正确的。我在 Spring Boot 2.0 类中添加了以下类:

package com.example.demo;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class DemoConfigurer extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception{
        http.authorizeRequests().antMatchers("/version").permitAll();
        super.configure(http);
    }
}
Run Code Online (Sandbox Code Playgroud)

}