欧阳劲驰 il y a 1 mois
Parent
commit
da80a128e9
20 fichiers modifiés avec 431 ajouts et 383 suppressions
  1. 17 1
      custom-gateway-app/src/main/resources/application.yml
  2. 0 9
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/ProjectRouter.java
  3. 64 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/AsyncConfig.java
  4. 0 10
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/AsyncTaskConfig.java
  5. 31 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SchedulingConfig.java
  6. 83 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SecurityConfig.java
  7. 7 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/TempFileConfig.java
  8. 114 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebConfig.java
  9. 0 121
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebMvcConfig.java
  10. 0 74
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebSecurityConfiguration.java
  11. 0 26
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/interfaces/URIInterceptorIntef.java
  12. 0 28
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/interfaces/sinks/LogPrintSink.java
  13. 0 27
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/manager/TraceLogMgr.java
  14. 49 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AsyncProperties.java
  15. 0 59
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AsyncTaskProperties.java
  16. 0 11
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AuthenticationProperties.java
  17. 25 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/SecurityProperties.java
  18. 15 6
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/TempFileProperties.java
  19. 10 0
      custom-gateway-core/src/main/resources/templates/index.html
  20. 16 11
      pom.xml

+ 17 - 1
custom-gateway-app/src/main/resources/application.yml

@@ -7,7 +7,23 @@ server:
   port: 9011
   servlet:
     context-path: /custom-gw/
+#security
+security:
+  permit-pattern:
+    - /common/async-results
+    - /common/temp-files
 #网关
 gateway:
   routes:
-    zydma: /zy-dma/
+    zydma: /zy-dma/
+#异步
+async:
+  result-path-pattern: /common/async-results
+  result-resource-location: ./async-results/
+#临时文件
+temp-file:
+  path-pattern: /common/temp-files
+  resource-location: ./temp-files/
+  cleanup-interval: PT1M
+  max-age: PT4H
+

+ 0 - 9
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/ProjectRouter.java

@@ -1,9 +0,0 @@
-package com.shkpr.service.customgateway.core;
-
-/**
- * 项目路由
- */
-public class ProjectRouter {
-
-
-}

+ 64 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/AsyncConfig.java

@@ -0,0 +1,64 @@
+package com.shkpr.service.customgateway.core.config;
+
+import com.global.base.log.LogLevelFlag;
+import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import com.shkpr.service.customgateway.core.properties.AsyncProperties;
+import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.task.TaskExecutorBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.time.Duration;
+import java.util.concurrent.Executor;
+
+/**
+ * 异步配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableAsync
+@EnableConfigurationProperties(AsyncProperties.class)
+public class AsyncConfig implements AsyncConfigurer {
+    /**
+     * 异步任务多线程处理
+     *
+     * @return 线程任务执行
+     */
+    @Bean(destroyMethod = "shutdown", name = "asyncThreadPoolTaskExecutor")
+    public ThreadPoolTaskExecutor taskExecutor() {
+        TaskExecutorBuilder builder = new TaskExecutorBuilder();
+        builder = builder.queueCapacity(Integer.MAX_VALUE);
+        builder = builder.corePoolSize(8);
+        builder = builder.maxPoolSize(Integer.MAX_VALUE);
+        builder = builder.allowCoreThreadTimeOut(true);
+        builder = builder.keepAlive(Duration.ofSeconds(30));
+        builder = builder.threadNamePrefix("AsyncTask-");
+        return builder.build();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Executor getAsyncExecutor() {
+        return taskExecutor();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
+        return (ex, method, params) ->
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, LogFlagBusiType.BUSI_INIT.toStrValue(),
+                        this.getClass().getSimpleName(),
+                        String.format("AsyncUncaughtException(method=" + method.getName() + ", msg=" + ex.getMessage() + ")..."));
+    }
+}

+ 0 - 10
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/AsyncTaskConfig.java

