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

相关推荐
Sherotree3 小时前
Google Antigravity——Agent 被提到主界面
前端·ide·后端·edge浏览器
Mr数据杨4 小时前
【Codex】用学生入学评估模块建立新生能力画像
android·java·javascript·django·codex·项目开发
2601_962056234 小时前
Spring Boot 入门 与 无法解析符号 springframework 的解决
java·spring boot·后端
国医中兴4 小时前
电子病历的时序数据分析:ClickHouse在临床指标监控中的落地
微服务·云原生·容器·kubernetes·k8s
Thomas21434 小时前
Java scala 数组 链表
java·链表·scala
亚历克斯神4 小时前
低代码与 AI 的融合趋势——从可视化搭建到自然语言生成应用
java·spring·微服务
你驴我4 小时前
WhatsApp 多账号场景下的会话归档与历史消息检索优化实践
后端·python
学长毕业设计5 小时前
基于SpringBoot的瑜伽馆网站的设计与实现(源码+文档+讲解视频)
java·spring boot·后端
一嘴一个橘子5 小时前
nginx 常用命令(在 nginx 目录下执行)
java
harmful_sheep5 小时前
java group by常见用法
java·开发语言·python