eureka注册中心的安全问题(对eureka也要授信用户才能访问)

  1. 在eureka 模块中pom.xml中引入security
   <!-- 引入spring的security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
  1. 在eureka模块的application.yml中加入安全配置
	spring:
      security:
        user:
          name: admin
          password: a
  1. 再重启eureka,测试一下授权登录访问 http://localhost:端口号

此时 其他服务也无法在eureka上注册了,所以要在其他服务端中加入登录配置
在这里插入图片描述
解决方案; 在 其他服务端的application.yml中修改登录eureka登录配置

eureka:
  client: # 客户端进行Eureka注册的配置
    service-url:
      #defaultZone: http://localhost:7001/eureka
      defaultZone: http://admin:a@localhost:7001/eureka  #授信用户登录

并且要求在eureka模块中增加一个类: 关闭 csrf

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 EurekaSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
  protected void configure(HttpSecurity http)throws Exception{
      http.csrf().disable();
      super.configure(http);
  }
}

关于什么是csrf 可以查看 :https://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html
之后
再重启eureka,再重启 服务端,可以看到 服务端在eureka中注册成功
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值