@@ -1,10 +0,0 @@
-package com.shkpr.service.customgateway.core.config;
-
-import com.shkpr.service.customgateway.core.properties.AsyncTaskProperties;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@EnableConfigurationProperties(AsyncTaskProperties.class)
-public class AsyncTaskConfig {
-}

+ 31 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SchedulingConfig.java

@@ -0,0 +1,31 @@
+package com.shkpr.service.customgateway.core.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+
+/**
+ * 计划任务配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableScheduling
+@Slf4j
+public class SchedulingConfig {
+    /**
+     * 定时任务多线程调度
+     */
+    @Bean(destroyMethod = "shutdown", name = "timeThreadPoolTaskScheduler")
+    public ThreadPoolTaskScheduler taskScheduler() {
+        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
+        scheduler.setPoolSize(2);
+        scheduler.setThreadNamePrefix("TimeTask-");
+        scheduler.setAwaitTerminationSeconds(5);
+        scheduler.setWaitForTasksToCompleteOnShutdown(true);
+        return scheduler;
+    }
+}

+ 83 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/SecurityConfig.java

@@ -0,0 +1,83 @@
+package com.shkpr.service.customgateway.core.config;
+
+import com.shkpr.service.customgateway.core.properties.SecurityProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+
+/**
+ * 安全配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableWebSecurity
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+@EnableConfigurationProperties(SecurityProperties.class)
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
+    private final SecurityProperties properties;
+
+    public SecurityConfig(SecurityProperties properties) {
+        this.properties = properties;
+    }
+
+    /**
+     * http安全配置
+     * {@inheritDoc}
+     */
+    @Override
+    protected void configure(HttpSecurity http) throws Exception {
+        //权限
+        http.authorizeRequests()
+                .antMatchers(properties.getPermitPattern().toArray(new String[0]))
+                .permitAll()
+                .anyRequest()
+                .authenticated()
+                .and()
+                // 过滤器
+//                .addFilterBefore(new ApiJWTBizFilterMgr(ApiURI.URI_ALL_BUSI_XXX, authenticationManager()),
+//                        UsernamePasswordAuthenticationFilter.class)
+                //跨域防伪
+                .csrf().disable()
+                //frame
+                .headers().frameOptions().disable()
+                .and()
+                // 添加过滤器
+                //session
+                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
+                .and()
+                //登陆
+                .formLogin().disable()
+                //登出
+                .logout().disable()
+        //异常处理
+//                .exceptionHandling()
+//                .accessDeniedHandler((request, response, accessDeniedException) ->
+////                        ResponseUtil.writeJson(response, new Result<>(HttpStatus.FORBIDDEN.value(), accessDeniedException.getMessage()))
+//                        {
+//                        }
+//                )
+//                .authenticationEntryPoint((request, response, authenticationException) ->
+//                        ResponseUtil.writeJson(response, new Result<>(HttpStatus.UNAUTHORIZED.value(), authenticationException.getMessage()))
+//                        {
+//                        }
+//                )
+        ;
+
+    }
+
+    /**
+     * web安全配置
+     * {@inheritDoc}
+     */
+    @Override
+    public void configure(WebSecurity web) {
+
+    }
+}

+ 7 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/TempFileConfig.java

