mirror of https://gitee.com/stylefeng/roses
【7.3.2】【security】更新security模块的缓存配置
parent
26ca14cb97
commit
ae84064c95
|
@ -24,22 +24,21 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.security.starter;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.security.api.BlackListApi;
|
||||
import cn.stylefeng.roses.kernel.security.api.CountValidatorApi;
|
||||
import cn.stylefeng.roses.kernel.security.api.WhiteListApi;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.BlackListService;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.WhiteListService;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.BlackListMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.WhiteListMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.security.count.DefaultCountValidator;
|
||||
import cn.stylefeng.roses.kernel.security.count.cache.DefaultCountValidateCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* 计数器和黑白名单自动配置
|
||||
|
@ -48,8 +47,18 @@ import org.springframework.context.annotation.Configuration;
|
|||
* @date 2020/12/1 21:44
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter({SecurityMemoryCacheAutoConfiguration.class, SecurityRedisCacheAutoConfiguration.class})
|
||||
public class CounterAutoConfiguration {
|
||||
|
||||
@Resource(name = "blackListCache")
|
||||
private CacheOperatorApi<String> blackListCache;
|
||||
|
||||
@Resource(name = "whiteListCache")
|
||||
private CacheOperatorApi<String> whiteListCache;
|
||||
|
||||
@Resource(name = "countValidateCache")
|
||||
private CacheOperatorApi<Long> countValidateCache;
|
||||
|
||||
/**
|
||||
* 黑名单校验
|
||||
*
|
||||
|
@ -57,25 +66,8 @@ public class CounterAutoConfiguration {
|
|||
* @date 2020/12/1 21:18
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(BlackListApi.class)
|
||||
public BlackListApi blackListApi() {
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
BlackListMemoryCache blackListMemoryCache = new BlackListMemoryCache(timedCache);
|
||||
return new BlackListService(blackListMemoryCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计数校验器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/1 21:18
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(CountValidatorApi.class)
|
||||
public CountValidatorApi countValidatorApi() {
|
||||
TimedCache<String, Long> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
DefaultCountValidateCache defaultCountValidateCache = new DefaultCountValidateCache(timedCache);
|
||||
return new DefaultCountValidator(defaultCountValidateCache);
|
||||
return new BlackListService(blackListCache);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,11 +77,19 @@ public class CounterAutoConfiguration {
|
|||
* @date 2020/12/1 21:18
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(WhiteListApi.class)
|
||||
public WhiteListApi whiteListApi() {
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
WhiteListMemoryCache whiteListMemoryCache = new WhiteListMemoryCache(timedCache);
|
||||
return new WhiteListService(whiteListMemoryCache);
|
||||
return new WhiteListService(whiteListCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计数校验器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/1 21:18
|
||||
*/
|
||||
@Bean
|
||||
public CountValidatorApi countValidatorApi() {
|
||||
return new DefaultCountValidator(countValidateCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,11 @@ 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.api.constants.CacheConstants;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.BlackListMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.WhiteListMemoryCache;
|
||||
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;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -32,4 +36,40 @@ public class SecurityMemoryCacheAutoConfiguration {
|
|||
return new CaptchaMemoryCache(timedCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 黑名单的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("blackListCache")
|
||||
public CacheOperatorApi<String> blackListMemoryCache() {
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
return new BlackListMemoryCache(timedCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 白名单的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("whiteListCache")
|
||||
public CacheOperatorApi<String> whiteListMemoryCache() {
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
return new WhiteListMemoryCache(timedCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计数缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("countValidateCache")
|
||||
public CacheOperatorApi<Long> countValidateMemoryCache() {
|
||||
TimedCache<String, Long> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
|
||||
return new CountValidateMemoryCache(timedCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ package cn.stylefeng.roses.kernel.security.starter.cache;
|
|||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.BlackListRedisCache;
|
||||
import cn.stylefeng.roses.kernel.security.blackwhite.cache.WhiteListRedisCache;
|
||||
import cn.stylefeng.roses.kernel.security.captcha.cache.CaptchaRedisCache;
|
||||
import cn.stylefeng.roses.kernel.security.count.cache.CountValidateRedisCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -33,4 +36,40 @@ public class SecurityRedisCacheAutoConfiguration {
|
|||
return new CaptchaRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 黑名单的缓存,Redis缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("blackListCache")
|
||||
public CacheOperatorApi<String> blackListRedisCache(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, String> redisTemplate = CreateRedisTemplateUtil.createString(redisConnectionFactory);
|
||||
return new BlackListRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 白名单的缓存,Redis缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("whiteListCache")
|
||||
public CacheOperatorApi<String> whiteListRedisCache(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, String> redisTemplate = CreateRedisTemplateUtil.createString(redisConnectionFactory);
|
||||
return new WhiteListRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计数缓存,Redis缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/8 21:24
|
||||
*/
|
||||
@Bean("countValidateCache")
|
||||
public CacheOperatorApi<Long> countValidateRedisCache(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Long> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
|
||||
return new CountValidateRedisCache(redisTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue