如何将基本身份验证替换为 Spring 启动安全功能?



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

  • 你能按照这个步骤从春天中删除现有的基本身份验证吗? 靴子
  • 在 Spring 启动中,我们可以通过配置实用程序类来启用基本身份验证 哪个网络安全配置器适配器,当您配置它时,您 将允许在访问任何配置的 URL 之前进行身份验证 (或所有网址(在您的应用程序中。

步骤

  1. 您必须删除网络安全配置器适配器扩展类

我会附上它的样子


@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>

最新更新