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

相关推荐
雨奔几秒前
Kubernetes 对象标识详解:Name、UID、Label
云原生·容器·kubernetes
xifangge20258 分钟前
【故障排查】IDEA 打开 Java 文件没有运行按钮(Run)?深度解析项目标识与环境配置的 3 大底层坑点
java·ide·intellij-idea
麻辣璐璐8 分钟前
EditText属性运用之适配RTL语言和LTR语言的输入习惯
android·xml·java·开发语言·安卓
weisian15113 分钟前
Java并发编程--33-Redis分布式缓存三大核心架构:主从、哨兵、分片,落地实战与选型
java·redis·缓存·主从架构·哨兵架构·分片架构
清溪54918 分钟前
Damn Vulnerable Web Application(中)
后端
清溪54920 分钟前
Damn Vulnerable Web Application(上)
后端
APIshop23 分钟前
Python 爬虫获取京东商品详情 API 接口实战指南
java·服务器·数据库
wang090728 分钟前
Linux性能优化之内存管理基础知识
java·linux·性能优化
掘金码甲哥31 分钟前
AI编程智能体登味太浓了,必须治一治!
后端
StackNoOverflow39 分钟前
SpringCloud的声明式服务调用 Feign 全面解析
后端·spring·spring cloud