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); }