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

相关推荐
Rain的Java大神之路几秒前
MySQL 与 Redis 双写一致性:从 Cache-Aside 到 Binlog 兜底,一次讲透
java·后端·面试
程序员蜡笔熊1 分钟前
HTML attribute 和 DOM property,根本不是一回事
java·前端·html
夜雪轻寒8 分钟前
Spring Boot 4 升级 Redis 序列化:编译报 tools.jackson.databind 不存在
spring boot·redis·后端
泡海椒12 分钟前
Java 生成接口调用量趋势 PDF:jquick-pdf 多重折线图(JChartType.MultipleLine)落地
java·开发语言·pdf
syf06111331 分钟前
Java 多线程编程:从原理到实战
java·开发语言
前端呆头鹅41 分钟前
Node.js 作为单线程语言,是怎样处理高并发的?
后端·node.js
ZhengEnCi2 小时前
所有账号存一张表,权限怎么做隔离:从RBAC表结构到行级隔离的落地写法
数据库·后端·postgresql
pan_junbiao7 小时前
Go 语言基本数据类型
java·前端·golang
这个昵称不容易11 小时前
网上摄影工作室系统设计与实现:96 个 Java 文件、115 个接口,作品发布到点赞评论一条线走完
java·springboot·毕设
码事漫谈11 小时前
AI 提效的真相:省下你的时间,填满你的硬盘
后端