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

相关推荐
壹方秘境6 分钟前
ApiCatcher支持抓包HTTP传输大文件的实现原理分享
前端·后端·客户端
神奇小汤圆21 分钟前
2026最新·最全·最实用|Java岗面试真题(已收录GitHub)
后端
神奇小汤圆28 分钟前
面试官当场让我手写Java线程安全工具类,我写完直接拿到了35K offer
后端
久美子1 小时前
Qoder 使用指南:从配置到落地
后端
tyung1 小时前
Go 手写 Wait-Free MPSC 无界队列:SwapPointer 实现多生产者无锁入队
后端·go
张不才2 小时前
CPU 100% 了怎么办?Java 性能排障的标准化操作
java·后端
鱼人2 小时前
Redis、网关负载均衡为什么不能用普通取模哈希?
后端
juejin9983 小时前
Claude Code Lab-3(下):三能力 MCP Server
后端
java小白小3 小时前
SpringBoot(07):事务管理——@Transactional 你真的用对了吗?
后端
shepherd1113 小时前
吞吐量提升 10 倍:高并发大批量数据处理任务的架构演进与性能调优
java·后端·架构