mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-22 20:54:25 +08:00
Merge branch 'dev'
This commit is contained in:
commit
97066e8369
9
.github/workflows/mirror.yml
vendored
9
.github/workflows/mirror.yml
vendored
@ -14,12 +14,3 @@ jobs:
|
||||
with:
|
||||
source-repo: "git@github.com:pig-mesh/pig.git"
|
||||
destination-repo: "git@code.gitlink.org.cn:lengleng/pig.git"
|
||||
atomgit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: wearerequired/git-mirror-action@master #同步至 atomgit
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
|
||||
with:
|
||||
source-repo: "git@github.com:pig-mesh/pig.git"
|
||||
destination-repo: "git@atomgit.com:log4j/pig.git"
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -57,3 +57,4 @@ target/
|
||||
Thumbs.db
|
||||
Servers
|
||||
.metadata
|
||||
.flattened-pom.xml
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-auth</artifactId>
|
||||
|
@ -147,14 +147,14 @@ public abstract class OAuth2ResourceOwnerBaseAuthenticationProvider<T extends OA
|
||||
.principal(usernamePasswordAuthentication)
|
||||
.authorizationServerContext(AuthorizationServerContextHolder.getContext())
|
||||
.authorizedScopes(authorizedScopes)
|
||||
.authorizationGrantType(AuthorizationGrantType.PASSWORD)
|
||||
.authorizationGrantType(resouceOwnerBaseAuthentication.getAuthorizationGrantType())
|
||||
.authorizationGrant(resouceOwnerBaseAuthentication);
|
||||
// @formatter:on
|
||||
|
||||
OAuth2Authorization.Builder authorizationBuilder = OAuth2Authorization
|
||||
.withRegisteredClient(registeredClient)
|
||||
.principalName(usernamePasswordAuthentication.getName())
|
||||
.authorizationGrantType(AuthorizationGrantType.PASSWORD)
|
||||
.authorizationGrantType(resouceOwnerBaseAuthentication.getAuthorizationGrantType())
|
||||
// 0.4.0 新增的方法
|
||||
.authorizedScopes(authorizedScopes);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-bom</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>pig-common-bom</name>
|
||||
@ -14,20 +14,18 @@
|
||||
<description>pig cloud parent</description>
|
||||
|
||||
<properties>
|
||||
<pig.common.version>${project.version}</pig.common.version>
|
||||
<revision>3.7.4-JDK8</revision>
|
||||
<spring-boot.version>2.7.18</spring-boot.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<log4j2.version>2.17.1</log4j2.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<git.commit.plugin>4.9.9</git.commit.plugin>
|
||||
<spring.checkstyle.plugin>0.0.39</spring.checkstyle.plugin>
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<knife4j.version>3.0.3</knife4j.version>
|
||||
<springdoc.version>1.6.9</springdoc.version>
|
||||
<swagger.core.version>2.2.0</swagger.core.version>
|
||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||
<dynamic-ds.version>4.2.0</dynamic-ds.version>
|
||||
<dynamic-ds.version>4.3.0</dynamic-ds.version>
|
||||
<mysql.version>8.0.33</mysql.version>
|
||||
<seata.version>1.6.1</seata.version>
|
||||
<excel.version>1.2.6</excel.version>
|
||||
@ -39,6 +37,9 @@
|
||||
<hutool.version>5.8.23</hutool.version>
|
||||
<mica.version>2.7.4</mica.version>
|
||||
<sentinel.version>1.8.4</sentinel.version>
|
||||
<git.commit.plugin>4.9.9</git.commit.plugin>
|
||||
<flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version>
|
||||
<spring.checkstyle.plugin>0.0.39</spring.checkstyle.plugin>
|
||||
</properties>
|
||||
|
||||
<!-- 定义全局jar版本,模块使用需要再次引入但不用写版本号-->
|
||||
@ -47,62 +48,62 @@
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-datasource</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-job</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-log</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-mybatis</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-feign</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-swagger</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-seata</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-xss</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-oss</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
<version>${pig.common.version}</version>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
@ -228,6 +229,32 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 统一 revision 版本 -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${flatten-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--打包jar 与git commit 关联插件-->
|
||||
<plugin>
|
||||
<groupId>io.github.git-commit-id</groupId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
|
@ -47,11 +47,6 @@ public interface SecurityConstants {
|
||||
*/
|
||||
String FROM = "from";
|
||||
|
||||
/**
|
||||
* 请求header
|
||||
*/
|
||||
String HEADER_FROM_IN = FROM + "=" + FROM_IN;
|
||||
|
||||
/**
|
||||
* 默认登录URL
|
||||
*/
|
||||
@ -82,11 +77,6 @@ public interface SecurityConstants {
|
||||
*/
|
||||
String NOOP = "{noop}";
|
||||
|
||||
/***
|
||||
* 资源服务器默认bean名称
|
||||
*/
|
||||
String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter";
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-job</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-log</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-mybatis</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-oss</artifactId>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-seata</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
|
@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-swagger</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-xss</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-gateway</artifactId>
|
||||
|
@ -7,6 +7,7 @@ import com.pig4cloud.pig.gateway.filter.ValidateCodeGatewayFilter;
|
||||
import com.pig4cloud.pig.gateway.handler.GlobalExceptionHandler;
|
||||
import com.pig4cloud.pig.gateway.handler.ImageCodeHandler;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyRequestBodyGatewayFilterFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@ -20,27 +21,56 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
@EnableConfigurationProperties(GatewayConfigProperties.class)
|
||||
public class GatewayConfiguration {
|
||||
|
||||
/**
|
||||
* 创建密码解码器过滤器
|
||||
* @param modifyRequestBodyGatewayFilterFactory 修改请求体网关过滤器工厂
|
||||
* @param configProperties 配置属性
|
||||
* @return 密码解码器过滤器
|
||||
*/
|
||||
@Bean
|
||||
public PasswordDecoderFilter passwordDecoderFilter(GatewayConfigProperties configProperties) {
|
||||
return new PasswordDecoderFilter(configProperties);
|
||||
public PasswordDecoderFilter passwordDecoderFilter(
|
||||
ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory,
|
||||
GatewayConfigProperties configProperties) {
|
||||
return new PasswordDecoderFilter(modifyRequestBodyGatewayFilterFactory, configProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建PigRequest全局过滤器
|
||||
* @return PigRequest全局过滤器
|
||||
*/
|
||||
@Bean
|
||||
public PigRequestGlobalFilter pigRequestGlobalFilter() {
|
||||
return new PigRequestGlobalFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建验证码网关过滤器
|
||||
* @param configProperties 配置属性
|
||||
* @param objectMapper 对象映射器
|
||||
* @param redisTemplate Redis模板
|
||||
* @return 验证码网关过滤器
|
||||
*/
|
||||
@Bean
|
||||
public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties,
|
||||
ObjectMapper objectMapper, RedisTemplate redisTemplate) {
|
||||
return new ValidateCodeGatewayFilter(configProperties, objectMapper, redisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建全局异常处理程序
|
||||
* @param objectMapper 对象映射器
|
||||
* @return 全局异常处理程序
|
||||
*/
|
||||
@Bean
|
||||
public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) {
|
||||
return new GlobalExceptionHandler(objectMapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建图片验证码处理器
|
||||
* @param redisTemplate Redis模板
|
||||
* @return 图片验证码处理器
|
||||
*/
|
||||
@Bean
|
||||
public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) {
|
||||
return new ImageCodeHandler(redisTemplate);
|
||||
|
@ -29,28 +29,14 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
|
||||
import org.springframework.cloud.gateway.support.BodyInserterContext;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyRequestBodyGatewayFilterFactory;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||
import org.springframework.web.reactive.function.BodyInserter;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.HandlerStrategies;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@ -60,107 +46,55 @@ import java.util.function.Function;
|
||||
@RequiredArgsConstructor
|
||||
public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
|
||||
|
||||
private static final List<HttpMessageReader<?>> messageReaders = HandlerStrategies.withDefaults().messageReaders();
|
||||
private final ModifyRequestBodyGatewayFilterFactory modifyRequestBodyFilter;
|
||||
|
||||
private static final String PASSWORD = "password";
|
||||
private static final String PASSWORD = "password";
|
||||
|
||||
private static final String KEY_ALGORITHM = "AES";
|
||||
private static final String KEY_ALGORITHM = "AES";
|
||||
|
||||
private final GatewayConfigProperties gatewayConfig;
|
||||
private final GatewayConfigProperties gatewayConfig;
|
||||
|
||||
static {
|
||||
// 关闭hutool 强制关闭Bouncy Castle库的依赖
|
||||
SecureUtil.disableBouncyCastle();
|
||||
}
|
||||
static {
|
||||
// 关闭hutool 强制关闭Bouncy Castle库的依赖
|
||||
SecureUtil.disableBouncyCastle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
return (exchange, chain) -> {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
// 1. 不是登录请求,直接向下执行
|
||||
if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), SecurityConstants.OAUTH_TOKEN_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
return (exchange, chain) -> {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
// 不是登录请求,直接向下执行
|
||||
if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), SecurityConstants.OAUTH_TOKEN_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
// 2. 不是密码登录模式直接跳过
|
||||
String grantType = request.getQueryParams().getFirst("grant_type");
|
||||
if (!StrUtil.equals(SecurityConstants.PASSWORD, grantType)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
return modifyRequestBodyFilter
|
||||
.apply(new ModifyRequestBodyGatewayFilterFactory.Config().setRewriteFunction(String.class, String.class,
|
||||
(webExchange, body) -> Mono.just(modifyRequestPassword(body))))
|
||||
.filter(exchange, chain);
|
||||
};
|
||||
}
|
||||
|
||||
// 3. 前端加密密文解密逻辑
|
||||
Class inClass = String.class;
|
||||
Class outClass = String.class;
|
||||
ServerRequest serverRequest = ServerRequest.create(exchange, messageReaders);
|
||||
/**
|
||||
* 修改请求报文的密码密文为名为
|
||||
* @param requestBody 请求报文
|
||||
* @return 修改后的报文
|
||||
*/
|
||||
private String modifyRequestPassword(String requestBody) {
|
||||
// 构建前端对应解密AES 因子
|
||||
AES aes = new AES(Mode.CFB, Padding.NoPadding,
|
||||
new SecretKeySpec(gatewayConfig.getEncodeKey().getBytes(), KEY_ALGORITHM),
|
||||
new IvParameterSpec(gatewayConfig.getEncodeKey().getBytes()));
|
||||
|
||||
// 4. 解密生成新的报文
|
||||
Mono<?> modifiedBody = serverRequest.bodyToMono(inClass).flatMap(decryptAES());
|
||||
// 获取请求密码并解密
|
||||
Map<String, String> inParamsMap = HttpUtil.decodeParamMap(requestBody, CharsetUtil.CHARSET_UTF_8);
|
||||
if (inParamsMap.containsKey(PASSWORD)) {
|
||||
String password = aes.decryptStr(inParamsMap.get(PASSWORD));
|
||||
// 返回修改后报文字符
|
||||
inParamsMap.put(PASSWORD, password);
|
||||
}
|
||||
|
||||
BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, outClass);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.putAll(exchange.getRequest().getHeaders());
|
||||
headers.remove(HttpHeaders.CONTENT_LENGTH);
|
||||
|
||||
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
||||
CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers);
|
||||
return bodyInserter.insert(outputMessage, new BodyInserterContext()).then(Mono.defer(() -> {
|
||||
ServerHttpRequest decorator = decorate(exchange, headers, outputMessage);
|
||||
return chain.filter(exchange.mutate().request(decorator).build());
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 原文解密
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Function decryptAES() {
|
||||
return s -> {
|
||||
// 构建前端对应解密AES 因子
|
||||
AES aes = new AES(Mode.CFB, 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);
|
||||
if (inParamsMap.containsKey(PASSWORD)) {
|
||||
String password = aes.decryptStr(inParamsMap.get(PASSWORD));
|
||||
// 返回修改后报文字符
|
||||
inParamsMap.put(PASSWORD, password);
|
||||
} else {
|
||||
log.error("非法请求数据:{}", s);
|
||||
}
|
||||
return Mono.just(HttpUtil.toParams(inParamsMap, Charset.defaultCharset(), true));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 报文转换
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ServerHttpRequestDecorator decorate(ServerWebExchange exchange, HttpHeaders headers,
|
||||
CachedBodyOutputMessage outputMessage) {
|
||||
return new ServerHttpRequestDecorator(exchange.getRequest()) {
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
long contentLength = headers.getContentLength();
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.putAll(super.getHeaders());
|
||||
if (contentLength > 0) {
|
||||
httpHeaders.setContentLength(contentLength);
|
||||
} else {
|
||||
httpHeaders.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
|
||||
}
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<DataBuffer> getBody() {
|
||||
return outputMessage.getBody();
|
||||
}
|
||||
};
|
||||
}
|
||||
return HttpUtil.toParams(inParamsMap, Charset.defaultCharset(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,14 +17,14 @@
|
||||
package com.pig4cloud.pig.gateway.filter;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pig.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.exception.ValidateCodeException;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
import com.pig4cloud.pig.common.core.util.WebUtils;
|
||||
import com.pig4cloud.pig.gateway.config.GatewayConfigProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -32,13 +32,15 @@ import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Validate code gateway filter.
|
||||
@ -56,68 +58,63 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory<Obje
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 应用网关过滤器
|
||||
* @param config 配置对象
|
||||
* @return 网关过滤器
|
||||
*/
|
||||
@Override
|
||||
public GatewayFilter apply(Object config) {
|
||||
|
||||
return (exchange, chain) -> {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
boolean isAuthToken = CharSequenceUtil.containsAnyIgnoreCase(request.getURI().getPath(),
|
||||
SecurityConstants.OAUTH_TOKEN_URL);
|
||||
|
||||
// 不是登录请求,直接向下执行
|
||||
if (!isAuthToken) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
// 刷新token,手机号登录(也可以这里进行校验) 直接向下执行
|
||||
String grantType = request.getQueryParams().getFirst("grant_type");
|
||||
if (StrUtil.equals(SecurityConstants.REFRESH_TOKEN, grantType)) {
|
||||
if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath(), SecurityConstants.OAUTH_TOKEN_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
// 客户端配置跳过,直接向下执行
|
||||
boolean isIgnoreClient = configProperties.getIgnoreClients().contains(WebUtils.getClientId(request));
|
||||
try {
|
||||
// only oauth and the request not in ignore clients need check code.
|
||||
if (!isIgnoreClient) {
|
||||
checkCode(request);
|
||||
if (isIgnoreClient) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
// 构建缓存body,可重复读获取form data
|
||||
return ServerWebExchangeUtils.cacheRequestBody(exchange, (serverHttpRequest) -> {
|
||||
// get cacheRequestBody
|
||||
DataBuffer cachedRequestBody = exchange.getAttribute("cachedRequestBody");
|
||||
CharBuffer charBuffer = StandardCharsets.UTF_8
|
||||
.decode(Objects.requireNonNull(cachedRequestBody).asByteBuffer());
|
||||
Map<String, String> requestBodyMap = HttpUtil.decodeParamMap(charBuffer.toString(),
|
||||
CharsetUtil.CHARSET_UTF_8);
|
||||
// 刷新请求跳过,直接向下执行
|
||||
if (StrUtil.equals(SecurityConstants.REFRESH_TOKEN, requestBodyMap.get("grant_type"))) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
final String errMsg = e.getMessage();
|
||||
return response.writeWith(Mono.create(monoSink -> {
|
||||
try {
|
||||
byte[] bytes = objectMapper.writeValueAsBytes(R.failed(errMsg));
|
||||
DataBuffer dataBuffer = response.bufferFactory().wrap(bytes);
|
||||
// 根据 randomStr 参数判断验证码是否正常
|
||||
String code = requestBodyMap.get("code");
|
||||
String randomStr = requestBodyMap.getOrDefault("randomStr",
|
||||
requestBodyMap.get(SecurityConstants.SMS_PARAMETER_NAME));
|
||||
checkCode(code, randomStr);
|
||||
|
||||
monoSink.success(dataBuffer);
|
||||
}
|
||||
catch (JsonProcessingException jsonProcessingException) {
|
||||
log.error("对象输出异常", jsonProcessingException);
|
||||
monoSink.error(jsonProcessingException);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
return chain.filter(exchange);
|
||||
return chain.filter(exchange.mutate().request(serverHttpRequest).build());
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查验证码,错误扔出 ValidateCodeException GlobalExceptionHandler统一处理
|
||||
* @param code 验证码
|
||||
* @param randomStr 请求参数
|
||||
* @throws ValidateCodeException 验证码异常
|
||||
*/
|
||||
@SneakyThrows
|
||||
private void checkCode(ServerHttpRequest request) {
|
||||
String code = request.getQueryParams().getFirst("code");
|
||||
|
||||
private void checkCode(String code, String randomStr) {
|
||||
if (CharSequenceUtil.isBlank(code)) {
|
||||
throw new ValidateCodeException("验证码不能为空");
|
||||
}
|
||||
|
||||
String randomStr = request.getQueryParams().getFirst("randomStr");
|
||||
if (CharSequenceUtil.isBlank(randomStr)) {
|
||||
randomStr = request.getQueryParams().getFirst(SecurityConstants.SMS_PARAMETER_NAME);
|
||||
}
|
||||
|
||||
String key = CacheConstants.DEFAULT_CODE_KEY + randomStr;
|
||||
|
||||
Object codeObj = redisTemplate.opsForValue().get(key);
|
||||
|
@ -61,7 +61,7 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
|
||||
return response.writeWith(Mono.fromSupplier(() -> {
|
||||
DataBufferFactory bufferFactory = response.bufferFactory();
|
||||
try {
|
||||
log.warn("Error Spring Cloud Gateway : {} {}", exchange.getRequest().getPath(), ex.getMessage());
|
||||
log.debug("Error Spring Cloud Gateway : {} {}", exchange.getRequest().getPath(), ex.getMessage());
|
||||
return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.failed(ex.getMessage())));
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-register</artifactId>
|
||||
|
@ -11,7 +11,10 @@ db:
|
||||
password: ${MYSQL_PWD:root}
|
||||
url:
|
||||
0: jdbc:mysql://${MYSQL_HOST:pig-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pig_config}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
|
||||
pool:
|
||||
config:
|
||||
connectionTimeout: 30000
|
||||
validationTimeout: 10000
|
||||
|
||||
nacos:
|
||||
core:
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms-biz</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms</artifactId>
|
||||
|
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-codegen</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-monitor</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-visual</artifactId>
|
||||
|
31
pom.xml
31
pom.xml
@ -22,11 +22,13 @@
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>3.7.1-JDK8</version>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
<url>https://www.pig4cloud.com</url>
|
||||
|
||||
<properties>
|
||||
<!-- 项目版本号 -->
|
||||
<revision>3.7.4-JDK8</revision>
|
||||
<spring-boot.version>2.7.18</spring-boot.version>
|
||||
<spring-cloud.version>2021.0.8</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||
@ -53,6 +55,7 @@
|
||||
<docker.password>password</docker.password>
|
||||
<git.commit.plugin>4.9.9</git.commit.plugin>
|
||||
<spring.checkstyle.plugin>0.0.39</spring.checkstyle.plugin>
|
||||
<flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<!-- 以下依赖 全局所有的模块都会引入 -->
|
||||
@ -199,6 +202,32 @@
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<!-- 统一 revision 版本 -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${flatten-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--打包jar 与git commit 关联插件-->
|
||||
<plugin>
|
||||
<groupId>io.github.git-commit-id</groupId>
|
||||
|
Loading…
Reference in New Issue
Block a user