@@ -4,7 +4,14 @@ import com.shkpr.service.customgateway.core.properties.TempFileProperties;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
+/**
+ * 临时文件配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
 @Configuration
 @EnableConfigurationProperties(TempFileProperties.class)
 public class TempFileConfig {
+
 }

+ 114 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebConfig.java

@@ -0,0 +1,114 @@
+package com.shkpr.service.customgateway.core.config;
+
+import com.shkpr.service.customgateway.core.properties.AsyncProperties;
+import com.shkpr.service.customgateway.core.properties.TempFileProperties;
+import lombok.NonNull;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * WebMvc配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableWebMvc
+public class WebConfig implements WebMvcConfigurer {
+    final
+    TempFileProperties tempFileProperties;
+    final
+    AsyncProperties asyncProperties;
+
+    public WebConfig(TempFileProperties tempFileProperties, AsyncProperties asyncProperties) {
+        this.tempFileProperties = tempFileProperties;
+        this.asyncProperties = asyncProperties;
+    }
+
+    /**
+     * 视图<br>
+     * {@inheritDoc}
+     */
+    @Override
+    public void addViewControllers(@NonNull ViewControllerRegistry registry) {
+        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
+        registry.addViewController("/").setViewName("index");
+    }
+
+    /**
+     * 静态资源<br>
+     * {@inheritDoc}
+     */
+    @Override
+    public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
+        //临时文件映射
+        registry.addResourceHandler(tempFileProperties.getPathPattern())
+                .addResourceLocations("file:" + tempFileProperties.getResourceLocation() + "/");
+        //异步结果映射
+        registry.addResourceHandler(asyncProperties.getResultPathPattern())
+                .addResourceLocations("file:" + asyncProperties.getResultResourceLocation() + "/");
+    }
+
+    /**
+     * 跨域<br>
+     * {@inheritDoc}
+     */
+    @Override
+    public void addCorsMappings(@NonNull CorsRegistry registry) {
+        //路径
+        registry.addMapping("/**")
+                //方法
+                .allowedMethods("GET", "POST")
+                //同源
+                .allowedOrigins("*")
+                //header
+                .allowedHeaders("x-requested-with", "Content-Type", "Authorization", "user-agent", "Timestamp", "Sequence", "Signature");
+    }
+
+    /**
+     * 拦截器<br>
+     * {@inheritDoc}
+     */
+    @Override
+    public void addInterceptors(@NonNull InterceptorRegistry registry) {
+
+    }
+
+    /**
+     * 消息转换器<br>
+     * {@inheritDoc}
+     */
+    @Override
+    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+        //类型集合
+        List<MediaType> mediaTypes = new ArrayList<>();
+        //json
+        mediaTypes.add(MediaType.APPLICATION_JSON);
+        //htm
+        mediaTypes.add(MediaType.TEXT_HTML);
+        //pdf
+        mediaTypes.add(MediaType.APPLICATION_PDF);
+        //zip
+        mediaTypes.add(MediaType.parseMediaType("application/zip"));
+        //xlsx
+        mediaTypes.add(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
+        //创建json转换器
+        MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
+        jackson2HttpMessageConverter.setSupportedMediaTypes(mediaTypes);
+        //创建string转换器
+        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
+        stringHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_PLAIN));
+        //填入转换器
+        converters.add(jackson2HttpMessageConverter);
+        converters.add(stringHttpMessageConverter);
+    }
+}

+ 0 - 121
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebMvcConfig.java

