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

相关推荐
weixin_440784114 分钟前
【IntentSeivice实现原理】
android·java·开发语言·intentservice
攻城有术10 分钟前
专项攻克-springcloud及其组件
后端·spring·spring cloud
IanSkunk15 分钟前
企业AI Agent生产化落地:从技术架构到实施服务的全链路分析
java·人工智能·架构
岁岁养乐多34 分钟前
Java 序列化相关问题
java·开发语言
张忠琳1 小时前
【NPU】Ascend Device Plugin —Part 6 K8s客户端 + 重复检测模块 超深度源码分析之二
云原生·容器·kubernetes·npu·docker device
JLWcai202510091 小时前
核电打磨 “安全卫士”|金利威不锈钢专用树脂砂轮,合规高效双在线
mysql·mongodb·eureka·sqlite·rabbitmq·nosql·memcached
小短腿乄1 小时前
java实现pdf加水印+签名
java·开发语言·pdf
Kripath_Rion1 小时前
带你速通计算机经典论文(一):分布式系统篇
分布式·后端·架构
云川之下2 小时前
【k8s】SR‑IOV‑Network‑Operator 详解
云原生·容器·kubernetes