This commit is contained in:
CangJieStore 2026-11-15 23:30:34 +08:00
parent 004e55f198
commit 4e9496e163
12 changed files with 8 additions and 568 deletions

View file

@ -26,6 +26,12 @@
| swagger-annotations | 2.2.52 | 2.2.55 | | swagger-annotations | 2.2.52 | 2.2.55 |
| jetcd | 0.8.5 | 0.8.8 | | jetcd | 0.8.5 | 0.8.8 |
## 移除 tianai-captcha 模块
- 删除子模块 `simple-starter-captcha/simple-starter-captcha-tianai`(此前新增的行为验证码封装,底层 `cloud.tianai.captcha` 核心库)。
- 清理 4 处引用:`simple-starter-captcha/pom.xml`(module)、`simple-starter-bom/pom.xml`(dependencyManagement)、`simple-starter-dependencies/pom.xml`(`tianai-captcha.version` 属性 + dependencyManagement)、`PropertiesConstants.CAPTCHA_TIANAI` 常量。
- 全量 `mvn -DskipTests clean compile` 通过;全仓 grep 确认无 tianai 残留。
## 分布式 ID 选型备忘(本次讨论结论) ## 分布式 ID 选型备忘(本次讨论结论)
- 项目对 CosId 用法极浅:仅 `simple-starter-data-mp` 的 `MyBatisPlusCosIdIdentifierGenerator` 用 `SnowflakeId` 当主键,`@Qualifier("__share__SnowflakeId")`,无 @CosId 注解、无 store。 - 项目对 CosId 用法极浅:仅 `simple-starter-data-mp` 的 `MyBatisPlusCosIdIdentifierGenerator` 用 `SnowflakeId` 当主键,`@Qualifier("__share__SnowflakeId")`,无 @CosId 注解、无 store。

View file

@ -13,7 +13,7 @@
<description>Simple Starter BOM</description> <description>Simple Starter BOM</description>
<properties> <properties>
<revision>2.6.3</revision> <revision>2.6.4</revision>
<!-- 对齐 simple-starter-dependencies 的 Spring Boot 版本 --> <!-- 对齐 simple-starter-dependencies 的 Spring Boot 版本 -->
<spring-boot.version>4.1.0</spring-boot.version> <spring-boot.version>4.1.0</spring-boot.version>
</properties> </properties>
@ -146,12 +146,6 @@
<artifactId>simple-starter-captcha-behavior</artifactId> <artifactId>simple-starter-captcha-behavior</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- 验证码模块 - 行为验证码(天爱) -->
<dependency>
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-captcha-tianai</artifactId>
<version>${revision}</version>
</dependency>
<!-- 安全模块 - 脱敏 --> <!-- 安全模块 - 脱敏 -->
<dependency> <dependency>

View file

@ -19,7 +19,6 @@
<modules> <modules>
<module>simple-starter-captcha-graphic</module> <module>simple-starter-captcha-graphic</module>
<module>simple-starter-captcha-behavior</module> <module>simple-starter-captcha-behavior</module>
<module>simple-starter-captcha-tianai</module>
</modules> </modules>
<dependencies> <dependencies>

View file

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-captcha</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>simple-starter-captcha-tianai</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>验证码模块 - 行为验证码(天爱 tianai-captcha,支持滑块/旋转/滑动还原/文字点选等)</description>
<dependencies>
<!-- Tianai Captcha(行为验证码核心库,内置背景图与模板,不依赖 Spring,兼容 Spring Boot 3) -->
<dependency>
<groupId>cloud.tianai.captcha</groupId>
<artifactId>tianai-captcha</artifactId>
</dependency>
<!-- 缓存模块 - Redisson(可选:仅 cache-type 为 redis 时需要) -->
<dependency>
<groupId>reliable.simple.starter</groupId>
<artifactId>simple-starter-cache-redisson</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View file

