我是靠谱客的博主 留胡子身影,最近开发中收集的这篇文章主要介绍Spring cloud eureka 安全认证基本配置,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

要添加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 WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.csrf().disable(); //关闭csrf
        super.configure(http);
    }
}

client端配置

yml 配置中修改defaultzone为

eureka:
  client:
    serviceUrl:
      defaultZone: http://admin:admin@peer2:1112/eureka/ #注册中心地址

完成配置

参考文献:https://blog.csdn.net/u011499747/article/details/77410997

最后

以上就是留胡子身影为你收集整理的Spring cloud eureka 安全认证基本配置的全部内容,希望文章能够帮你解决Spring cloud eureka 安全认证基本配置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部