eureka 註冊中心 增加賬號和密碼保護(Spring boot 2.x)

Eureka註冊中心:

1.pom.xml增加依賴:

<dependency>

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

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

</dependency>
2.配置文件:application.yml

spring:
  profiles: jielong
  security:
    basic:
      enabled:true
    user:
      name: user1
      password: password123

3.開啓認證

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //開啓認證
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
        http.csrf().ignoringAntMatchers("/eureka/**");
        super.configure(http);

    }
}

 

4.應用客戶端配置文件:application.yml

eureka:
  client:
    serviceUrl:
       defaultZone: http://user1:password123@localhost:9030/eureka/

 

5.登錄控制檯:(某些瀏覽器不支持直接登錄)

http://user1:password123@localhost:9030/

http://localhost:9030/

輸入賬號和密碼;

 

 

 

 

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