沙钢智慧能源系统后端代码
houzhongjian
2024-10-09 97edd72e5e6dbb134cedae4b72c95be8c948c5ec
提交 | 用户 | 时间
97edd7 1 package com.iailab.module.shasteel.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;
8 import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
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
21             public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
22                 // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案
23                 // Swagger 接口文档
24                 registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据
25                         .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI
26                 // Druid 监控
27                 registry.antMatchers("/druid/**").anonymous();
28                 // Spring Boot Actuator 的安全配置
29                 registry.antMatchers("/actuator").anonymous()
30                         .antMatchers("/actuator/**").anonymous();
31                 // RPC 服务的安全配置
32                 registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
33             }
34
35         };
36     }
37
38 }