Java 如何用Spring引导安全功能替换基本身份验证?

Java 如何用Spring引导安全功能替换基本身份验证?,java,spring-boot,spring-security,spring-security-oauth2,Java,Spring Boot,Spring Security,Spring Security Oauth2,目前,我们正在使用基本身份验证,并将加密格式的用户名和密码设置为HttpHeaders。有没有办法用Springboot安全性来删除/替换它?如果是,您能帮助我在我的项目中实现这一点吗。 您可以按照步骤从spring中删除现有的基本身份验证吗 靴子 在SpringBoot中,我们可以通过配置实用程序类来启用BasicAuth 哪个WebSecurityConfigureAdapter,当您配置它时 将允许在访问任何配置的URL之前进行身份验证 (或所有URL)在应用程序中 步骤 您必须删除We

目前,我们正在使用基本身份验证,并将加密格式的用户名和密码设置为HttpHeaders。有没有办法用Springboot安全性来删除/替换它?如果是,您能帮助我在我的项目中实现这一点吗。

  • 您可以按照步骤从spring中删除现有的基本身份验证吗 靴子
  • 在SpringBoot中,我们可以通过配置实用程序类来启用BasicAuth 哪个WebSecurityConfigureAdapter,当您配置它时 将允许在访问任何配置的URL之前进行身份验证 (或所有URL)在应用程序中
步骤

  • 您必须删除WebSecurityConfigureAdapter扩展类
  • 我会附上它的样子

    
    @Configuration
    public class EnablingSecutiry extends WebSecurityConfigurerAdapter
    {
        @Override
        protected void configure(HttpSecurity http) throws Exception
        {
            http
             .csrf().disable()
             .authorizeRequests().anyRequest().authenticated()
             .and()
             .httpBasic();
        }
    
        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth)
                throws Exception
        {
            auth.inMemoryAuthentication()
                .withUser("admin")
                .password("{noop}password")
                .roles("USER");
        }
    }
    
    步骤

  • 从POM文件中删除依赖项
  • 
    org.springframework.boot
    弹簧启动安全
    
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>