eureka 加入密码认证 springboot-admin 加入密码认证

eureka 加入密码认证 springboot-admin 加入密码认证

  1. pom.xml 加入依赖

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
  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 解决方案:设置的密码中可能有@符号"

相关推荐
曹牧13 分钟前
Spring:@RequestMapping
java·后端·spring
霸道流氓气质19 分钟前
SpringBoot+LangChain4j+Ollama实现本地大模型语言LLM的搭建、集成和示例流程
java·spring boot·后端
iiiiyu29 分钟前
常用API(SimpleDateFormat类 & Calendar类 & JDK8日期 时间 日期时间 & JDK8日期(时区) )
java·大数据·开发语言·数据结构·编程语言
迷藏49443 分钟前
# 发散创新:基于Selenium的自动化测试框架重构与实战优化在当今快速迭代的软件开
java·python·selenium·测试工具·重构
浮游本尊1 小时前
MES 实施计划从新建到自动流转:三条入口、一套存储、两类驱动
后端
Nyarlathotep01131 小时前
LockSupport工具类
java·后端
jieyucx1 小时前
Go 语言零基础入门:编写第一个 Hello World 程序
开发语言·后端·golang
一点一一1 小时前
nestjs+langchain:大模型的基本调用、对message的
人工智能·后端
阿巴斯甜1 小时前
BiFunction的使用
java
NineData1 小时前
NineData将亮相2026德国汉诺威工业博览会
运维·数据库·后端