Spring cloud eureka 安全认证基本配置

本文介绍了如何在Spring Cloud Eureka中添加安全认证,分别从server端和client端进行配置。server端涉及maven依赖更新、YML配置修改,包括服务器地址和安全认证方式的调整。client端则需要更新YML文件中的defaultzone设置。为了实现安全认证,还需要禁用csrf并添加特定的配置类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要添加Spring cloud eureka 的安全认证需要在server 和 client 两端分别进行配置

首先是server端:

(1)添加的maven

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

(2)yml配置

yml 中添加:

spring:
    security:
        user:
          name: admin #登陆用户名
          password: admin #登陆密码

服务器地址的yml改为:

eureka:
  client:
    #registerWithEureka: false #其本身作为注册中心,所有设置为:不显示在注册中心
    service-url:
      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@peer1:1111/eureka/

(3)安全认证方式的修改

 新版本的安全认证不支持yml如下配置:

security:
  basic:
     #开启认证
    enabled: true

需要关闭csrf认证方式,添加如下配置类

@EnableWebSecurity
public class WebSecurityConf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值