From 8780aa89046e30f075ced10fdf8fd8057198d3ed Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Sat, 25 Nov 2023 09:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.0.4=E3=80=91=E3=80=90sys=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8B=96=E6=8B=BD=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/security/api/constants/CaptchaConstants.java | 5 +++++ .../roses/kernel/security/captcha/DragCaptchaService.java | 4 ++-- .../starter/cache/SecurityMemoryCacheAutoConfiguration.java | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel-d-security/security-api/src/main/java/cn/stylefeng/roses/kernel/security/api/constants/CaptchaConstants.java b/kernel-d-security/security-api/src/main/java/cn/stylefeng/roses/kernel/security/api/constants/CaptchaConstants.java index 5fc492da1..16c5f0180 100644 --- a/kernel-d-security/security-api/src/main/java/cn/stylefeng/roses/kernel/security/api/constants/CaptchaConstants.java +++ b/kernel-d-security/security-api/src/main/java/cn/stylefeng/roses/kernel/security/api/constants/CaptchaConstants.java @@ -37,4 +37,9 @@ public interface CaptchaConstants { */ String CAPTCHA_CACHE_KEY_PREFIX = "CAPTCHA_KEY"; + /** + * 拖拽验证码缓存过期时间 + */ + Long DRAG_CAPTCHA_IMG_EXP_SECONDS = 120L; + } diff --git a/kernel-d-security/security-sdk-captcha/src/main/java/cn/stylefeng/roses/kernel/security/captcha/DragCaptchaService.java b/kernel-d-security/security-sdk-captcha/src/main/java/cn/stylefeng/roses/kernel/security/captcha/DragCaptchaService.java index acf80ab35..845ca28a1 100644 --- a/kernel-d-security/security-sdk-captcha/src/main/java/cn/stylefeng/roses/kernel/security/captcha/DragCaptchaService.java +++ b/kernel-d-security/security-sdk-captcha/src/main/java/cn/stylefeng/roses/kernel/security/captcha/DragCaptchaService.java @@ -31,6 +31,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.security.api.DragCaptchaApi; +import cn.stylefeng.roses.kernel.security.api.constants.CaptchaConstants; import cn.stylefeng.roses.kernel.security.api.exception.SecurityException; import cn.stylefeng.roses.kernel.security.api.exception.enums.SecurityExceptionEnum; import cn.stylefeng.roses.kernel.security.api.pojo.DragCaptchaImageDTO; @@ -63,11 +64,10 @@ public class DragCaptchaService implements DragCaptchaApi { // 缓存x轴坐标 String verKey = IdUtil.simpleUUID(); Integer verValue = dragCaptchaImageDTO.getLocationX(); - cacheOperatorApi.put(verKey, verValue.toString()); + cacheOperatorApi.put(verKey, verValue.toString(), CaptchaConstants.DRAG_CAPTCHA_IMG_EXP_SECONDS); // 清空x轴坐标 dragCaptchaImageDTO.setKey(verKey); -// dragCaptchaImageDTO.setLocationX(null); return dragCaptchaImageDTO; } catch (IOException e) { diff --git a/kernel-d-security/security-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/security/starter/cache/SecurityMemoryCacheAutoConfiguration.java b/kernel-d-security/security-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/security/starter/cache/SecurityMemoryCacheAutoConfiguration.java index 58c1ccd6a..d645ab3a6 100644 --- a/kernel-d-security/security-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/security/starter/cache/SecurityMemoryCacheAutoConfiguration.java +++ b/kernel-d-security/security-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/security/starter/cache/SecurityMemoryCacheAutoConfiguration.java @@ -5,6 +5,7 @@ import cn.hutool.cache.CacheUtil; import cn.hutool.cache.impl.TimedCache; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants; +import cn.stylefeng.roses.kernel.security.api.constants.CaptchaConstants; import cn.stylefeng.roses.kernel.security.captcha.cache.CaptchaMemoryCache; import cn.stylefeng.roses.kernel.security.count.cache.CountValidateMemoryCache; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; @@ -30,7 +31,7 @@ public class SecurityMemoryCacheAutoConfiguration { @Bean("captchaCache") public CacheOperatorApi captchaMemoryCache() { // 验证码过期时间 120秒 - TimedCache timedCache = CacheUtil.newTimedCache(1000 * 120); + TimedCache timedCache = CacheUtil.newTimedCache(1000 * CaptchaConstants.DRAG_CAPTCHA_IMG_EXP_SECONDS); return new CaptchaMemoryCache(timedCache); }