mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
perf: Actuator Endpoints 保护
This commit is contained in:
parent
7012b7b8ea
commit
925da99d0b
4
pom.xml
4
pom.xml
@ -155,6 +155,10 @@
|
|||||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||||
<version>3.0.0-M1</version>
|
<version>3.0.0-M1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
|
@ -4,12 +4,16 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -20,21 +24,30 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class NovelApplication {
|
public class NovelApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(NovelApplication.class, args);
|
SpringApplication.run(NovelApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CommandLineRunner commandLineRunner(ApplicationContext context){
|
public CommandLineRunner commandLineRunner(ApplicationContext context) {
|
||||||
return args -> {
|
return args -> {
|
||||||
Map<String, CacheManager> beans = context.getBeansOfType(CacheManager.class);
|
Map<String, CacheManager> beans = context.getBeansOfType(CacheManager.class);
|
||||||
log.info("加载了如下缓存管理器:");
|
log.info("加载了如下缓存管理器:");
|
||||||
beans.forEach((k,v)->{
|
beans.forEach((k, v) -> {
|
||||||
log.info("{}:{}",k,v.getClass().getName());
|
log.info("{}:{}", k, v.getClass().getName());
|
||||||
log.info("缓存:{}",v.getCacheNames());
|
log.info("缓存:{}", v.getCacheNames());
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
http.csrf().disable()
|
||||||
|
.requestMatcher(EndpointRequest.toAnyEndpoint())
|
||||||
|
.authorizeRequests(requests -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
|
||||||
|
http.httpBasic();
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -147,28 +147,44 @@ spring:
|
|||||||
username: novel
|
username: novel
|
||||||
# Spring Boot Admin 服务端认证密码
|
# Spring Boot Admin 服务端认证密码
|
||||||
password: novel
|
password: novel
|
||||||
|
security:
|
||||||
|
user:
|
||||||
|
name: ENDPOINT_ADMIN
|
||||||
|
password: ENDPOINT_ADMIN
|
||||||
|
roles: ENDPOINT_ADMIN
|
||||||
|
|
||||||
|
# Actuator 端点管理
|
||||||
management:
|
management:
|
||||||
|
# 端点公开配置
|
||||||
endpoints:
|
endpoints:
|
||||||
|
# 通过 HTTP 公开的 Web 端点
|
||||||
web:
|
web:
|
||||||
exposure:
|
exposure:
|
||||||
|
# 公开所有的 Web 端点
|
||||||
include: "*"
|
include: "*"
|
||||||
|
|
||||||
|
# 端点启用配置
|
||||||
endpoint:
|
endpoint:
|
||||||
logfile:
|
logfile:
|
||||||
|
# 启用返回日志文件内容的端点
|
||||||
enabled: true
|
enabled: true
|
||||||
|
# 外部日志文件路径
|
||||||
external-file: logs/novel.log
|
external-file: logs/novel.log
|
||||||
|
|
||||||
info:
|
info:
|
||||||
env:
|
env:
|
||||||
|
# 公开所有以 info. 开头的环境属性
|
||||||
enabled: true
|
enabled: true
|
||||||
health:
|
health:
|
||||||
rabbit:
|
rabbit:
|
||||||
|
# 关闭 rabbitmq 的健康检查
|
||||||
enabled: false
|
enabled: false
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
|
# 关闭 elasticsearch 的健康检查
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
spring:
|
spring:
|
||||||
config:
|
config:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user