@@ -1,121 +0,0 @@
-package com.shkpr.service.customgateway.core.config;
-
-import com.shkpr.service.customgateway.core.utils.SpringContextUtil;
-import com.shkpr.service.customgateway.core.properties.AsyncTaskProperties;
-import com.shkpr.service.customgateway.core.properties.TempFileProperties;
-import com.shkpr.service.customgateway.core.constants.ApiURI;
-import com.shkpr.service.customgateway.core.interfaces.URIInterceptorIntef;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.Ordered;
-import org.springframework.http.HttpMethod;
-import org.springframework.util.StringUtils;
-import org.springframework.web.cors.CorsConfiguration;
-import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
-import org.springframework.web.filter.CorsFilter;
-import org.springframework.web.servlet.config.annotation.*;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * 该类主要用来注册各种Controller拦截器
- * WebSecurityConfig类中注册的过滤器JWTLoginFilter、JWTAuthenticationFilter优先于该类中注册的拦截器URIInterceptorIntef
- * 过滤拦截顺序: JWTLoginFilter--->JWTAuthenticationFilter--->URIInterceptorIntef
- */
-@Configuration
-@EnableWebMvc
-public class WebMvcConfig implements WebMvcConfigurer {
-    private  TempFileProperties tempFileProperties;
-    private  AsyncTaskProperties asyncTaskProperties;
-
-    public WebMvcConfig(TempFileProperties tempFileProperties , AsyncTaskProperties asyncTaskProperties) {
-        this.tempFileProperties = tempFileProperties;
-        this.asyncTaskProperties = asyncTaskProperties;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void addResourceHandlers(ResourceHandlerRegistry registry) {
-        //临时文件映射
-        registry.addResourceHandler(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_TEMP_FILES + "/**")
-                .addResourceLocations("file:" + tempFileProperties.getResourcePath() + "/");
-        //异步结果映射
-        registry.addResourceHandler(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_ASYNC_RESULTS + "/**")
-                .addResourceLocations("file:" + asyncTaskProperties.getResultPath() + "/");
-    }
-
-    @Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        @SuppressWarnings("static-access")
-        Map<String, URIInterceptorIntef> mapURLInterceptorByOrder = new TreeMap<String, URIInterceptorIntef>(); //TreeMap默认按键值升序
-        Map<String, URIInterceptorIntef> mapURLInterceptor = SpringContextUtil.getApplicationContext().getBeansOfType(URIInterceptorIntef.class);  //获取URIInterceptorIntef类型的所有Component组件
-        if (!StringUtils.isEmpty(mapURLInterceptor)){
-            Iterator it = mapURLInterceptor.entrySet().iterator();
-            while (it.hasNext()){
-                Map.Entry entry = (Map.Entry)it.next();
-                URIInterceptorIntef urlInterceptor = (URIInterceptorIntef)entry.getValue();
-                if (urlInterceptor != null){
-                    mapURLInterceptorByOrder.put(String.valueOf(urlInterceptor.order()), urlInterceptor);
-                }
-            }
-        }
-
-        if (!StringUtils.isEmpty(mapURLInterceptorByOrder)){
-            Iterator it = mapURLInterceptorByOrder.entrySet().iterator();
-            while (it.hasNext()){
-                Map.Entry entry = (Map.Entry)it.next();
-                //System.out.println("WebMvcConfig::addInterceptors() key="+(String) entry.getKey());
-                URIInterceptorIntef urlInterceptor = (URIInterceptorIntef)entry.getValue();
-                if (urlInterceptor != null){
-                    String[] arrForbidUrls = urlInterceptor.forbidPathPatterns();
-                    if (arrForbidUrls == null)
-                        arrForbidUrls = new String[]{};
-                    String[] arrExcludeUrls = urlInterceptor.excludePathPatterns();
-                    if (arrExcludeUrls == null){
-                        //多个拦截器将按照链接的顺序依次匹配拦截(注:有可能多个拦截器都匹配成功,则多个拦截器依次执行)
-                        registry.addInterceptor(urlInterceptor).addPathPatterns(arrForbidUrls);
-                    }else{
-                        registry.addInterceptor(urlInterceptor).addPathPatterns(arrForbidUrls).excludePathPatterns(arrExcludeUrls);
-                    }
-                }
-            }
-        }
-        //super.addInterceptors(registry);
-    }
-
-    //解决跨域问题
-    private CorsConfiguration buildConfig() {
-        CorsConfiguration corsConfiguration = new CorsConfiguration();
-        corsConfiguration.addAllowedOrigin("*");
-        //corsConfiguration.addAllowedMethod("*");
-        corsConfiguration.addAllowedMethod(HttpMethod.POST);
-        corsConfiguration.addAllowedMethod(HttpMethod.GET);
-        corsConfiguration.addAllowedMethod(HttpMethod.PUT);
-        corsConfiguration.addAllowedMethod(HttpMethod.DELETE);
-        corsConfiguration.addAllowedMethod(HttpMethod.OPTIONS);
-        corsConfiguration.addAllowedMethod(HttpMethod.HEAD);
-        corsConfiguration.addAllowedHeader("x-requested-with,Content-Type,Authorization,user-agent,Timestamp,Sequence,Signature");
-        return corsConfiguration;
-    }
-
-    //解决跨域问题
-    @Bean
-    public CorsFilter corsFilter() {
-        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
-        source.registerCorsConfiguration("/**", buildConfig());
-        return new CorsFilter(source);
-    }
-
-    //配置该服务的默认首页用于阿里云服务SLB的http head健康检查
-    @Override
-    public void addViewControllers(ViewControllerRegistry registry) {
-        registry.addViewController("/").setViewName("index");
-        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
-        //super.addViewControllers(registry);
-    }
-
-}

