liriming
2024-12-03 97f3c16ac595493405e8cf76399dc703c088ef6f
提交 | 用户 | 时间
bbc1ee 1 package com.iailab.module.model.framework.security.config;
2
3 import com.iailab.framework.security.config.AuthorizeRequestsCustomizer;
4 import com.iailab.module.system.enums.ApiConstants;
5 import org.springframework.context.annotation.Bean;
6 import org.springframework.context.annotation.Configuration;
7 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
874287 8 import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
bbc1ee 9
10 /**
11  * System 模块的 Security 配置
12  */
13 @Configuration(proxyBeanMethods = false, value = "systemSecurityConfiguration")
14 public class SecurityConfiguration {
15
16     @Bean("systemAuthorizeRequestsCustomizer")
17     public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
18         return new AuthorizeRequestsCustomizer() {
19
20             @Override
874287 21             public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
bbc1ee 22                 // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案
23                 // Swagger 接口文档
874287 24                 registry.requestMatchers("/v3/api-docs/**").permitAll() // 元数据
H 25                         .requestMatchers("/swagger-ui.html").permitAll(); // Swagger UI
bbc1ee 26                 // Druid 监控
874287 27                 registry.requestMatchers("/druid/**").anonymous();
bbc1ee 28                 // Spring Boot Actuator 的安全配置
874287 29                 registry.requestMatchers("/actuator").anonymous()
H 30                         .requestMatchers("/actuator/**").anonymous();
137356 31
874287 32                 registry.requestMatchers("/admin-api/model/pre/item/upload-model").anonymous();
bbc1ee 33                 // RPC 服务的安全配置
874287 34                 registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll();
bbc1ee 35             }
36
37         };
38     }
39
40 }