@ -1,110 +0,0 @@
/*
* Copyright (c) 2022-present Xcynet Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reliable.simple.starter.captcha.tianai.autoconfigure;
import cloud.tianai.captcha.application.ImageCaptchaApplication;
import cloud.tianai.captcha.application.ImageCaptchaProperties;
import cloud.tianai.captcha.application.TACBuilder;
import cloud.tianai.captcha.cache.CacheStore;
import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.resource.common.model.dto.Resource;
import cn.hutool.core.collection.CollectionUtil;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import reliable.simple.starter.captcha.tianai.autoconfigure.cache.TianaiCaptchaCacheAutoConfiguration;
import reliable.simple.starter.core.constant.PropertiesConstants;
import reliable.simple.starter.core.constant.StringConstants;
import java.util.LinkedHashMap;
/**
* 天爱验证码自动配置
*
* @author Copyright with xcynet
*/
@AutoConfiguration(after = TianaiCaptchaCacheAutoConfiguration.class)
@ConditionalOnClass(ImageCaptchaApplication.class)
@EnableConfigurationProperties(TianaiCaptchaProperties.class)
@ConditionalOnProperty(prefix = PropertiesConstants.CAPTCHA_TIANAI, name = PropertiesConstants.ENABLED, havingValue = "true")
public class TianaiCaptchaAutoConfiguration {
private static final Logger log = LoggerFactory.getLogger(TianaiCaptchaAutoConfiguration.class);
/**
* 内置底图(tianai-captcha 自带,未配置自定义底图时使用)
*/
private static final String DEFAULT_BACKGROUND_IMAGE = "META-INF/cut-image/resource/1.jpg";
/**
* 内置模板支持的验证码类型(其余类型需自行提供模板与底图)
*/
private static final String[] DEFAULT_TEMPLATE_TYPES = {CaptchaTypeConstant.SLIDER, CaptchaTypeConstant.ROTATE};
/**
* 天爱验证码应用
*
* @param properties 天爱验证码配置属性
* @param cacheStore 验证码缓存
* @return 验证码应用
*/
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean
public ImageCaptchaApplication imageCaptchaApplication(TianaiCaptchaProperties properties, CacheStore cacheStore) {
TACBuilder builder = TACBuilder.builder()
.setProp(buildApplicationProperties(properties))
.setCacheStore(cacheStore)
.addDefaultTemplate();
// 自定义底图
properties.getBackgroundImages()
.forEach((type, paths) -> paths.forEach(path -> builder
.addResource(type, new Resource("classpath", path))));
// 未配置自定义底图的类型,回退到内置底图
for (String type : DEFAULT_TEMPLATE_TYPES) {
if (CollectionUtil.isEmpty(properties.getBackgroundImages().get(type))) {
builder.addResource(type, new Resource("classpath", DEFAULT_BACKGROUND_IMAGE));
}
}
// 自定义字体(文字点选验证码使用)
properties.getFonts().forEach(path -> builder.addFont(new Resource("classpath", path)));
return builder.build();
}
/**
* 构建 tianai-captcha 应用配置
*
* @param properties 天爱验证码配置属性
* @return 应用配置
*/
private static ImageCaptchaProperties buildApplicationProperties(TianaiCaptchaProperties properties) {
ImageCaptchaProperties applicationProperties = new ImageCaptchaProperties();
applicationProperties.setPrefix(properties.getPrefix());
applicationProperties.setExpire(new LinkedHashMap<>(properties.getExpire()));
return applicationProperties;
}
@PostConstruct
public void postConstruct() {
log.debug(StringConstants.LOGGER + " - Auto Configuration 'Captcha-Tianai' completed initialization.");
}
}

View file

