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

相关推荐
请告诉他2 分钟前
【实战经验】Dell Inspiron 7560 升级 BIOS 支持 DDR4-2666 内存,解决 Spring Cloud 多模块开发内存瓶颈
后端·spring·spring cloud
悟能不能悟5 分钟前
JAVA 对象转为二级制流,再转化为base64
java·开发语言
我想问问天5 分钟前
【从0到1大模型应用开发实战】02|用 LangChain 和本地大模型,完成第一次“可控对话
后端·langchain·aigc
潲爺13 分钟前
Java-IO笔记
java·笔记·学习
JH307315 分钟前
静态资源映射相关问题解答
java
爬山算法17 分钟前
Hibernate(6) Hibernate支持哪些数据库?
java·数据库·hibernate
爱吃牛肉的大老虎26 分钟前
Spring WebFlux与SpringMVC 对比讲解
java·后端·spring
QQ 313163789040 分钟前
文华财经软件指标公式期货买卖信号提示软件
java·前端·javascript
老华带你飞43 分钟前
房屋租赁管理系统|基于java+ vue房屋租赁管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
jqrbcts44 分钟前
关于发那科机器人如何时时把角度发给PLC
java·服务器·网络·人工智能