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

相关推荐
一路向北North6 分钟前
Spring Security OAuth2.0(22):分布式系统授权-搭建网关
java·后端·spring
存在的五月雨10 分钟前
SpringBoot后端限制重复提交
java·spring boot·后端
Sam_Deep_Thinking28 分钟前
一次线程池线上故障复盘:四层防线如何避免数据丢失
java·面试·程序员
paopaokaka_luck28 分钟前
基于Springboot3+Vue3的宠物殡葬管理系统(webSocket实时通讯、接入腾讯地图、支付宝沙盒支付、Echarts图形化分析)
java·开发语言·网络·后端
卷无止境32 分钟前
Python 中基于 Qt 的 GUI 库授权方式全解析
后端·python
程序员爱钓鱼33 分钟前
Rust 注释与文档注释详解:从代码说明到 cargo doc
后端·rust
前鼻音太阳熊42 分钟前
【MES系统】MES为什么需要SSE?从设备实时监控谈Spring Boot流式推送设计
java·spring boot·后端
Lhappy嘻嘻1 小时前
网络初识|基础入门:局域网广域网、IP 端口、TCP/IP 五层模型与封装解封装全过程
java·开发语言·网络·笔记·网络协议·tcp/ip
卷无止境1 小时前
Guardrails.ai:为大语言模型加一道"安全阀"
后端·python
Java面试题总结1 小时前
区间树:反向映射的前置数据结构
java·前端·数据结构