@ -1,125 +0,0 @@
/*
* Copyright (c) 2022-present Xcynet Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reliable.simple.starter.captcha.tianai.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
import reliable.simple.starter.captcha.tianai.enums.StorageType;
import reliable.simple.starter.core.constant.PropertiesConstants;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 天爱验证码配置属性
*
* <p>热插拔:默认关闭,引入依赖后需显式配置 {@code simple-starter.captcha.tianai.enabled=true} 才会装配,
* 可与 {@code simple-starter-captcha-behavior}(AJ-Captcha)同时存在于类路径而互不干扰。</p>
*
* @author Copyright with xcynet
*/
@ConfigurationProperties(PropertiesConstants.CAPTCHA_TIANAI)
public class TianaiCaptchaProperties {
/**
* 是否启用(默认:false,按需开启实现热插拔)
*/
private boolean enabled = false;
/**
* 缓存类型(默认:内存)
*/
private StorageType cacheType = StorageType.DEFAULT;
/**
* 缓存键前缀(默认:captcha:tianai)
*/
private String prefix = "captcha:tianai";
/**
* 验证码有效期(单位:毫秒,键为验证码类型,default 为全局默认值)
*/
private Map<String, Long> expire = defaultExpire();
/**
* 自定义底图(键为验证码类型,如 SLIDER / ROTATE / CONCAT / WORD_IMAGE_CLICK,值为 classpath 下的图片路径)
*
* <p>不配置则使用 tianai-captcha 内置底图</p>
*/
private Map<String, List<String>> backgroundImages = new LinkedHashMap<>();
/**
* 自定义字体(classpath 下的字体路径,如 font/SimHei.ttf,用于文字点选验证码)
*/
private List<String> fonts = new ArrayList<>();
private static Map<String, Long> defaultExpire() {
Map<String, Long> expire = new LinkedHashMap<>();
expire.put("default", 120_000L);
expire.put("WORD_IMAGE_CLICK", 200_000L);
return expire;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public StorageType getCacheType() {
return cacheType;
}
public void setCacheType(StorageType cacheType) {
this.cacheType = cacheType;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public Map<String, Long> getExpire() {
return expire;
}
public void setExpire(Map<String, Long> expire) {
this.expire = expire;
}
public Map<String, List<String>> getBackgroundImages() {
return backgroundImages;
}
public void setBackgroundImages(Map<String, List<String>> backgroundImages) {
this.backgroundImages = backgroundImages;
}
public List<String> getFonts() {
return fonts;
}
public void setFonts(List<String> fonts) {
this.fonts = fonts;
}
}

View file

@ -1,113 +0,0 @@
/*
* Copyright (c) 2022-present Xcynet Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reliable.simple.starter.captcha.tianai.autoconfigure.cache;
import cloud.tianai.captcha.cache.CacheStore;
import cloud.tianai.captcha.cache.impl.LocalCacheStore;
import jakarta.annotation.PostConstruct;
import org.redisson.client.RedisClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.core.ResolvableType;
import reliable.simple.starter.cache.redisson.autoconfigure.RedissonAutoConfiguration;
import reliable.simple.starter.captcha.tianai.autoconfigure.TianaiCaptchaProperties;
import reliable.simple.starter.core.constant.PropertiesConstants;
import reliable.simple.starter.core.constant.StringConstants;
/**
* 天爱验证码缓存自动配置
*
* @author Copyright with xcynet
*/
@AutoConfiguration
@ConditionalOnClass(CacheStore.class)
@ConditionalOnProperty(prefix = PropertiesConstants.CAPTCHA_TIANAI, name = PropertiesConstants.ENABLED, havingValue = "true")
public class TianaiCaptchaCacheAutoConfiguration {
private static final Logger log = LoggerFactory.getLogger(TianaiCaptchaCacheAutoConfiguration.class);
private TianaiCaptchaCacheAutoConfiguration() {
}
/**
* 自定义缓存实现-默认(内存)
*/
@AutoConfiguration
@ConditionalOnMissingBean(CacheStore.class)
@ConditionalOnProperty(prefix = PropertiesConstants.CAPTCHA_TIANAI, name = "cache-type", havingValue = "default", matchIfMissing = true)
public static class Default {
@Bean
public CacheStore cacheStore() {
return new LocalCacheStore();
}
@PostConstruct
public void postConstruct() {
log.debug(StringConstants.LOGGER + " - Auto Configuration 'Captcha-Tianai-Cache-Default' completed initialization.");
}
}
/**
* 自定义缓存实现-Redis
*/
@AutoConfiguration(after = RedissonAutoConfiguration.class)
@ConditionalOnClass(RedisClient.class)
@ConditionalOnMissingBean(CacheStore.class)
@ConditionalOnProperty(prefix = PropertiesConstants.CAPTCHA_TIANAI, name = "cache-type", havingValue = "redis")
public static class Redis {
@Bean
public CacheStore cacheStore(TianaiCaptchaProperties properties) {
return new TianaiRedisCacheStore(properties.getPrefix());
}
@PostConstruct
public void postConstruct() {
log.debug(StringConstants.LOGGER + " - Auto Configuration 'Captcha-Tianai-Cache-Redis' completed initialization.");
}
}
/**
* 自定义缓存实现
*/
@AutoConfiguration
@ConditionalOnProperty(prefix = PropertiesConstants.CAPTCHA_TIANAI, name = "cache-type", havingValue = "custom")
public static class Custom {
@Bean
@ConditionalOnMissingBean
public CacheStore cacheStore() {
if (log.isErrorEnabled()) {
log.error("Consider defining a bean of type '{}' in your configuration.", ResolvableType
.forClass(CacheStore.class));
}
throw new NoSuchBeanDefinitionException(CacheStore.class);
}
@PostConstruct
public void postConstruct() {
log.debug(StringConstants.LOGGER + " - Auto Configuration 'Captcha-Tianai-Cache-Custom' completed initialization.");
}
}
}

View file

@ -1,123 +0,0 @@
/*
* Copyright (c) 2022-present Xcynet Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reliable.simple.starter.captcha.tianai.autoconfigure.cache;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONUtil;
import cloud.tianai.captcha.cache.CacheStore;
import cloud.tianai.captcha.common.AnyMap;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RBucket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reliable.simple.starter.cache.redisson.util.RedisUtils;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
/**
* 天爱验证码 Redis 缓存实现
*
* <p>验证码数据以 JSON 字符串存储,避免不同 Redisson 编解码器反序列化后丢失 {@link AnyMap} 类型。</p>
*
* @author Copyright with xcynet
*/
public class TianaiRedisCacheStore implements CacheStore {
private static final Logger log = LoggerFactory.getLogger(TianaiRedisCacheStore.class);
/**
* 默认验证码有效期(单位:毫秒)
*/
private static final long DEFAULT_EXPIRE = 120_000L;
private final String prefix;
public TianaiRedisCacheStore(String prefix) {
this.prefix = CharSequenceUtil.addSuffixIfNot(CharSequenceUtil.blankToDefault(prefix, "captcha:tianai"), ":");
}
@Override
public AnyMap getCache(String key) {
return parse(RedisUtils.get(formatKey(key)));
}
@Override
public AnyMap getAndRemoveCache(String key) {
RBucket<String> bucket = RedisUtils.getClient().getBucket(formatKey(key));
return parse(bucket.getAndDelete());
}
@Override
public boolean setCache(String key, AnyMap data, Long expire, TimeUnit timeUnit) {
if (data == null || data.isEmpty()) {
return false;
}
long expireMillis = expire == null || expire <= 0 ? DEFAULT_EXPIRE : timeUnit.toMillis(expire);
RedisUtils.set(formatKey(key), JSONUtil.toJsonStr(data), Duration.ofMillis(expireMillis));
return true;
}
@Override
public Long incr(String key, long delta, Long expire, TimeUnit timeUnit) {
RAtomicLong counter = RedisUtils.getClient().getAtomicLong(formatKey(key));
long value = counter.addAndGet(delta);
if (expire != null && expire > 0) {
counter.expire(Duration.ofMillis(timeUnit.toMillis(expire)));
}
return value;
}
@Override
public Long getLong(String key) {
RAtomicLong counter = RedisUtils.getClient().getAtomicLong(formatKey(key));
return counter.isExists() ? counter.get() : null;
}
@Override
public void close() {
// Redisson 客户端由容器统一管理,此处无需释放资源
}
/**
* 拼接完整的缓存键
*
* @param key 原始键
* @return 带前缀的缓存键
*/
private String formatKey(String key) {
return prefix + key;
}
/**
* 将 JSON 字符串解析为 {@link AnyMap}
*
* @param json JSON 字符串
* @return 验证码缓存数据,解析失败或内容为空时返回 null
*/
private AnyMap parse(String json) {
if (CharSequenceUtil.isBlank(json)) {
return null;
}
try {
return AnyMap.of(JSONUtil.parseObj(json));
} catch (Exception e) {
log.warn("天爱验证码缓存数据解析失败", e);
return null;
}
}
}

View file

@ -1,40 +0,0 @@
/*
* Copyright (c) 2022-present Xcynet Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package reliable.simple.starter.captcha.tianai.enums;
/**
* 天爱验证码缓存类型
*
* @author Copyright with xcynet
*/
public enum StorageType {
/**
* 默认(内存)
*/
DEFAULT,
/**
* Redis
*/
REDIS,
/**
* 自定义
*/
CUSTOM
}

View file

@ -1,2 +0,0 @@
reliable.simple.starter.captcha.tianai.autoconfigure.cache.TianaiCaptchaCacheAutoConfiguration
reliable.simple.starter.captcha.tianai.autoconfigure.TianaiCaptchaAutoConfiguration

View file

@ -115,11 +115,6 @@ public class PropertiesConstants {
*/ */
public static final String CAPTCHA_BEHAVIOR = CAPTCHA + StringConstants.DOT + "behavior"; public static final String CAPTCHA_BEHAVIOR = CAPTCHA + StringConstants.DOT + "behavior";
/**
* 行为验证码配置(天爱)
*/
public static final String CAPTCHA_TIANAI = CAPTCHA + StringConstants.DOT + "tianai";
/** /**
* 消息配置 * 消息配置
*/ */

View file

@ -14,7 +14,7 @@
<properties> <properties>
<!-- Project Version --> <!-- Project Version -->
<revision>2.6.3</revision> <revision>2.6.4</revision>
<!-- Core Framework Versions --> <!-- Core Framework Versions -->
<spring-boot.version>4.1.2</spring-boot.version> <spring-boot.version>4.1.2</spring-boot.version>
<spring-cloud.version>2025.1.4</spring-cloud.version> <spring-cloud.version>2025.1.4</spring-cloud.version>
@ -45,7 +45,6 @@
<!-- Captcha Versions --> <!-- Captcha Versions -->
<aj-captcha.version>2.0.0</aj-captcha.version> <aj-captcha.version>2.0.0</aj-captcha.version>
<easy-captcha.version>1.6.2</easy-captcha.version> <easy-captcha.version>1.6.2</easy-captcha.version>
<tianai-captcha.version>1.5.6</tianai-captcha.version>
<!-- Excel Processing Versions --> <!-- Excel Processing Versions -->
<fesod.version>2.0.2-incubating</fesod.version> <fesod.version>2.0.2-incubating</fesod.version>
@ -368,13 +367,6 @@
<version>${easy-captcha.version}</version> <version>${easy-captcha.version}</version>
</dependency> </dependency>
<!-- Tianai Captcha(行为验证码核心库,包含滑块拼图、旋转、滑动还原、文字点选等方式) -->
<dependency>
<groupId>cloud.tianai.captcha</groupId>
<artifactId>tianai-captcha</artifactId>
<version>${tianai-captcha.version}</version>
</dependency>
<!-- 解决部分传递依赖漏洞问题 --> <!-- 解决部分传递依赖漏洞问题 -->
<dependency> <dependency>
<groupId>commons-beanutils</groupId> <groupId>commons-beanutils</groupId>