我是靠谱客的博主 甜美芝麻,这篇文章主要介绍Eureka注册中心开启密码认证(可以防止外部服务注册进去),现在分享给大家,希望可以做个参考。

  1. 首先添加安全验证的依赖
     
      <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
  2. 添加配置
    spring:
      security:
        user:
          name: root   # 用户名
          password: root # 密码

     

  3. 添加启动配置文件
    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();
        }
    }
    

     

  4. 修改eureka注册的地址
     
defaultZone: ${EUREKA_SERVER:http://root:root@localhost:8761/eureka/}

备注:所有的客户端注册都需要添加账号密码,web管理页面登录也需要账号密码

 

最后

以上就是甜美芝麻最近收集整理的关于Eureka注册中心开启密码认证(可以防止外部服务注册进去)的全部内容,更多相关Eureka注册中心开启密码认证(可以防止外部服务注册进去)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部