本文基于SpringCloud-Dalston.SR5

一般的,Eureka在内网服务,我们不会对于外网暴露Eureka端口,所以一般Eureka不做任何验证。假设我们想进一步增强Eureka的安全性,可以结合spring security来简单配置一些安全设置

首先在Spring Cloud Eureka Server所在的项目中添加对于spring security的依赖:

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

然后在项目配置文件application.properties中加入安全认证,注意三点配置,用户名,密码,还有Eureka服务地址:

#打开security
security.basic.enabled=true
security.user.name=username
security.user.password=password

#这里的用户名密码就是上面配置的
eureka.client.service-url.defaultZone=http://username:password@localhost:8761/eureka  # 安全的注册地址
07-06 13:18