feat(auth): 图片验证码类型支持参数管理动态配置 / Make image captcha type configurable via sys_config
- 生成验证码时优先读取参数 sys.account.captchaType(math/char),未配置时回退 yml security.captcha.type - 参数经 RemoteConfigService 读取,参数管理保存后即时生效
This commit is contained in:
@@ -6,6 +6,7 @@ import cn.hutool.captcha.generator.RandomGenerator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.auth.config.WaveAndCircleCaptcha;
|
||||
import org.dromara.auth.domain.vo.CaptchaVo;
|
||||
import org.dromara.auth.properties.CaptchaProperties;
|
||||
@@ -17,6 +18,7 @@ import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.redis.annotation.RateLimiter;
|
||||
import org.dromara.common.redis.enums.LimitType;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.system.api.RemoteConfigService;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -40,6 +42,9 @@ public class CaptchaController {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
|
||||
@DubboReference
|
||||
private final RemoteConfigService remoteConfigService;
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@@ -64,7 +69,9 @@ public class CaptchaController {
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + uuid;
|
||||
// 生成验证码
|
||||
String captchaType = captchaProperties.getType();
|
||||
// 验证码类型:优先取参数管理中的 sys.account.captchaType(math/char),未配置时回退 yml 配置
|
||||
String captchaType = StringUtils.blankToDefault(
|
||||
remoteConfigService.getConfigValue("sys.account.captchaType"), captchaProperties.getType());
|
||||
CodeGenerator codeGenerator;
|
||||
if ("math".equals(captchaType)) {
|
||||
codeGenerator = new MathGenerator(captchaProperties.getNumberLength(), false);
|
||||
|
||||
Reference in New Issue
Block a user