【问题标题】:How to replace Basic auth with Spring Boot security feature? [closed]如何用 Spring Boot 安全功能替换基本身份验证? [关闭]
【发布时间】:2019-09-07 14:34:18
【问题描述】:

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

【问题讨论】:

    标签: java spring-boot spring-security spring-security-oauth2


    【解决方案1】:
    • 您能否按照步骤从 spring 中删除现有的基本身份验证 开机
    • 在 Spring Boot 中,我们可以通过配置实用程序类来启用 BasicAuth 哪个 WebSecurityConfigurerAdapter,当你配置它时,你 将允许在访问任何配置的 URL 之前进行身份验证 (或所有网址)在您的应用程序中。

    步骤

    1. 您必须删除 WebSecurityConfigurerAdapter 扩展类

    我会附上它的样子

    
    @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");
        }
    }
    

    步骤

    1. 从 POM 文件中删除依赖项
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 2018-04-13
      • 1970-01-01
      • 2012-09-05
      • 2018-09-07
      • 2019-04-25
      • 2019-02-21
      • 2017-07-31
      • 2017-11-02
      相关资源
      最近更新 更多