1 回答

TA貢獻1864條經驗 獲得超2個贊
您可以按照以下步驟從 Spring Boot 中刪除現有的基本身份驗證嗎
在 Spring Boot 中,我們可以通過配置實用程序類 WebSecurityConfigurerAdapter 來啟用 BasicAuth,并且當您配置它時,您將允許在訪問應用程序中的任何配置的 URL(或所有 url)之前進行身份驗證。
腳步
您必須刪除 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");
}
}
腳步
從 POM 文件中刪除依賴項
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
添加回答
舉報