选煤厂生产管理平台后台代码
houzhongjian
2024-12-03 c3a5919948da2ff07c9b8f206b09ae2f8b59b189
提交 | 用户 | 时间
f968b4 1 package com.iailab.module.pms.framework.security.config;
H 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;
c3a591 8 import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
f968b4 9
H 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
c3a591 21             public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
f968b4 22                 // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案
H 23                 // Swagger 接口文档
c3a591 24                 registry.requestMatchers("/v3/api-docs/**").permitAll() // 元数据
H 25                         .requestMatchers("/swagger-ui.html").permitAll(); // Swagger UI
f968b4 26                 // Druid 监控
c3a591 27                 registry.requestMatchers("/druid/**").anonymous();
f968b4 28                 // Spring Boot Actuator 的安全配置
c3a591 29                 registry.requestMatchers("/actuator").anonymous()
H 30                         .requestMatchers("/actuator/**").anonymous();
f968b4 31                 // RPC 服务的安全配置
c3a591 32                 registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll();
f968b4 33             }
H 34
35         };
36     }
37 }