houzhongjian
2024-08-08 08e3e8f80a1c524176084f4b71c0152981302765
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.framework.security.config;
H 2
3 import com.iailab.framework.security.config.AuthorizeRequestsCustomizer;
4 import com.iailab.module.infra.enums.ApiConstants;
5 import org.springframework.beans.factory.annotation.Value;
6 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration;
8 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9 import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
10
11 /**
12  * Infra 模块的 Security 配置
13  */
14 @Configuration(proxyBeanMethods = false, value = "infraSecurityConfiguration")
15 public class SecurityConfiguration {
16
17     @Value("${spring.boot.admin.context-path:''}")
18     private String adminSeverContextPath;
19
20     @Bean("infraAuthorizeRequestsCustomizer")
21     public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
22         return new AuthorizeRequestsCustomizer() {
23
24             @Override
25             public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
26                 // Swagger 接口文档
d9f9ba 27                 registry.antMatchers("/v3/api-docs/**").permitAll()
H 28                         .antMatchers("/webjars/**").permitAll()
29                         .antMatchers("/swagger-ui").permitAll()
30                         .antMatchers("/swagger-ui/**").permitAll();
e7c126 31                 // Spring Boot Actuator 的安全配置
H 32                 registry.antMatchers("/actuator").anonymous()
33                         .antMatchers("/actuator/**").anonymous();
34                 // Druid 监控
35                 registry.antMatchers("/druid/**").anonymous();
36                 // Spring Boot Admin Server 的安全配置
37                 registry.antMatchers(adminSeverContextPath).anonymous()
38                         .antMatchers(adminSeverContextPath + "/**").anonymous();
39                 // 文件读取
40                 registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll();
41
42                 // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案
43                 // RPC 服务的安全配置
44                 registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
45             }
46
47         };
48     }
49
50 }