Eureka安全認證


Eureka 服務加入安全認證只需要在之前的服務中增加三處步驟即可:

1、在Eureka Server中加入spring-boot-starter-security依賴

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>

注意:只要加入了security包則自動開啟了默認安全認證,密碼隨機生成,在控制台可以看到。

2、修改application.yml新增配置

spring: application: name: mima-cloud-eureka server: port: 8761 security: basic: #關閉安全驗證 enabled: true user: name: ruthless password: 123456 eureka: instance: #實例主機名 hostname: localhost client: #不向Eureka注冊自己 register-with-eureka: false #不檢查其他的EurekaServer節點 fetch-registry: false

 

3、啟動Eureka服務:

輸入配置文件中配置的用戶名和密碼即可。

4、在Eureka Client中修改application.yml中的service-url,形式為下面的模式:
eureka.client.serviceUrl.defaultZone=http://${userName}:${password}@localhost:1111/eureka/

debug: false spring: application: name: mima-cloud-eureka-producer server: port: 9907 eureka: client: serviceUrl: #defaultZone: http://localhost:8761/eureka/
      defaultZone: http://ruthless:123456@localhost:8761/eureka/
 instance: prefer-ip-address: true instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port} 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM