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

相关推荐
geovindu9 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
码事漫谈9 小时前
黄仁勋的来时路
后端
Joy T9 小时前
Spring Security 从 Acegi 到 AI Agent——JWT、角色鉴权与异步任务安全实战
人工智能·安全·spring·spring security·json web token·securitycontext·多次鉴权
IT空门:门主9 小时前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线
java·学习
bai2739 小时前
path.join('C:\a', '\b') 给我 C:\a\b,path.resolve 给 C:\b:Windows 上 51 行路径实测
javascript·后端
hackhase9 小时前
Django 多表数据整合:7 张异构表如何收敛成 4 类页面
后端·mysql
用户37215742613511 小时前
Java 批量操作 Excel 超链接:添加、读取、修改和删除
java
 梦晓天明11 小时前
1.Spring学习笔记_IOC入门案例
笔记·学习·spring
Cosolar12 小时前
需求做完了,经验归零了:Agent 真正缺的是第二条闭环
人工智能·后端·agent
用户37215742613512 小时前
Java 将 Excel 图表导出为图片:指定图表、批量导出与图表工作表
java