Preface
In a previous article, we started Eureka Server in spring cloud, and then entered http://localhost:8761/ in the browser and entered directly to enter the service governance page of spring cloud. This is extremely unsafe in the production environment. Next, we will add secure user authentication to Eureka Server.
1. Add spring-security support
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
2. Add security authentication to the configuration file
# eureka.client.registerWithEureka: Indicates whether to register yourself with Eureka Server, default is true. Since the current application is Eureka Server, it is set to false # eureka.client.fetchRegistry: indicates whether to obtain registration information from Eureka Server, default is true. Because this is a single point of Eureka Server, it does not need to synchronize the data of other Eureka Server nodes, so it is set to false. # eureka.client.serviceUrl.defaultZone: Set the address to interact with Eureka Server. Both query services and registration services need to rely on this address. The default is http://localhost:8761/eureka; multiple addresses can be used and separated. server: port: 8764 # Security authentication configuration security: basic: enabled: true user: name: chhliu # Username password: chhliu123456 # User password eureka: client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://chhliu:chhliu123456@localhost:8761/eureka # Secure registration address
3. Enter http://localhost:8764/ in the browser
After entering the car, you will find that you need to enter the username and password for verification. Only after entering it correctly will you enter the service governance page of Eureka Server.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.