+ 0 - 74
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/WebSecurityConfiguration.java

@@ -1,74 +0,0 @@
-package com.shkpr.service.customgateway.core.config;
-
-import com.shkpr.service.customgateway.core.constants.ApiURI;
-import com.shkpr.service.customgateway.core.filter.ApiJWTBizFilterMgr;
-import com.shkpr.service.customgateway.core.filter.CustomAuthenticationProvider;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
-
-/**
- * 该类主要用来做权限控制的配置、以及注册各种过滤器
- * 执行顺序
- * (1) 注册验证组件 - configure(AuthenticationManagerBuilder auth)方法中注册自定义验证组件
- * (2) 设置验证规则 - configure(HttpSecurity http)方法中设置了各种路由访问规则
- * (3) 初始化过滤组件 - JWTLoginFilter 和 JWTAuthenticationFilter 类会初始化
- */
-@Configuration
-@EnableWebSecurity
-@EnableGlobalMethodSecurity(prePostEnabled = true)                     //@PreAuthorize对权限的注解需要设置prePostEnabled = true
-public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
-    @Value("${global.test.pressure:false}")
-    private boolean mBForPressureTest;
-
-    @Value("${global.ops.lan.ip:127.0.0.1}")
-    private String mStrOpsServerLanIP;
-
-    @Override
-    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
-        //使用自定义身份验证组件
-        auth.authenticationProvider(new CustomAuthenticationProvider());
-    }
-
-    // 设置 HTTP 验证规则
-    @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        String[] arrOpsServerLanIPs = mStrOpsServerLanIP.split(";");
-        String strAccessFilterForOps = "hasIpAddress('127.0.0.1')";
-        for (String strTmp : arrOpsServerLanIPs) {
-            strAccessFilterForOps += " or hasIpAddress('" + strTmp + "')";
-        }
-
-        http.csrf().disable()                                          // 关闭csrf验证
-                .authorizeRequests()                                   // 对请求进行认证
-                .antMatchers(ApiURI.URI_ACCESS_TOKEN_CHECK).permitAll()
-                .antMatchers(ApiURI.URI_FILE_BUSI_XXX).permitAll()
-                .antMatchers("/").permitAll()
-                //系统检查结果放行
-                .antMatchers(ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_SYS_CHECK_RESULTS + "/**").permitAll()
-                .anyRequest().permitAll()                                                                                          //所有其他请求需要身份认证
-                .and()
-                .addFilterBefore(new ApiJWTBizFilterMgr(ApiURI.URI_ALL_BUSI_XXX, authenticationManager()),
-                        UsernamePasswordAuthenticationFilter.class)
-                //禁用frame
-                .headers().frameOptions().disable();
-                /*.addFilterBefore(new ServerStatusMonitorFilter(ThirdApiURI.URI_HGAS_MONITOR_XXX, authenticationManager()),
-                        UsernamePasswordAuthenticationFilter.class);*/
-
-    }
-
-    @Override
-    public void configure(WebSecurity web) throws Exception {
-        /*web.ignoring()
-                .antMatchers("/error")
-                .antMatchers("/static")
-                .antMatchers("/static/**");                                                               // 所有/static下的静态资源请求时都忽略访问规则
-        */
-    }
-}

+ 0 - 26
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/interfaces/URIInterceptorIntef.java

