✨ Introducing new features. #1899 up swagger 3.0 重构 common-swagger 模块
This commit is contained in:
commit
6f4328a31f
20 files changed
+191
-118
No files matched your search
@@ -34,17 +34,44 @@
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!--swagger 依赖-->
|
||||
<!--接口文档-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-oas</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--knife4j是为Java MVC框架集成Swagger生成Api文档的增强-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--webflux 相关包-->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webflux</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--网关 swagger 聚合依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-gateway-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+5
-2
@@ -17,20 +17,23 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.swagger.annotation;
|
||||
|
||||
import com.pig4cloud.pigx.common.swagger.config.GatewaySwaggerAutoConfiguration;
|
||||
import com.pig4cloud.pigx.common.swagger.config.SwaggerAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/21 开启pigx swagger
|
||||
* @date 2020/10/2 开启pigx swagger
|
||||
*/
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ SwaggerAutoConfiguration.class })
|
||||
@EnableSwagger2
|
||||
@Import({ SwaggerAutoConfiguration.class, GatewaySwaggerAutoConfiguration.class })
|
||||
public @interface EnablePigxSwagger2 {
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.pig4cloud.pigx.common.swagger.config;
|
||||
|
||||
import com.pig4cloud.pigx.common.swagger.support.SwaggerResourceHandler;
|
||||
import com.pig4cloud.pigx.common.swagger.support.SwaggerSecurityHandler;
|
||||
import com.pig4cloud.pigx.common.swagger.support.SwaggerUiHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/10/2
|
||||
* <p>
|
||||
* 网关swagger 配置类,仅在webflux 环境生效哦
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
||||
@ComponentScan("com.pig4cloud.pigx.common.swagger.support")
|
||||
public class GatewaySwaggerAutoConfiguration {
|
||||
|
||||
private final SwaggerResourceHandler swaggerResourceHandler;
|
||||
|
||||
private final SwaggerSecurityHandler swaggerSecurityHandler;
|
||||
|
||||
private final SwaggerUiHandler swaggerUiHandler;
|
||||
|
||||
@Bean
|
||||
public WebFluxSwaggerConfiguration fluxSwaggerConfiguration() {
|
||||
return new WebFluxSwaggerConfiguration();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouterFunction swaggerRouterFunction() {
|
||||
return RouterFunctions
|
||||
.route(RequestPredicates.GET("/swagger-resources").and(RequestPredicates.accept(MediaType.ALL)),
|
||||
swaggerResourceHandler)
|
||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
|
||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
|
||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
|
||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
|
||||
}
|
||||
|
||||
}
|
||||
+19
-21
@@ -16,28 +16,27 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.common.swagger.config;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ParameterBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.builders.RequestParameterBuilder;
|
||||
import springfox.documentation.schema.ScalarType;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author lengleng swagger配置 禁用方法1:使用注解@Profile({"dev","test"})
|
||||
@@ -45,7 +44,6 @@ import java.util.List;
|
||||
* havingValue = "true") 然后在测试配置或者开发配置中添加swagger.enable=true即可开启,生产环境不填则默认关闭Swagger.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableAutoConfiguration
|
||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||
public class SwaggerAutoConfiguration {
|
||||
@@ -69,9 +67,6 @@ public class SwaggerAutoConfiguration {
|
||||
if (swaggerProperties.getBasePath().isEmpty()) {
|
||||
swaggerProperties.getBasePath().add(BASE_PATH);
|
||||
}
|
||||
// noinspection unchecked
|
||||
List<Predicate<String>> basePath = new ArrayList();
|
||||
swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
|
||||
|
||||
// exclude-path处理
|
||||
if (swaggerProperties.getExcludePath().isEmpty()) {
|
||||
@@ -81,18 +76,22 @@ public class SwaggerAutoConfiguration {
|
||||
swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));
|
||||
|
||||
// 版本请求头处理
|
||||
ParameterBuilder versionPar = new ParameterBuilder();
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
versionPar.name("VERSION").description("灰度路由版本信息").modelRef(new ModelRef("string")).parameterType("header")
|
||||
.required(false).build();
|
||||
List<RequestParameter> pars = new ArrayList<>();
|
||||
|
||||
RequestParameterBuilder versionPar = new RequestParameterBuilder().description("灰度路由版本信息")
|
||||
.in(ParameterType.HEADER).name("VERSION").required(false)
|
||||
.query(param -> param.model(model -> model.scalarModel(ScalarType.STRING)));
|
||||
|
||||
pars.add(versionPar.build());
|
||||
|
||||
// noinspection Guava
|
||||
return new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
|
||||
.apiInfo(apiInfo(swaggerProperties)).globalOperationParameters(pars).select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
|
||||
.paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath))).build()
|
||||
.securitySchemes(Collections.singletonList(securitySchema()))
|
||||
ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
|
||||
.apiInfo(apiInfo(swaggerProperties)).globalRequestParameters(pars).select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));
|
||||
|
||||
swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));
|
||||
swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));
|
||||
|
||||
return builder.build().securitySchemes(Collections.singletonList(securitySchema()))
|
||||
.securityContexts(Collections.singletonList(securityContext())).pathMapping("/");
|
||||
}
|
||||
|
||||
@@ -101,8 +100,7 @@ public class SwaggerAutoConfiguration {
|
||||
* @return
|
||||
*/
|
||||
private SecurityContext securityContext() {
|
||||
return SecurityContext.builder().securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex(swaggerProperties().getAuthorization().getAuthRegex())).build();
|
||||
return SecurityContext.builder().securityReferences(defaultAuth()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
@@ -53,6 +53,11 @@ public class SwaggerProperties {
|
||||
**/
|
||||
private List<String> excludePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 需要排除的服务
|
||||
*/
|
||||
private List<String> ignoreProviders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 标题
|
||||
**/
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.pig4cloud.pigx.common.swagger.config;
|
||||
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/10/2
|
||||
* <p>
|
||||
* webflux 网关 swagger 资源路径配置
|
||||
*/
|
||||
public class WebFluxSwaggerConfiguration implements WebFluxConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
|
||||
.resourceChain(false);
|
||||
}
|
||||
|
||||
}
|
||||
+7
-6
@@ -15,9 +15,10 @@
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.gateway.config;
|
||||
package com.pig4cloud.pigx.common.swagger.support;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import com.pig4cloud.pigx.common.swagger.config.SwaggerProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinition;
|
||||
import org.springframework.cloud.gateway.route.RouteDefinitionRepository;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
@@ -34,16 +35,16 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* @author Sywd 聚合接口文档注册,和zuul实现类似
|
||||
*/
|
||||
@Component
|
||||
@Primary
|
||||
@AllArgsConstructor
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SwaggerProvider implements SwaggerResourcesProvider {
|
||||
|
||||
private static final String API_URI = "/v2/api-docs";
|
||||
|
||||
private final RouteDefinitionRepository routeDefinitionRepository;
|
||||
|
||||
private final FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
|
||||
private final SwaggerProperties swaggerProperties;
|
||||
|
||||
@Override
|
||||
public List<SwaggerResource> get() {
|
||||
@@ -52,7 +53,7 @@ public class SwaggerProvider implements SwaggerResourcesProvider {
|
||||
return routes.stream()
|
||||
.flatMap(routeDefinition -> routeDefinition.getPredicates().stream()
|
||||
.filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName()))
|
||||
.filter(predicateDefinition -> !filterIgnorePropertiesConfig.getSwaggerProviders()
|
||||
.filter(predicateDefinition -> !swaggerProperties.getIgnoreProviders()
|
||||
.contains(routeDefinition.getId()))
|
||||
.map(predicateDefinition -> swaggerResource(routeDefinition.getId(),
|
||||
predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**",
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.gateway.handler;
|
||||
package com.pig4cloud.pigx.common.swagger.support;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.gateway.handler;
|
||||
package com.pig4cloud.pigx.common.swagger.support;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.gateway.handler;
|
||||
package com.pig4cloud.pigx.common.swagger.support;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
+3
-14
@@ -82,21 +82,10 @@
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!--接口文档-->
|
||||
<!--swagger 依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-swagger</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.pig4cloud.pigx.gateway;
|
||||
|
||||
import com.pig4cloud.pigx.common.gateway.annotation.EnablePigxDynamicRoute;
|
||||
import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
@@ -27,6 +28,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
||||
* @author lengleng
|
||||
* @date 2018年06月21日 网关应用
|
||||
*/
|
||||
@EnablePigxSwagger2
|
||||
@EnablePigxDynamicRoute
|
||||
@SpringCloudApplication
|
||||
public class PigxGatewayApplication {
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.gateway.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/22 网关不校验终端配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConditionalOnExpression("!'${ignore}'.isEmpty()")
|
||||
@ConfigurationProperties(prefix = "ignore")
|
||||
public class FilterIgnorePropertiesConfig {
|
||||
|
||||
private List<String> clients = new ArrayList<>();
|
||||
|
||||
private List<String> swaggerProviders = new ArrayList<>();
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.pig4cloud.pigx.gateway.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/10/2
|
||||
* <p>
|
||||
* 网关通用配置文件
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@RefreshScope
|
||||
@ConfigurationProperties("gateway")
|
||||
public class GatewayConfigProperties {
|
||||
|
||||
/**
|
||||
* 网关解密登录前端密码 秘钥 {@link com.pig4cloud.pigx.gateway.filter.PasswordDecoderFilter}
|
||||
*/
|
||||
public String encodeKey;
|
||||
|
||||
/**
|
||||
* 网关不需要校验验证码的客户端 {@link com.pig4cloud.pigx.gateway.filter.ValidateCodeGatewayFilter}
|
||||
*/
|
||||
public List<String> ignoreClient;
|
||||
|
||||
}
|
||||
+3
-14
@@ -17,7 +17,8 @@
|
||||
|
||||
package com.pig4cloud.pigx.gateway.config;
|
||||
|
||||
import com.pig4cloud.pigx.gateway.handler.*;
|
||||
import com.pig4cloud.pigx.gateway.handler.ImageCodeCheckHandler;
|
||||
import com.pig4cloud.pigx.gateway.handler.ImageCodeCreateHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -40,25 +41,13 @@ public class RouterFunctionConfiguration {
|
||||
|
||||
private final ImageCodeCreateHandler imageCodeCreateHandler;
|
||||
|
||||
private final SwaggerResourceHandler swaggerResourceHandler;
|
||||
|
||||
private final SwaggerSecurityHandler swaggerSecurityHandler;
|
||||
|
||||
private final SwaggerUiHandler swaggerUiHandler;
|
||||
|
||||
@Bean
|
||||
public RouterFunction routerFunction() {
|
||||
return RouterFunctions
|
||||
.route(RequestPredicates.path("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
|
||||
imageCodeCreateHandler)
|
||||
.andRoute(RequestPredicates.POST("/code/check").and(RequestPredicates.accept(MediaType.ALL)),
|
||||
imageCodeCheckHandler)
|
||||
.andRoute(RequestPredicates.GET("/swagger-resources").and(RequestPredicates.accept(MediaType.ALL)),
|
||||
swaggerResourceHandler)
|
||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
|
||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
|
||||
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
|
||||
.and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
|
||||
imageCodeCheckHandler);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -25,8 +25,9 @@ import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.gateway.config.GatewayConfigProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
|
||||
@@ -69,8 +70,8 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
|
||||
|
||||
private static final String KEY_ALGORITHM = "AES";
|
||||
|
||||
@Value("${security.encode.key:1234567812345678}")
|
||||
private String encodeKey;
|
||||
@Autowired
|
||||
private GatewayConfigProperties gatewayConfig;
|
||||
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
@@ -115,8 +116,9 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
|
||||
private Function decryptAES() {
|
||||
return s -> {
|
||||
// 构建前端对应解密AES 因子
|
||||
AES aes = new AES(Mode.CBC, Padding.NoPadding, new SecretKeySpec(encodeKey.getBytes(), KEY_ALGORITHM),
|
||||
new IvParameterSpec(encodeKey.getBytes()));
|
||||
AES aes = new AES(Mode.CBC, Padding.NoPadding,
|
||||
new SecretKeySpec(gatewayConfig.getEncodeKey().getBytes(), KEY_ALGORITHM),
|
||||
new IvParameterSpec(gatewayConfig.getEncodeKey().getBytes()));
|
||||
|
||||
// 获取请求密码并解密
|
||||
Map<String, String> inParamsMap = HttpUtil.decodeParamMap((String) s, CharsetUtil.CHARSET_UTF_8);
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ import com.pig4cloud.pigx.common.core.exception.ValidateCodeException;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import com.pig4cloud.pigx.common.core.util.WebUtils;
|
||||
import com.pig4cloud.pigx.gateway.config.FilterIgnorePropertiesConfig;
|
||||
import com.pig4cloud.pigx.gateway.config.GatewayConfigProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -59,7 +59,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
||||
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
private final FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
|
||||
private final GatewayConfigProperties gatewayConfig;
|
||||
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
@@ -82,7 +82,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
||||
try {
|
||||
String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
|
||||
String clientId = WebUtils.extractClientId(header).orElse(null);
|
||||
if (StrUtil.isNotBlank(clientId) && filterIgnorePropertiesConfig.getClients().contains(clientId)) {
|
||||
if (StrUtil.isNotBlank(clientId) && gatewayConfig.getIgnoreClient().contains(clientId)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -42,7 +42,7 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class ImageCodeCheckHandler implements HandlerFunction<ServerResponse> {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -42,7 +42,7 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class ImageCodeCreateHandler implements HandlerFunction<ServerResponse> {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<spring-boot-admin.version>2.3.0</spring-boot-admin.version>
|
||||
<hutool.version>5.4.3</hutool.version>
|
||||
<captcha.version>1.2.4</captcha.version>
|
||||
<swagger.fox.version>2.9.2</swagger.fox.version>
|
||||
<swagger.fox.version>3.0.0</swagger.fox.version>
|
||||
<knife4j.version>2.0.4</knife4j.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<lcn.version>4.1.0</lcn.version>
|
||||
|
||||
Reference in new issue
Block a user