開啓Eureka的安全認證(訪問web頁面需要驗證用戶名和密碼)

我們需要引入的依賴包

<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-security</artifactId>
		</dependency>

 然後需要在配置文件中增加的配置:

 

spring:
  security:
    user:
      name: root
      password: jack66666

最後我們需要增加一個配置類:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // TODO Auto-generated method stub
        // super.configure(http);
        http.csrf().disable();
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}

啓動項目成功後我們訪問Eureka的管理界面需要認證。

這時候就需要輸入用戶名和密碼去訪問了。

同理我們服務端往Eureka註冊也是需要添加認證信息的

 

spring:
  security:
    user:
      name: root
      password: jack66666

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章