mirror of https://gitee.com/stylefeng/roses
【7.3.2】【cache】整理验证码的缓存实现
parent
5888956cba
commit
9104753124
|
@ -29,6 +29,8 @@ import cn.stylefeng.roses.kernel.security.api.DragCaptchaApi;
|
|||
import cn.stylefeng.roses.kernel.security.api.ImageCaptchaApi;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.DragCaptchaService;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.ImageCaptchaService;
|
||||
import cn.stylefeng.roses.kernel.security.starter.cache.SecurityMemoryCacheAutoConfiguration;
|
||||
import cn.stylefeng.roses.kernel.security.starter.cache.SecurityRedisCacheAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -43,7 +45,7 @@ import javax.annotation.Resource;
|
|||
* @date 2020/12/1 21:44
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter(SecurityCacheAutoConfiguration.class)
|
||||
@AutoConfigureAfter({SecurityMemoryCacheAutoConfiguration.class, SecurityRedisCacheAutoConfiguration.class})
|
||||
public class CaptchaAutoConfiguration {
|
||||
|
||||
@Resource(name = "captchaCache")
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package cn.stylefeng.roses.kernel.security.starter.cache;
|
||||
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.cache.CaptchaMemoryCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 安全模块,缓存的依赖
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 9:57
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
|
||||
public class SecurityMemoryCacheAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 验证码相关的缓存,内存缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 20:44
|
||||
*/
|
||||
@Bean("captchaCache")
|
||||
public CacheOperatorApi<String> captchaMemoryCache() {
|
||||
// 验证码过期时间 120秒
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(1000 * 120);
|
||||
return new CaptchaMemoryCache(timedCache);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,10 @@
|
|||
package cn.stylefeng.roses.kernel.security.starter;
|
||||
package cn.stylefeng.roses.kernel.security.starter.cache;
|
||||
|
||||
|
||||
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.redis.util.CreateRedisTemplateUtil;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.cache.CaptchaMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.cache.CaptchaRedisCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
@ -21,21 +17,8 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||
* @date 2022/11/8 9:57
|
||||
*/
|
||||
@Configuration
|
||||
public class SecurityCacheAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 验证码相关的缓存,内存缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 20:44
|
||||
*/
|
||||
@Bean("captchaCache")
|
||||
@ConditionalOnMissingClass("org.springframework.data.redis.core.RedisTemplate")
|
||||
public CacheOperatorApi<String> captchaMemoryCache() {
|
||||
// 验证码过期时间 120秒
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(1000 * 120);
|
||||
return new CaptchaMemoryCache(timedCache);
|
||||
}
|
||||
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
|
||||
public class SecurityRedisCacheAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 验证码相关的缓存,Redis缓存
|
||||
|
@ -44,7 +27,6 @@ public class SecurityCacheAutoConfiguration {
|
|||
* @date 2022/11/8 20:44
|
||||
*/
|
||||
@Bean("captchaCache")
|
||||
@ConditionalOnClass(name = "org.springframework.data.redis.core.RedisTemplate")
|
||||
public CacheOperatorApi<String> captchaRedisCache(RedisConnectionFactory redisConnectionFactory) {
|
||||
// 验证码过期时间 120秒
|
||||
RedisTemplate<String, String> redisTemplate = CreateRedisTemplateUtil.createString(redisConnectionFactory);
|
|
@ -3,4 +3,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
|||
cn.stylefeng.roses.kernel.security.starter.GunsXssAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.security.starter.CounterAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.security.starter.CaptchaAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.security.starter.SecurityCacheAutoConfiguration
|
||||
cn.stylefeng.roses.kernel.security.starter.cache.SecurityMemoryCacheAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.security.starter.cache.SecurityRedisCacheAutoConfiguration
|
||||
|
|
Loading…
Reference in New Issue