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 解决方案:设置的密码中可能有@符号"

相关推荐
m0_5257247215 分钟前
AIOps全链路智能运维架构揭秘
云原生·devops
捡田螺的小男孩17 分钟前
什么是 Skill?手把手带你写一个简单有用的 Skill!
前端·后端·程序员
IT_陈寒22 分钟前
Redis集群这个坑,差点让我通宵
前端·人工智能·后端
极创信息37 分钟前
系统安全隐患全方位排查方案:标准化渗透测试全流程
java·opencv·struts·数据挖掘·eclipse·语音识别·hibernate
用户83562907805144 分钟前
Python 自动化 Word 文本框处理:创建、定位、填充内容与管理
后端·python
网渡科技1 小时前
向量数据库选型指南:RAG场景下的性能对比与调优策略
后端
汉字萌萌哒1 小时前
2019CCF-CSP入门级C++试题解析
java·开发语言·c++
riverNijika1 小时前
项目学习笔记:C++基础同步输出日志库
后端
Lyra_Infra1 小时前
OpenClaw 升级及 Channel 安装故障排查与遗留问题分析
后端·npm
喜欢的名字被抢了1 小时前
程序出问题怎么查,以及如何让它不掉线
java·运维·数据库