亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何用 Spring Boot 安全功能替換 Basic auth?

如何用 Spring Boot 安全功能替換 Basic auth?

明月笑刀無情 2023-07-13 17:47:13
目前我們使用基本身份驗證并將加密格式的用戶名和密碼設置為 HttpHeaders。有沒有辦法用 Springboot 安全性刪除/替換它?如果是的話,你能幫我在我的項目中實現這一點嗎?
查看完整描述

1 回答

?
慕斯王

TA貢獻1864條經驗 獲得超2個贊

  • 您可以按照以下步驟從 Spring Boot 中刪除現有的基本身份驗證嗎

  • 在 Spring Boot 中,我們可以通過配置實用程序類 WebSecurityConfigurerAdapter 來啟用 BasicAuth,并且當您配置它時,您將允許在訪問應用程序中的任何配置的 URL(或所有 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");

    }

}

腳步


從 POM 文件中刪除依賴項

 <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-security</artifactId>

    </dependency>


查看完整回答
反對 回復 2023-07-13
  • 1 回答
  • 0 關注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號