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

相关推荐
Bacon11 分钟前
给项目做一次"全身 CT":Agent Skills 生态里的代码体检全链路
前端·人工智能·后端
Java旅途26 分钟前
课程表编排与调课申请系统|排得开,也能把每次调整管清楚
后端
象牙塔五六七1 小时前
Java 泛型精讲:从 Stream 源码说起
后端
掘金挖土1 小时前
前端手摸手跑路之 AI 应用开发(十二)
前端·后端
程序员cxuan1 小时前
GPT-6.2 Astra 发布了,但口碑崩了。。。
人工智能·后端·程序员
象牙塔五六七1 小时前
Java 函数式编程精讲:从 Stream 源码说起 —— 用真实源码学懂函数式思维
后端
字节跳动数据库1 小时前
火山引擎缓存数据库:如何构建超大规模缓存集群的无感弹性能力
数据库·人工智能·后端
小满、1 小时前
Java 值传递
java·java 值传递
IT枫斗者枫哥1 小时前
Java 异步导出只测最终行数,为什么下载时仍会少一行?
java·后端
用户7850611957971 小时前
不会前端,我靠 AI 和 Python 做了一个 4K 壁纸站
后端