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

相关推荐
alden_ygq6 分钟前
Kubernetes生产实战(十九):镜像拉取失败排查处理
云原生·容器·kubernetes
alden_ygq8 分钟前
Kubernetes排错(十四):Pod状态异常排查手册
云原生·容器·kubernetes
hie9889416 分钟前
k8s存储类型:emptyDir、hostPath、nfs、pvc及存储类storageclass的静态/动态创建pv
云原生·容器·kubernetes
D_aniel_38 分钟前
排序算法-堆排序
java·排序算法·堆排序
哞哞不熬夜1 小时前
JavaEE--文件操作和IO
java·开发语言·windows·学习·java-ee·intellij-idea·idea
LUCIAZZZ1 小时前
JVM之内存管理(二)
java·jvm·后端·spring·操作系统·springboot
向哆哆1 小时前
Hibernate 性能优化:告别慢查询,提升数据库访问性能
java·数据库·性能优化·hibernate
海风极客1 小时前
《Go小技巧&易错点100例》第三十一篇
开发语言·后端·golang
小雅痞1 小时前
[Java][Leetcode middle] 80. 删除有序数组中的重复项 II
java·python·leetcode
бесплатно1 小时前
Scala流程控制
开发语言·后端·scala