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

相关推荐
范什么特西6 分钟前
计算机杂记
java
RyFit14 分钟前
SpirngAI
java
阿维的博客日记16 分钟前
Spring Cloud 为什么需要服务注册与发现中心这些东西?
后端·spring·spring cloud
笑而不语16 分钟前
13|元数据过滤检索:UserContext 与按用户查知识
后端
庞轩px20 分钟前
第六篇:Spring用了哪些设计模式?——从单例到代理,拆解框架中的经典设计
java·spring·设计模式·bean·代理模式·aop·单例
番石榴AI39 分钟前
纯 CPU 推理!0.1B 超轻量级端到端OCR模型,使用 Java 进行文档解析
java·开发语言·ocr
likerhood43 分钟前
ConcurrentHashMap详细讲解(java)
java·开发语言·性能优化
用户095367515831 小时前
Go:浮点数如何进行比较?
后端·go
Zeus_1 小时前
如何更好的创建skill
后端
千云1 小时前
AI Coding 落地探索日志 · 初篇 · 启程记
后端·ai编程