[SpringCloud Notes] Eureka Registration Center adds permission authentication

When Spring Cloud implements service registration and discovery through Eureka, the web management interface is provided by default, but if it is exposed in the production environment, there will be security problems. In order to solve this problem, we can control it by adding permission authentication. The specific steps are as follows:

[step1]: Perform user authentication through spring-security and add relevant dependencies to pom

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

[step2]: Add the authentication configuration information to application.yml

 security.basic.enabled: true #Enable authentication
 security.user.name: userName #Your username
 security.user.password: password #Your password

 

[step3]: At the same time, the application that needs to be registered needs to modify the configuration file and add the authentication information, otherwise the registration will report a 401 authentication failure error

 eureka.client.serviceUrl.defaultZone: http://userName:password@localhost:8761/eureka/

Test: Visit http://localhost:8761/ again, the following authentication page will pop up, and enter the correct authentication information.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325250734&siteId=291194637