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

相关推荐
brzhang3 分钟前
为什么说低代码谎言的破灭,是AI原生开发的起点?
前端·后端·架构
阿里云云原生36 分钟前
不重启、不重写、不停机:SLS 软删除如何实现真正的“无感数据急救”?
云原生
得物技术37 分钟前
破解gh-ost变更导致MySQL表膨胀之谜|得物技术
数据库·后端·mysql
小码编匠1 小时前
WPF 中的高级交互通过右键拖动实现图像灵活缩放
后端·c#·.net
Java水解1 小时前
【MySQL】从零开始学习MySQL:基础与安装指南
后端·mysql
Java水解1 小时前
Scala深入面向对象:类、对象与伴生关系
后端·scala
LeeGe1 小时前
基于binlog的canal到redis的同步
后端
kfyty7251 小时前
loveqq-bootstrap 和 springcloud-bootstrap 有什么区别
后端·架构
咖啡Beans1 小时前
使用OpenFeign实现微服务间通信
java·spring cloud
RoyLin1 小时前
TypeScript设计模式:桥接模式
前端·后端·typescript