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

相关推荐
考虑考虑5 小时前
tcpdump指令
运维·后端·自动化运维
Resean02235 小时前
架构设计系列(十六):DDD 与代码架构
java·开发语言·架构
Wellijohn6 小时前
2000 个请求、30% 失败率:我把 Python 批量并发的限流和重试参数算了一遍
后端·python·性能优化
皮皮林5516 小时前
YouTube 是如何保存巨量视频文件的?
后端
学长毕设6 小时前
基于SpringBoot 车辆租赁系统平台-附源码
java·spring boot·后端
码途行者6 小时前
每天10分钟学Go:第22课 自定义错误
开发语言·后端·golang
方便面不加香菜7 小时前
Docker Compose 文件 -- docker-compose.yml
spring cloud·docker·容器
Csvn7 小时前
Nginx 性能调优与压测:连接账本、找拐点与调优前后对比
后端·nginx
Flynt8 小时前
Spring AI Alibaba 真停更了?我把它的 GitHub 翻了个底朝天
java·spring·开源
你的钉钉响了10 小时前
用 kubeadm-ha 部署高可用 Kubernetes 集群
云原生·容器·kubernetes·ansible·高可用集群·kubeadm-ha