eureka 加入密码认证 springboot-admin 加入密码认证

eureka 加入密码认证 springboot-admin 加入密码认证

  1. pom.xml 加入依赖

    org.springframework.boot spring-boot-starter-security
  2. application.properties 配置如下 用户名和密码

    #开启安全认证 用户名和密码
    spring.security.basic.enabled=true
    spring.security.user.name=admin
    spring.security.user.password=root

    eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@localhost:${server.port}/eureka/

  3. 加入配置类 WebSecurityConfig.java.

    package org.fh.config;

    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;
    import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    复制代码
     @Override
     protected void configure(HttpSecurity http) throws Exception {
     	
     	SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
     	successHandler.setTargetUrlParameter("redirectTo");
    
     	http.headers().frameOptions().disable();
     	
     	http.csrf().disable().authorizeRequests().antMatchers("/actuator/**").permitAll().anyRequest().authenticated().and().httpBasic();
     }

    }

注意:Eureka启动,报Failed at: ${replica.key} [in template "eureka/navbar.ftl 解决方案:设置的密码中可能有@符号"

相关推荐
hryou09229 分钟前
10分钟看懂嵌入模型选型:6个维度+1张存储账单
人工智能·后端·机器学习
device_Any22 分钟前
线上CPU飙高,排查先分清三种形态
java·后端开发
骑着蜗牛撵大象32739 分钟前
K8s Operator 排障:调谐循环、Finalizer 与状态漂移的 4 个坑
java·kubernetes·dubbo·operator·finalizer·状态漂移
两点王爷43 分钟前
StringBuffer 和 StringBuilder 高频面试题全解析
java·开发语言·面试
SummerJokes1 小时前
Java 异常处理完整详解|try‑catch‑finally、throws、throw、自定义异常实战
java·开发语言·python
sharemylove1 小时前
Java 面向对象(OOP)笔记
java·开发语言·笔记·学习·课程设计
warpdrivelabs2 小时前
DCT / DOC / FLC 元数据定义体系 —— 通用化 · 国际化 · 业务化 演进方案
大数据·数据库·云原生·架构
IT研究室2 小时前
最新计算机毕业设计选题推荐-基于spring boot的家庭医生管理系统-网站-文档指导-Java-springboot
java·spring boot·课程设计
DataMover智迁2 小时前
免费数据库同步工具怎么选?DataMover 的定时全量、增量与 CDC
java·数据库·oracle
吴声子夜歌3 小时前
Kubernetes进阶实战——Ingress与服务发布(二)
云原生·容器·kubernetes