@@ -1,26 +0,0 @@
-package com.shkpr.service.customgateway.core.interfaces;
-
-import org.springframework.web.servlet.HandlerInterceptor;
-
-/**
- * URL拦截器接口,实现该接口并在实现类上添加注解@Component,将会自动注入spring拦截器
- */
-public interface URIInterceptorIntef extends HandlerInterceptor {
-    /**
-     * 需拦截的地址
-     * @return
-     */
-    public String [] forbidPathPatterns();
-
-    /**
-     * 排除拦截的地址
-     * @return
-     */
-    public String [] excludePathPatterns();
-
-    /**
-     * 值越小优先级越高,值越大优先级越低;优先级越高越先得到执行
-     * @return
-     */
-    public int order();
-}

+ 0 - 28
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/interfaces/sinks/LogPrintSink.java

@@ -1,28 +0,0 @@
-package com.shkpr.service.customgateway.core.interfaces.sinks;
-
-import com.global.base.log.ILogPrintSink;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LogPrintSink implements ILogPrintSink {
-    private final Logger mLogger = LoggerFactory.getLogger(this.getClass());
-    public LogPrintSink() {
-    }
-
-    @Override
-    public void printLogMsg(int nLevel, String strMsg) {
-        switch (nLevel){
-            case 0:{
-                mLogger.info(strMsg);
-            }break;
-            case 1:{
-                mLogger.warn(strMsg);
-            }break;
-            case 2:{
-                mLogger.error(strMsg);
-            }break;
-            default:
-                break;
-        }
-    }
-}

+ 0 - 27
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/manager/TraceLogMgr.java

@@ -1,27 +0,0 @@
-package com.shkpr.service.customgateway.core.manager;
-
-import com.global.base.tools.TraceIdUtil;
-import com.shkpr.service.customgateway.core.storage.GlobalData;
-
-public class TraceLogMgr {
-    public static void setTraceId(String traceId){
-        if (GlobalData.getInstance().isSwitchTraceLog())
-            TraceIdUtil.setTraceId(traceId);
-    }
-    public static void setTraceIdByBusinessType(String strBusinessType){
-        if (GlobalData.getInstance().isSwitchTraceLog())
-            TraceIdUtil.setTraceIdByBusinessType(strBusinessType);
-    }
-
-    public static String getTraceId(){
-        if (GlobalData.getInstance().isSwitchTraceLog())
-            return TraceIdUtil.getTraceId();
-        return "TID-0";
-    }
-
-    public static String removeTraceId(){
-        if (GlobalData.getInstance().isSwitchTraceLog())
-            return TraceIdUtil.removeTraceId();
-        return "TID-0";
-    }
-}

+ 49 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AsyncProperties.java

@@ -0,0 +1,49 @@
+package com.shkpr.service.customgateway.core.properties;
+
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import java.nio.file.Path;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 异步任务属性
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Getter
+@Setter
+@ConfigurationProperties(prefix = "async")
+public class AsyncProperties {
+    /**
+     * 结果路径匹配
+     */
+    @NonNull
+    private String resultPathPattern;
+    /**
+     * 结果本地资源
+     */
+    @NonNull
+    private Path resultResourceLocation;
+    /**
+     * 任务超时时间
+     * <p>key: 任务类型</p>
+     * <p>value: 超时时长</p>
+     */
+    private Map<String, Duration> timeouts = new HashMap<>();
+    /**
+     * 结果落后数据库时间
+     * <p>key: 任务类型</p>
+     * <p>value: 落后时间时长</p>
+     *
+     * <p>表示任务结果落后于数据库最新数据的最大容忍时间。
+     * 如果结果未超过此落后时间,则使用本地缓存结果;
+     * 如果结果超过此落后时间,则重新执行任务获取最新结果。</p>
+     */
+    private Map<String, Duration> maxTolerableLag = new HashMap<>();
+}

+ 0 - 59
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AsyncTaskProperties.java

