- 首先添加安全验证的依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> - 添加配置
spring: security: user: name: root # 用户名 password: root # 密码 - 添加启动配置文件
package com.my.eureka.app; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // 关闭csrf http.csrf().disable(); // 支持httpBasic http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); } } - 修改eureka注册的地址
defaultZone: ${EUREKA_SERVER:http://root:root@localhost:8761/eureka/}
备注:所有的客户端注册都需要添加账号密码,web管理页面登录也需要账号密码
最后
以上就是甜美芝麻最近收集整理的关于Eureka注册中心开启密码认证(可以防止外部服务注册进去)的全部内容,更多相关Eureka注册中心开启密码认证(可以防止外部服务注册进去)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复