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

相关推荐
ProgrammerPulse24 分钟前
企业云原生转型选型参考:VM / 容器混合负载场景青云云易捷容器版与 SmartX 技术适配解析
云原生·超融合
我要神龙摆尾41 分钟前
约定俗成的力量--java中泛型的意义和用法
java·开发语言
老友@1 小时前
分布式事务完全演进链:从单体事务到 TCC 、Saga 与最终一致性
分布式·后端·系统架构·事务·数据一致性
毅炼1 小时前
hot100打卡——day14
java·数据结构·算法·leetcode·ai·深度优先·哈希算法
C雨后彩虹1 小时前
优雅子数组
java·数据结构·算法·华为·面试
一嘴一个橘子1 小时前
springmvc 全局异常处理 and 拦截器
java
wangmengxxw1 小时前
SpringAI-mysql
java·数据库·人工智能·mysql·springai
Coder_Boy_1 小时前
基于SpringAI的在线考试系统-数据库设计核心业务方案
java·数据库·spring boot·ddd·tdd
一嘴一个橘子1 小时前
springmvc 参数校验
java
shehuiyuelaiyuehao1 小时前
String的杂七杂八方法
java·开发语言