@@ -1,59 +0,0 @@
-package com.shkpr.service.customgateway.core.properties;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-import java.nio.file.Path;
-import java.time.Duration;
-
-/**
- * 异步任务属性
- *
- * @author 欧阳劲驰
- * @since 1.0.0
- */
-@Getter
-@Setter
-@ConfigurationProperties(prefix = "async-task")
-public class AsyncTaskProperties {
-    /**
-     * 系统检查超时时间
-     */
-    private Duration systemCheckTimeout;
-
-    /**
-     * 系统检查结果落后时间
-     */
-    private Duration systemCheckResultLag;
-
-    /**
-     * 第三方导入超时时间
-     */
-    private Duration thirdImportTimeout;
-
-    /**
-     * 第三方导入超时时间
-     */
-    private Duration commitImportTimeout;
-
-    /**
-     * 第三方导出超时时间
-     */
-    private Duration thirdExportTimeout;
-
-    /**
-     * 第三方导出结果落后时间
-     */
-    private Duration thirdExportResultLag;
-
-    /**
-     * cad转换超时时间
-     */
-    private Duration cadConvertTimeout;
-
-    /**
-     * 结果路径
-     */
-    private Path resultPath;
-}

+ 0 - 11
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/AuthenticationProperties.java

@@ -1,11 +0,0 @@
-package com.shkpr.service.customgateway.core.properties;
-
-
-/**
- * 认证属性
- *
- * @author 欧阳劲驰
- * @since 1.0.0
- */
-public class AuthenticationProperties {
-}

+ 25 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/SecurityProperties.java

@@ -0,0 +1,25 @@
+package com.shkpr.service.customgateway.core.properties;
+
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 认证属性
+ *
+ * @author 欧阳劲驰
+ * @since 0.0.1-dev
+ */
+@Getter
+@Setter
+@ConfigurationProperties(prefix = "security")
+public class SecurityProperties {
+    /**
+     * 放行的请求,ant格式
+     */
+    private List<String> permitPattern = Collections.emptyList();
+}

+ 15 - 6
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/TempFileProperties.java

@@ -1,6 +1,7 @@
 package com.shkpr.service.customgateway.core.properties;
 
 import lombok.Getter;
+import lombok.NonNull;
 import lombok.Setter;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
@@ -18,15 +19,23 @@ import java.time.Duration;
 @ConfigurationProperties(prefix = "temp-file")
 public class TempFileProperties {
     /**
-     * 检查周期
+     * 路径匹配
      */
-    private Duration checkCycle;
+    @NonNull
+    private String pathPattern;
     /**
-     * 资源路径
+     * 本地资源
      */
-    private Path resourcePath;
+    @NonNull
+    private Path resourceLocation;
     /**
-     * 文件生命周期
+     * 清理周期
      */
-    private Duration lifecycle;
+    @NonNull
+    private Duration cleanupInterval;
+    /**
+     * 文件存活时间
+     */
+    @NonNull
+    private Duration maxAge;
 }

+ 10 - 0
custom-gateway-core/src/main/resources/templates/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8" />
+    <title>Title</title>
+</head>
+<body>
+<h2>This is home page!</h2>
+</body>
+</html>

+ 16 - 11
pom.xml

@@ -52,6 +52,11 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <!--spring-thymeleaf-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
+        </dependency>
         <!--spring-test-->
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -69,17 +74,17 @@
         </dependency>
     </dependencies>
 
-<!--    &lt;!&ndash;仓库&ndash;&gt;-->
-<!--    <repositories>-->
-<!--        &lt;!&ndash;阿里中央&ndash;&gt;-->
-<!--        <repository>-->
-<!--            <id>central</id>-->
-<!--            <url>https://maven.aliyun.com/repository/central</url>-->
-<!--            <releases>-->
-<!--                <enabled>true</enabled>-->
-<!--            </releases>-->
-<!--        </repository>-->
-<!--    </repositories>-->
+    <!--仓库-->
+    <repositories>
+        <!--阿里中央-->
+        <repository>
+            <id>central</id>
+            <url>https://maven.aliyun.com/repository/central</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+        </repository>
+    </repositories>
 
     <!--依赖控制-->
     <dependencyManagement>