一般的,Eureka在内网服务,我们不会对于外网暴露Eureka端口,所以一般Eureka不做任何验证。假设我们想进一步增强Eureka的安全性,可以结合spring security来简单配置一些安全设置
首先在Spring Cloud Eureka Server所在的项目中添加对于spring security的依赖:
1<dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-security</artifactId> 4</dependency>
然后在项目配置文件application.properties中加入安全认证,注意三点配置,用户名,密码,还有Eureka服务地址:
1#打开security 2security.basic.enabled=true 3security.user.name=username 4security.user.password=password 5 6#这里的用户名密码就是上面配置的 7eureka.client.service-url.defaultZone=http://username:password@localhost:8761/eureka # 安全的注册地址