Unable to work due to various reasons such as continuous learning, micro-services now continue to learn, but a new demo, springcloud version using a Finchley.SR2.
Before using a simple demo implements registry, now verify the registration center plus security:
First, add dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
Second, modify the configuration file
Set security authentication username with password:
## username and password authentication
spring.security.user.name = ZRK
spring.security.user.password = 123
Modify eureka access url
eureka.client.service-url.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
Third, restart eureka service
Access, the interface is as follows:
Enter your user name, password
Fourth, the client registers to the registry
Modify the configuration file
eureka.client.serviceUrl.defaultZone=http://zrk:123@localhost:30000/eureka/
Fifth, add configuration in eureka Service
Look springcloud official document Securing The Eureka Server this part, it reads
Simply Spring -boot-starter- security will be added to the service path Spring Security, you can protect the Eureka service. By default, when Spring Security on the classpath it will require a valid CSRF sends a token every time the transmission request to the application. Eureka client does not usually have a valid token cross-site request forgery (CSRF), you need to disable this request / Eureka / ** endpoints
, For example:
@EnableWebSecurity class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().ignoringAntMatchers("/eureka/**"); super.configure(http); } }
Configuration is complete restart.