当前位置: 首页 > news >正文

spring boot actuator 安全配置 springboot的安全性

关于springboot Actuator框架的安全配置方案:

加入security安全验证框架

方案一:

配置信息:

spring:security:user:password: adminname: adminmanagement:endpoints:web:base-path: /monitorexposure:include: "*"# 排除端点exclude: shutdownserver:port: 9595endpoint:health:show-details: alwaysshutdown:enabled: true

引入依赖信息

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>

需要上下午url对进行处理;

处理方法一:只针对端点请求进行权限校验

@Configuration
@EnableWebSecurity
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {@AutowiredEnvironment env;@Overrideprotected void configure(HttpSecurity security) throws Exception {String contextPath = env.getProperty("management.endpoints.web.base-path");if(StringUtils.isEmpty(contextPath)) {contextPath = "";}security.csrf().disable().headers().frameOptions().disable();security.cors().and().antMatcher("/**"+contextPath+"/**").authorizeRequests().anyRequest().authenticated().and().httpBasic();}
}

以下处理跨域请求

@Configuration
public class WebConfig implements WebMvcConfigurer {/*** 允许跨域请求** @param registry*/@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS").allowCredentials(true).maxAge(3600).allowedHeaders("*");}@BeanCorsConfigurationSource corsConfigurationSource() {CorsConfiguration configuration = new CorsConfiguration();configuration.setAllowedOrigins(Arrays.asList("*"));configuration.setAllowedMethods(Arrays.asList("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"));UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", configuration);return source;}
}

方案二:定制端点信息

**启用端点:**默认情况下,启用除shutdown 之外的所有端点。要配置端点的启用,请使用其management.endpoint…enabled 属性。以下示例启用shutdown 端点:

management.endpoint.shutdown.enabled=true
management.endpoint.env.enabled=false

如果您希望端点启用是选择加入而不是选择退出,请将management.endpoints.enabled-by-default 属性设置为false 并使用单个端点enabled 属性重新加入。以下示例启用info endpoint并禁用所有其他端点:

management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true
http://www.lryc.cn/news/327420.html

相关文章:

  • macOS Sonoma如何查看隐藏文件
  • 深入浅出:语言模型的原理、实战与评估
  • 基于ssm的线上旅行信息管理系统论文
  • Jupyter开启远程服务器(最新版)
  • 【SpringCloud微服务实战10】DevOps自动化部署微服务项目(Jenkins+Docker+K8s)
  • DSVPN实验报告
  • Linux:Jenkins:参数化版本回滚(6)
  • Haproxy2.8.1+Lua5.1.4部署,haproxy.cfg配置文件详解和演示
  • GenICam-GenApi简介
  • 如何创建纯净版Django项目并启动?——让Django更加简洁
  • 蓝桥杯 2022 省A 选数异或
  • 计数器选型参数,结构原理,工艺与注意问题总结
  • Android 性能优化实例分享-内存优化 兼顾效率与性能
  • IT服务监督管理案例分析题
  • 【spring】AbstractApplicationContext 的refresh() 方法学习
  • 零基础10 天入门 Web3之第1天
  • 【1】网络协议基础概念
  • flutter 中 GetxController 和 GetxService 的区别和使用场景
  • Python+Django+Yolov5路面墙体桥梁裂缝特征检测识别html网页前后端
  • uniApp使用XR-Frame创建3D场景(7)加入点击交互
  • 单元测试11213123231313131231231231
  • libVLC 捕获鼠标、键盘事件
  • 京东云0基础搭建帕鲁服务器_4核16G和8核32G幻兽帕鲁专用服务器
  • OpenCV 如何使用 XML 和 YAML 文件的文件输入和输出
  • playbook的介绍、应用与实施
  • uniApp使用XR-Frame创建3D场景(5)材质贴图的运用
  • 阿里云CentOS7安装Hadoop3伪分布式
  • 78.子集90.子集2
  • 基于Ubuntu的Linux系统安装jsoncpp开发包过程
  • 葵花卫星影像应用场景及数据获取