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

相关推荐
nece0014 分钟前
Kubernetes v1.36.0 + Ubuntu24.04 + containerd 2.x WordPress 完整部署文档
云原生·容器·kubernetes
wuqingshun3141599 分钟前
请描述简单工厂模式的工作原理
java·简单工厂模式
anno11 分钟前
Agent 新手 Skill 优先级指南:从第一套必装工作流,到专业能力补全
前端·后端
大不点wow15 分钟前
Spring 中 @Bean、@Component 与 @Configuration 的作用及底层逻辑
java·spring
hdsoft_huge23 分钟前
SpringBoot 系列 20:Jar 打包 + Docker 容器化 + Compose 一键部署|服务器上线 & 零停机平滑升级全教程
spring boot·docker·jar
anno25 分钟前
别再把文档“一刀切”:用 LangChain.js 做好 RAG 的第一公里
前端·后端
用户7138742290026 分钟前
claude_rules 深度解析:Claude Code 的模块化路径作用域规则
后端
IvorySQL27 分钟前
云环境下PostgreSQL的Cgroup内存管理实践
java·数据库·postgresql
卡卡罗特AI27 分钟前
曾经狂推的 Superpowers,今天我终于把它卸载了! 臃肿,Token吞金兽!
后端·chatgpt·ai编程
不定积分要+C_yyy28 分钟前
Java基础核心精讲:基本数据类型与包装类区别、自动装箱拆箱与缓存陷阱实战解析
java·开发语言