Skip to content
Merged

Dev #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# zlt-microservices-platform

<p align="center">
<img src="https://img.shields.io/badge/Version-5.2.0-critical" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Boot-2.5.7-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud-2020.0.4-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Version-5.3.0-critical" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Boot-2.5.13-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud-2020.0.5-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud%20Alibaba-2021.1-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Elasticsearch-7.x-brightgreen" alt="Downloads"/>
<a target="_blank" href='https://gitee.com/zlt2000/microservices-platform'>
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.zlt</groupId>
<artifactId>central-platform</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
<packaging>pom</packaging>

<properties>
Expand All @@ -14,8 +14,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>
<spring-cloud-alibaba-dependencies.version>2021.1</spring-cloud-alibaba-dependencies.version>
<spring-boot-dependencies.version>2.5.9</spring-boot-dependencies.version>
<spring-cloud-dependencies.version>2020.0.4</spring-cloud-dependencies.version>
<spring-boot-dependencies.version>2.5.13</spring-boot-dependencies.version>
<spring-cloud-dependencies.version>2020.0.5</spring-cloud-dependencies.version>
<commons-collections4.version>4.4</commons-collections4.version>
<swagger.butler.version>2.0.1</swagger.butler.version>
<jjwt.version>0.9.1</jjwt.version>
Expand All @@ -27,12 +27,12 @@
<redisson-starter.version>3.16.1</redisson-starter.version>
<easyCaptcha.version>1.6.2</easyCaptcha.version>
<hutool.version>5.7.20</hutool.version>
<mybatis-plus-boot-starter.version>3.4.0</mybatis-plus-boot-starter.version>
<mybatis-plus-boot-starter.version>3.5.1</mybatis-plus-boot-starter.version>
<aliyun-sdk-oss>3.8.1</aliyun-sdk-oss>
<qiniu-java-sdk>7.2.28</qiniu-java-sdk>
<easypoi.version>4.1.3</easypoi.version>
<poi.version>4.1.1</poi.version>
<spring-boot-admin.version>2.5.5</spring-boot-admin.version>
<spring-boot-admin.version>2.5.6</spring-boot-admin.version>
<velocity.version>1.7</velocity.version>
<commons-configuration2.version>2.7</commons-configuration2.version>
<txlcn.version>5.0.2.RELEASE</txlcn.version>
Expand Down
2 changes: 1 addition & 1 deletion zlt-business/code-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-business</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>code-generator</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion zlt-business/file-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-business</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>file-center</artifactId>
<description>文件中心</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,4 @@ public class FileInfo extends Model<FileInfo> {
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;

@Override
protected Serializable pkVal() {
return this.id;
}
}
2 changes: 1 addition & 1 deletion zlt-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>central-platform</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>zlt-business</artifactId>
<description>业务中心</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-business/search-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-business</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>search-center</artifactId>
<description>搜索中心</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-business/search-center/search-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>search-center</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>search-client</artifactId>
<description>搜索中心客户端</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-business/search-center/search-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>search-center</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>search-server</artifactId>
<description>搜索中心服务端</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-business/user-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-business</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>user-center</artifactId>
<description>用户中心</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>central-platform</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>zlt-commons</artifactId>
<description>通用组件</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
public class CustomRedisTokenStore implements TokenStore {
private static final String ACCESS = "access:";
private static final String ACCESS_BAK = "access_bak:";
private static final String AUTH_TO_ACCESS = "auth_to_access:";
private static final String REFRESH_AUTH = "refresh_auth:";
private static final String ACCESS_TO_REFRESH = "access_to_refresh:";
Expand Down Expand Up @@ -118,7 +119,7 @@ private OAuth2RefreshToken deserializeRefreshToken(byte[] bytes) {
}

private ClientDetails deserializeClientDetails(byte[] bytes) {
return (ClientDetails)redisValueSerializer.deserialize(bytes);
return (ClientDetails) redisValueSerializer.deserialize(bytes);
}

private byte[] serialize(String string) {
Expand Down Expand Up @@ -166,7 +167,7 @@ public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {
//获取过期时长
int validitySeconds = getAccessTokenValiditySeconds(clientAuth.getClientId());
if (validitySeconds > 0) {
double expiresRatio = token.getExpiresIn() / (double)validitySeconds;
double expiresRatio = token.getExpiresIn() / (double) validitySeconds;
//判断是否需要续签,当前剩余时间小于过期时长的50%则续签
if (expiresRatio <= securityProperties.getAuth().getRenew().getTimeRatio()) {
//更新AccessToken过期时间
Expand All @@ -182,6 +183,7 @@ public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {

/**
* 判断应用自动续签是否满足白名单和黑名单的过滤逻辑
*
* @param clientId 应用id
* @return 是否满足
*/
Expand All @@ -193,14 +195,15 @@ private boolean checkRenewClientId(String clientId) {
List<String> exclusiveClientIds = securityProperties.getAuth().getRenew().getExclusiveClientIds();
if (includeClientIds.size() > 0) {
result = includeClientIds.contains(clientId);
} else if(exclusiveClientIds.size() > 0) {
} else if (exclusiveClientIds.size() > 0) {
result = !exclusiveClientIds.contains(clientId);
}
return result;
}

/**
* 获取token的总有效时长
*
* @param clientId 应用id
*/
private int getAccessTokenValiditySeconds(String clientId) {
Expand Down Expand Up @@ -256,12 +259,14 @@ public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authe

/**
* 存储token
*
* @param isRenew 是否续签
*/
private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication, boolean isRenew) {
byte[] serializedAccessToken = serialize(token);
byte[] serializedAuth = serialize(authentication);
byte[] accessKey = serializeKey(ACCESS + token.getValue());
byte[] accessBakKey = serializeKey(ACCESS_BAK + token.getValue());
byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + token.getValue());
byte[] authToAccessKey = serializeKey(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication));
byte[] approvalKey = serializeKey(SecurityConstants.REDIS_UNAME_TO_ACCESS + getApprovalKey(authentication));
Expand All @@ -279,13 +284,15 @@ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication auth
if (springDataRedis_2_0) {
try {
this.redisConnectionSet_2_0.invoke(conn, accessKey, serializedAccessToken);
this.redisConnectionSet_2_0.invoke(conn, accessBakKey, serializedAccessToken);
this.redisConnectionSet_2_0.invoke(conn, authKey, serializedAuth);
this.redisConnectionSet_2_0.invoke(conn, authToAccessKey, serializedAccessToken);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else {
conn.set(accessKey, serializedAccessToken);
conn.set(accessBakKey, serializedAccessToken);
conn.set(authKey, serializedAuth);
conn.set(authToAccessKey, serializedAccessToken);
}
Expand All @@ -303,6 +310,7 @@ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication auth
if (token.getExpiration() != null) {
int seconds = token.getExpiresIn();
conn.expire(accessKey, seconds);
conn.expire(accessBakKey, seconds + 60);
conn.expire(authKey, seconds);
conn.expire(authToAccessKey, seconds);
conn.expire(clientId, seconds);
Expand Down Expand Up @@ -363,6 +371,7 @@ public OAuth2AccessToken readAccessToken(String tokenValue) {

public void removeAccessToken(String tokenValue) {
byte[] accessKey = serializeKey(ACCESS + tokenValue);
byte[] accessBakKey = serializeKey(ACCESS_BAK + tokenValue);
byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + tokenValue);
byte[] accessToRefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
RedisConnection conn = getConnection();
Expand All @@ -371,6 +380,7 @@ public void removeAccessToken(String tokenValue) {
byte[] auth = conn.get(authKey);
conn.openPipeline();
conn.del(accessKey);
conn.del(accessBakKey);
conn.del(accessToRefreshKey);
// Don't remove the refresh token - it's up to the caller to do that
conn.del(authKey);
Expand Down
2 changes: 1 addition & 1 deletion zlt-commons/zlt-common-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>zlt-common-core</artifactId>
<description>公共通用组件</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface CommonConstant {
/**
* 项目版本号(banner使用)
*/
String PROJECT_VERSION = "5.2.0";
String PROJECT_VERSION = "5.3.0";

/**
* token请求头名称
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ public interface ConfigConstants {
* 是否开启自定义隔离规则
*/
String CONFIG_RIBBON_ISOLATION_ENABLED = "zlt.ribbon.isolation.enabled";

String CONFIG_LOADBALANCE_ISOLATION = "zlt.loadbalance.isolation";

String CONFIG_LOADBALANCE_ISOLATION_ENABLE = CONFIG_LOADBALANCE_ISOLATION + ".enabled";

String CONFIG_LOADBALANCE_ISOLATION_CHOOSER = CONFIG_LOADBALANCE_ISOLATION + ".chooser";

String CONFIG_LOADBALANCE_VERSION = "zlt.loadbalance.version";


}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public interface SecurityConstants {
* redis中授权token对应的key
*/
String REDIS_TOKEN_AUTH = "auth:";
/**
* 值同access 过期时间+60
*/
String ACCESS_BAK = "access_bak:";
/**
* redis中应用对应的token集合的key
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ public class SuperEntity<T extends Model<?>> extends Model<T> {
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;

@Override
protected Serializable pkVal() {
return this.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean saveIdempotency(T entity, DistributedLock locker, String lockKey,
) {
if (lock != null) {
//判断记录是否已存在
int count = super.count(countWrapper);
long count = super.count(countWrapper);
if (count == 0) {
return super.save(entity);
} else {
Expand Down
2 changes: 1 addition & 1 deletion zlt-commons/zlt-common-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>zlt-common-spring-boot-starter</artifactId>
<description>公共通用组件</description>
Expand Down
2 changes: 1 addition & 1 deletion zlt-commons/zlt-db-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.central.db.config;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.parser.ISqlParserFilter;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.central.common.properties.TenantProperties;
import com.central.db.interceptor.CustomTenantInterceptor;
import com.central.db.properties.MybatisPlusAutoFillProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -26,10 +26,7 @@
@EnableConfigurationProperties(MybatisPlusAutoFillProperties.class)
public class MybatisPlusAutoConfigure {
@Autowired
private TenantHandler tenantHandler;

@Autowired
private ISqlParserFilter sqlParserFilter;
private TenantLineHandler tenantLineHandler;

@Autowired
private TenantProperties tenantProperties;
Expand All @@ -41,17 +38,17 @@ public class MybatisPlusAutoConfigure {
* 分页插件,自动识别数据库类型
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
boolean enableTenant = tenantProperties.getEnable();
//是否开启多租户隔离
if (enableTenant) {
TenantSqlParser tenantSqlParser = new TenantSqlParser()
.setTenantHandler(tenantHandler);
paginationInterceptor.setSqlParserList(CollUtil.toList(tenantSqlParser));
paginationInterceptor.setSqlParserFilter(sqlParserFilter);
CustomTenantInterceptor tenantInterceptor = new CustomTenantInterceptor(
tenantLineHandler, tenantProperties.getIgnoreSqls());
mpInterceptor.addInnerInterceptor(tenantInterceptor);
}
return paginationInterceptor;
return mpInterceptor;
}

@Bean
Expand Down
Loading