潘志宝
2024-12-03 0ee7939bb9d8c0d2996d9c9262010423cb786ec6
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.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;
874287 8 import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
e7c126 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
874287 21             public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
e7c126 22                 // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案
H 23                 // Swagger 接口文档
874287 24                 registry.requestMatchers("/v3/api-docs/**").permitAll()
H 25                         .requestMatchers("/webjars/**").permitAll()
26                         .requestMatchers("/swagger-ui").permitAll()
27                         .requestMatchers("/swagger-ui/**").permitAll();
e7c126 28                 // Druid 监控
874287 29                 registry.requestMatchers("/druid/**").permitAll();
e7c126 30                 // Spring Boot Actuator 的安全配置
874287 31                 registry.requestMatchers("/actuator").permitAll()
H 32                         .requestMatchers("/actuator/**").permitAll();
e7c126 33                 // RPC 服务的安全配置
874287 34                 registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll();
e7c126 35             }
H 36
37         };
38     }
39
40 }