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_4467291616 分钟前
java实现发送邮件
java·开发语言
无相求码19 分钟前
为什么你的第二个 scanf 还没输入就直接跳过了?C语言输入缓冲区陷阱
c语言·后端
叼馒女友郭芙蓉20 分钟前
Function Calling理解
后端
玉宇夕落21 分钟前
LangChain RAG Retriever 的学习
后端
QCoding26 分钟前
Java转AI第三课:Spring AI如何把100行HTTP代码缩减到10行?
java·人工智能
用户2986985301426 分钟前
Python 一键导出 Excel 中的图表和形状为图片
后端·python·excel
用户81300778163728 分钟前
PageHelper分页查询步骤
后端
振宇i28 分钟前
Java集成openfeign远程RPC调用教程
java·rpc·openfeign
wear工程师30 分钟前
volatile 这题别只答「可见性」:面试官真正想听的是这条 happens-before
java·jvm
是小李呀30 分钟前
MyBatis、MyBatis-Plus 与全自动 ORM 的本质区别
后端