Merge remote-tracking branch 'origin/6.X' into 6.X

This commit is contained in:
admin
2026-09-08 18:12:27 +08:00
5 changed files with 38 additions and 16 deletions
@@ -15,10 +15,7 @@ import org.dromara.common.core.utils.regex.RegexValidator;
import org.dromara.common.mail.config.properties.MailProperties; import org.dromara.common.mail.config.properties.MailProperties;
import org.dromara.common.redis.annotation.RateLimiter; import org.dromara.common.redis.annotation.RateLimiter;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* 验证码操作处理 * 验证码操作处理
@@ -92,12 +89,11 @@ public class CaptchaController {
* 校验【行为滑块验证码】 * 校验【行为滑块验证码】
* POST语义更合适,提交校验参数 * POST语义更合适,提交校验参数
* *
* @param captchaKey 验证码缓存key * @param data 验证码缓存key
* @param slideX 用户滑动偏移x坐标
* @return 校验结果 * @return 校验结果
*/ */
@PostMapping("/behavior/verify") @PostMapping("/behavior/verify")
public ApiResponse<?> verifyBehaviorCaptcha(behaviorData data) { public ApiResponse<?> verifyBehaviorCaptcha(@RequestBody behaviorData data) {
return captchaUtils.verifyBehaviorCaptchaFirstStage(data.id(), data.data()); return captchaUtils.verifyBehaviorCaptchaFirstStage(data.id(), data.data());
} }
@@ -49,7 +49,7 @@ captcha:
local-cache-ignored-cache-fields: "" local-cache-ignored-cache-fields: ""
# 配置字体包,供文字点选验证码使用,可以配置多个,不配置使用默认的字体 # 配置字体包,供文字点选验证码使用,可以配置多个,不配置使用默认的字体
font-path: font-path:
- classpath:font/SimHei.ttf - classpath:font/AaKuangPaiShouShu-2.ttf
secondary: secondary:
# 二次验证, 默认false 不开启 # 二次验证, 默认false 不开启
enabled: true enabled: true
@@ -38,7 +38,7 @@ public class CaptchaConfig {
resourceStore.addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgimages/j.jpg", "default")); resourceStore.addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgimages/j.jpg", "default"));
resourceStore.addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgimages/48.jpg", "default")); resourceStore.addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgimages/48.jpg", "default"));
resourceStore.addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgimages/48.jpg", "default")); resourceStore.addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgimages/48.jpg", "default"));
// resourceStore.addResource(CaptchaTypeConstant.WORD_IMAGE_CLICK, new Resource("classpath", "bgimages/c.jpg", "default")); resourceStore.addResource(CaptchaTypeConstant.WORD_IMAGE_CLICK, new Resource("classpath", "bgimages/c.jpg", "default"));
return resourceStore; return resourceStore;
} }
@@ -1,5 +1,7 @@
package org.dromara.common.core.validate.enums; package org.dromara.common.core.validate.enums;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.BooleanUtil;
import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext; import jakarta.validation.ConstraintValidatorContext;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
@@ -14,12 +16,17 @@ import java.util.Set;
* @author 秋辞未寒 * @author 秋辞未寒
* @date 2024-12-09 * @date 2024-12-09
*/ */
public class EnumPatternValidator implements ConstraintValidator<EnumPattern, String> { public class EnumPatternValidator implements ConstraintValidator<EnumPattern, Object> {
/** /**
* 枚举允许值集合。 * 枚举允许值集合。
*/ */
private final Set<String> values = new HashSet<>(); private final Set<Object> values = new HashSet<>();
/**
* 枚举字段值类型。
*/
private Class<?> valueType;
/** /**
* 初始化枚举允许值集合。 * 初始化枚举允许值集合。
@@ -36,24 +43,43 @@ public class EnumPatternValidator implements ConstraintValidator<EnumPattern, St
for (Object e : annotation.type().getEnumConstants()) { for (Object e : annotation.type().getEnumConstants()) {
Object fieldValue = ReflectUtils.invokeGetter(e, fieldName); Object fieldValue = ReflectUtils.invokeGetter(e, fieldName);
if (fieldValue != null) { if (fieldValue != null) {
values.add(String.valueOf(fieldValue)); if (valueType == null) {
valueType = fieldValue.getClass();
}
values.add(fieldValue);
} }
} }
} }
/** /**
* 校验字符串是否在枚举允许值集合内。 * 校验值是否在枚举允许值集合内。
*
* <p>以枚举字段的实际类型转换输入值后进行比较,可兼容字符串、数字、布尔值等字段类型,
* 同时避免将无法转换的值视为合法值。字符串类型的空白值按未填写处理,其他类型仅 null
* 按未填写处理。</p>
* *
* @param value 待校验值 * @param value 待校验值
* @param constraintValidatorContext 校验上下文 * @param constraintValidatorContext 校验上下文
* @return true 校验通过 false 校验失败 * @return true 校验通过 false 校验失败
*/ */
@Override @Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
if (StringUtils.isBlank(value)) { if (value == null) {
return true; return true;
} }
return values.contains(value); if (valueType == null) {
return false;
}
if (value instanceof CharSequence && StringUtils.isBlank(value.toString())
&& CharSequence.class.isAssignableFrom(valueType)) {
return true;
}
if ((valueType == Boolean.class || valueType == boolean.class) && value instanceof CharSequence
&& BooleanUtil.toBooleanObject(value.toString()) == null) {
return false;
}
Object convertedValue = Convert.convertWithCheck(valueType, value, null, true);
return convertedValue != null && values.contains(convertedValue);
} }
} }