【7.0.1】验证码,计数器放入security模块

pull/3/head v7.0.1
fengshuonan 2021-03-14 18:15:17 +08:00
parent 4e5c634e08
commit 5fb475946a
43 changed files with 211 additions and 151 deletions

View File

@ -32,6 +32,14 @@
<version>7.0.1</version>
</dependency>
<!--安全模块的api-->
<!--需要用到校验验证码的接口-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>
<!--system业务模块的api-->
<!--登录和鉴权需要用到用户相关的接口-->
<dependency>

View File

@ -18,12 +18,12 @@ import cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum;
import cn.stylefeng.roses.kernel.jwt.api.pojo.payload.DefaultJwtPayload;
import cn.stylefeng.roses.kernel.message.api.expander.WebSocketConfigExpander;
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
import cn.stylefeng.roses.kernel.security.api.CaptchaApi;
import cn.stylefeng.roses.kernel.system.api.LoginLogServiceApi;
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
import cn.stylefeng.roses.kernel.system.api.enums.UserStatusEnum;
import cn.stylefeng.roses.kernel.system.api.expander.SystemConfigExpander;
import cn.stylefeng.roses.kernel.system.api.pojo.user.UserLoginInfoDTO;
import cn.stylefeng.roses.kernel.validator.api.CaptchaApi;
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
import org.springframework.stereotype.Service;

View File

@ -17,6 +17,9 @@
<modules>
<module>security-api</module>
<module>security-sdk-black-white</module>
<module>security-sdk-captcha</module>
<module>security-sdk-count</module>
<module>security-sdk-xss</module>
<module>security-spring-boot-starter</module>
</modules>

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.validator.api;
package cn.stylefeng.roses.kernel.security.api;
import java.util.Collection;

View File

@ -1,6 +1,6 @@
package cn.stylefeng.roses.kernel.validator.api;
package cn.stylefeng.roses.kernel.security.api;
import cn.stylefeng.roses.kernel.validator.api.pojo.EasyCaptcha;
import cn.stylefeng.roses.kernel.security.api.pojo.EasyCaptcha;
/**
* Api

View File

@ -1,7 +1,6 @@
package cn.stylefeng.roses.kernel.validator.api;
package cn.stylefeng.roses.kernel.security.api;
import cn.stylefeng.roses.kernel.validator.api.exception.CountValidateException;
import cn.stylefeng.roses.kernel.security.api.exception.CountValidateException;
/**
* andAPI

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.validator.api;
package cn.stylefeng.roses.kernel.security.api;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.validator.api.constants;
package cn.stylefeng.roses.kernel.security.api.constants;
/**
*

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.security.api.constants;
/**
*
*
* @author fengshuonan
* @date 2021/3/14 17:29
*/
public interface CounterConstants {
/**
*
*/
String COUNT_VALIDATE_CACHE_KEY_PREFIX = "COUNT_VALIDATE";
/**
*
*/
String BLACK_LIST_CACHE_KEY_PREFIX = "BLACK_LIST";
/**
*
*/
String WHITE_LIST_CACHE_KEY_PREFIX = "WHITE_LIST";
/**
*
*/
String RECORD_TIME_SECONDS = "RECORD_TIME_SECONDS";
/**
*
*/
String COUNT_NUMBER = "COUNT_NUMBER";
}

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kernel.validator.api.exception;
package cn.stylefeng.roses.kernel.security.api.exception;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
import cn.stylefeng.roses.kernel.security.api.constants.SecurityConstants;
/**
*
@ -14,11 +14,11 @@ import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
public class CountValidateException extends ServiceException {
public CountValidateException(AbstractExceptionEnum exception, Object... params) {
super(ValidatorConstants.VALIDATOR_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
super(SecurityConstants.SECURITY_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
}
public CountValidateException(AbstractExceptionEnum exception) {
super(ValidatorConstants.VALIDATOR_MODULE_NAME, exception);
super(SecurityConstants.SECURITY_MODULE_NAME, exception);
}
}

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kernel.validator.api.exception;
package cn.stylefeng.roses.kernel.security.api.exception;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
import cn.stylefeng.roses.kernel.security.api.constants.SecurityConstants;
/**
* XSS
@ -14,11 +14,11 @@ import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
public class XssFilterException extends ServiceException {
public XssFilterException(AbstractExceptionEnum exception, Object... params) {
super(ValidatorConstants.VALIDATOR_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
super(SecurityConstants.SECURITY_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
}
public XssFilterException(AbstractExceptionEnum exception) {
super(ValidatorConstants.VALIDATOR_MODULE_NAME, exception);
super(SecurityConstants.SECURITY_MODULE_NAME, exception);
}
}

View File

@ -1,8 +1,8 @@
package cn.stylefeng.roses.kernel.validator.api.exception.enums;
package cn.stylefeng.roses.kernel.security.api.exception.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
import cn.stylefeng.roses.kernel.security.api.constants.SecurityConstants;
import lombok.Getter;
/**
@ -17,12 +17,12 @@ public enum CountValidateExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
INTERRUPT_EXECUTION(RuleConstants.BUSINESS_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "01", "满足自定义策略要求,程序已中断执行!"),
INTERRUPT_EXECUTION(RuleConstants.BUSINESS_ERROR_TYPE_CODE + SecurityConstants.SECURITY_EXCEPTION_STEP_CODE + "01", "满足自定义策略要求,程序已中断执行!"),
/**
*
*/
TRAFFIC_LIMIT_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "02", "已触发限流机制,请稍后重新访问!");
TRAFFIC_LIMIT_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + SecurityConstants.SECURITY_EXCEPTION_STEP_CODE + "02", "已触发限流机制,请稍后重新访问!");
/**
*

View File

@ -1,8 +1,8 @@
package cn.stylefeng.roses.kernel.validator.api.exception.enums;
package cn.stylefeng.roses.kernel.security.api.exception.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
import cn.stylefeng.roses.kernel.security.api.constants.SecurityConstants;
import lombok.Getter;
/**
@ -17,7 +17,7 @@ public enum XssFilterExceptionEnum implements AbstractExceptionEnum {
/**
* XSS
*/
CONFIG_IS_NULL(RuleConstants.BUSINESS_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "11", "XSS初始化配置为空请检查XSS过滤器配置是否正确");
CONFIG_IS_NULL(RuleConstants.BUSINESS_ERROR_TYPE_CODE + SecurityConstants.SECURITY_EXCEPTION_STEP_CODE + "11", "XSS初始化配置为空请检查XSS过滤器配置是否正确");
/**
*

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.validator.api.pojo;
package cn.stylefeng.roses.kernel.security.api.pojo;
import lombok.Builder;
import lombok.Data;

View File

@ -6,18 +6,18 @@
<parent>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>kernel-d-validator</artifactId>
<artifactId>kernel-d-security</artifactId>
<version>7.0.1</version>
</parent>
<artifactId>validator-sdk-black-white</artifactId>
<artifactId>security-sdk-black-white</artifactId>
<dependencies>
<!--校验模块的api-->
<!--安全模块的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>validator-api</artifactId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kemel.validator.blackwhite;
package cn.stylefeng.roses.kemel.security.blackwhite;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.validator.api.BlackListApi;
import cn.stylefeng.roses.kernel.security.api.BlackListApi;
import java.util.Collection;

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kemel.validator.blackwhite;
package cn.stylefeng.roses.kemel.security.blackwhite;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.validator.api.WhiteListApi;
import cn.stylefeng.roses.kernel.security.api.WhiteListApi;
import java.util.Collection;

View File

@ -1,9 +1,8 @@
package cn.stylefeng.roses.kemel.validator.blackwhite.cache;
package cn.stylefeng.roses.kemel.security.blackwhite.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import static cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants.BLACK_LIST_CACHE_KEY_PREFIX;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
/**
*
@ -19,7 +18,7 @@ public class BlackListMemoryCache extends AbstractMemoryCacheOperator<String> {
@Override
public String getCommonKeyPrefix() {
return BLACK_LIST_CACHE_KEY_PREFIX;
return CounterConstants.BLACK_LIST_CACHE_KEY_PREFIX;
}
}

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kemel.validator.blackwhite.cache;
package cn.stylefeng.roses.kemel.security.blackwhite.cache;
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
import org.springframework.data.redis.core.RedisTemplate;
import static cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants.BLACK_LIST_CACHE_KEY_PREFIX;
/**
*
@ -19,7 +19,7 @@ public class BlackListRedisCache extends AbstractRedisCacheOperator<String> {
@Override
public String getCommonKeyPrefix() {
return BLACK_LIST_CACHE_KEY_PREFIX;
return CounterConstants.BLACK_LIST_CACHE_KEY_PREFIX;
}
}

View File

@ -1,9 +1,8 @@
package cn.stylefeng.roses.kemel.validator.blackwhite.cache;
package cn.stylefeng.roses.kemel.security.blackwhite.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import static cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants.WHITE_LIST_CACHE_KEY_PREFIX;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
/**
*
@ -19,7 +18,7 @@ public class WhiteListMemoryCache extends AbstractMemoryCacheOperator<String> {
@Override
public String getCommonKeyPrefix() {
return WHITE_LIST_CACHE_KEY_PREFIX;
return CounterConstants.WHITE_LIST_CACHE_KEY_PREFIX;
}
}

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kemel.validator.blackwhite.cache;
package cn.stylefeng.roses.kemel.security.blackwhite.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
import static cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants.WHITE_LIST_CACHE_KEY_PREFIX;
/**
*
@ -19,7 +19,7 @@ public class WhiteListRedisCache extends AbstractMemoryCacheOperator<Long> {
@Override
public String getCommonKeyPrefix() {
return WHITE_LIST_CACHE_KEY_PREFIX;
return CounterConstants.WHITE_LIST_CACHE_KEY_PREFIX;
}
}

View File

@ -6,18 +6,18 @@
<parent>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>kernel-d-validator</artifactId>
<artifactId>kernel-d-security</artifactId>
<version>7.0.1</version>
</parent>
<artifactId>validator-sdk-captcha</artifactId>
<artifactId>security-sdk-captcha</artifactId>
<dependencies>
<!--校验模块的api-->
<!--安全模块的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>validator-api</artifactId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>

View File

@ -1,10 +1,10 @@
package cn.stylefeng.roses.kemel.validator.captcha;
package cn.stylefeng.roses.kemel.security.captcha;
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.validator.api.CaptchaApi;
import cn.stylefeng.roses.kernel.validator.api.pojo.EasyCaptcha;
import cn.stylefeng.roses.kernel.security.api.CaptchaApi;
import cn.stylefeng.roses.kernel.security.api.pojo.EasyCaptcha;
import com.wf.captcha.SpecCaptcha;
/**

View File

@ -1,9 +1,8 @@
package cn.stylefeng.roses.kemel.validator.captcha.cache;
package cn.stylefeng.roses.kemel.security.captcha.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import static cn.stylefeng.roses.kernel.validator.api.constants.CaptchaConstants.CAPTCHA_CACHE_KEY_PREFIX;
import cn.stylefeng.roses.kernel.security.api.constants.CaptchaConstants;
/**
*
@ -19,6 +18,7 @@ public class CaptchaMemoryCache extends AbstractMemoryCacheOperator<String> {
@Override
public String getCommonKeyPrefix() {
return CAPTCHA_CACHE_KEY_PREFIX;
return CaptchaConstants.CAPTCHA_CACHE_KEY_PREFIX;
}
}

View File

@ -1,9 +1,8 @@
package cn.stylefeng.roses.kemel.validator.captcha.cache;
package cn.stylefeng.roses.kemel.security.captcha.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import static cn.stylefeng.roses.kernel.validator.api.constants.CaptchaConstants.CAPTCHA_CACHE_KEY_PREFIX;
import cn.stylefeng.roses.kernel.security.api.constants.CaptchaConstants;
/**
*
@ -19,7 +18,7 @@ public class CaptchaRedisCache extends AbstractMemoryCacheOperator<Long> {
@Override
public String getCommonKeyPrefix() {
return CAPTCHA_CACHE_KEY_PREFIX;
return CaptchaConstants.CAPTCHA_CACHE_KEY_PREFIX;
}
}

View File

@ -6,18 +6,18 @@
<parent>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>kernel-d-validator</artifactId>
<artifactId>kernel-d-security</artifactId>
<version>7.0.1</version>
</parent>
<artifactId>validator-sdk-count</artifactId>
<artifactId>security-sdk-count</artifactId>
<dependencies>
<!--校验模块的api-->
<!--安全模块的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>validator-api</artifactId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>

View File

@ -1,12 +1,12 @@
package cn.stylefeng.roses.kemel.validator.count;
package cn.stylefeng.roses.kemel.security.count;
import cn.hutool.core.convert.Convert;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
import cn.stylefeng.roses.kernel.validator.api.CountValidatorApi;
import cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants;
import cn.stylefeng.roses.kernel.validator.api.exception.CountValidateException;
import cn.stylefeng.roses.kernel.validator.api.exception.enums.CountValidateExceptionEnum;
import cn.stylefeng.roses.kernel.security.api.CountValidatorApi;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
import cn.stylefeng.roses.kernel.security.api.exception.CountValidateException;
import cn.stylefeng.roses.kernel.security.api.exception.enums.CountValidateExceptionEnum;
/**
*
@ -29,10 +29,10 @@ public class DefaultCountValidator implements CountValidatorApi {
long currentTimeSeconds = System.currentTimeMillis() / 1000;
// 上一次操作时间秒数的缓存key COUNT_VALIDATE:key:RECORD_SECONDS
String recordTimeSecondsKey = ValidatorConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX + CacheConstants.CACHE_DELIMITER + key + CacheConstants.CACHE_DELIMITER + ValidatorConstants.RECORD_TIME_SECONDS;
String recordTimeSecondsKey = CounterConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX + CacheConstants.CACHE_DELIMITER + key + CacheConstants.CACHE_DELIMITER + CounterConstants.RECORD_TIME_SECONDS;
// 上一次执行次数的记录缓存key COUNT_VALIDATE:key:COUNT_NUMBER
String countNumberKey = ValidatorConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX + CacheConstants.CACHE_DELIMITER + key + CacheConstants.CACHE_DELIMITER + ValidatorConstants.COUNT_NUMBER;
String countNumberKey = CounterConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX + CacheConstants.CACHE_DELIMITER + key + CacheConstants.CACHE_DELIMITER + CounterConstants.COUNT_NUMBER;
// 获取缓存中上一次操作时间秒数
Object recordTimeSecondsObject = cacheOperatorApi.get(recordTimeSecondsKey);

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kemel.validator.count.cache;
package cn.stylefeng.roses.kemel.security.count.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.security.api.constants.CounterConstants;
import static cn.stylefeng.roses.kernel.validator.api.constants.ValidatorConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX;
/**
*
@ -19,7 +19,7 @@ public class DefaultCountValidateCache extends AbstractMemoryCacheOperator<Long>
@Override
public String getCommonKeyPrefix() {
return COUNT_VALIDATE_CACHE_KEY_PREFIX;
return CounterConstants.COUNT_VALIDATE_CACHE_KEY_PREFIX;
}
}

View File

@ -24,6 +24,27 @@
<version>7.0.1</version>
</dependency>
<!--图形验证码模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-sdk-captcha</artifactId>
<version>7.0.1</version>
</dependency>
<!--count模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-sdk-count</artifactId>
<version>7.0.1</version>
</dependency>
<!--黑白名单校验-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-sdk-black-white</artifactId>
<version>7.0.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.security.starter;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kemel.security.captcha.CaptchaService;
import cn.stylefeng.roses.kemel.security.captcha.cache.CaptchaMemoryCache;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
import cn.stylefeng.roses.kernel.security.api.CaptchaApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @date 2020/12/1 21:44
*/
@Configuration
public class CaptchaAutoConfiguration {
/**
*
*
* @author chenjinlong
* @date 2021/1/15 11:25
*/
@Bean
@ConditionalOnMissingBean(CaptchaApi.class)
public CaptchaApi captchaApi() {
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
CaptchaMemoryCache captchaMemoryCache = new CaptchaMemoryCache(timedCache);
return new CaptchaService(captchaMemoryCache);
}
}

View File

@ -1,24 +1,21 @@
package cn.stylefeng.roses.kernel.validator.starter;
package cn.stylefeng.roses.kernel.security.starter;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kemel.validator.blackwhite.BlackListService;
import cn.stylefeng.roses.kemel.validator.blackwhite.WhiteListService;
import cn.stylefeng.roses.kemel.validator.blackwhite.cache.BlackListMemoryCache;
import cn.stylefeng.roses.kemel.validator.blackwhite.cache.WhiteListMemoryCache;
import cn.stylefeng.roses.kemel.validator.captcha.CaptchaService;
import cn.stylefeng.roses.kemel.validator.captcha.cache.CaptchaMemoryCache;
import cn.stylefeng.roses.kemel.validator.count.DefaultCountValidator;
import cn.stylefeng.roses.kemel.validator.count.cache.DefaultCountValidateCache;
import cn.stylefeng.roses.kernel.validator.api.BlackListApi;
import cn.stylefeng.roses.kernel.validator.api.CaptchaApi;
import cn.stylefeng.roses.kernel.validator.api.CountValidatorApi;
import cn.stylefeng.roses.kernel.validator.api.WhiteListApi;
import cn.stylefeng.roses.kemel.security.blackwhite.BlackListService;
import cn.stylefeng.roses.kemel.security.blackwhite.WhiteListService;
import cn.stylefeng.roses.kemel.security.blackwhite.cache.BlackListMemoryCache;
import cn.stylefeng.roses.kemel.security.blackwhite.cache.WhiteListMemoryCache;
import cn.stylefeng.roses.kemel.security.count.DefaultCountValidator;
import cn.stylefeng.roses.kemel.security.count.cache.DefaultCountValidateCache;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
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 org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants.NONE_EXPIRED_TIME;
/**
*
@ -38,7 +35,7 @@ public class ValidatorAutoConfiguration {
@Bean
@ConditionalOnMissingBean(BlackListApi.class)
public BlackListApi blackListApi() {
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(NONE_EXPIRED_TIME);
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
BlackListMemoryCache blackListMemoryCache = new BlackListMemoryCache(timedCache);
return new BlackListService(blackListMemoryCache);
}
@ -52,7 +49,7 @@ public class ValidatorAutoConfiguration {
@Bean
@ConditionalOnMissingBean(CountValidatorApi.class)
public CountValidatorApi countValidatorApi() {
TimedCache<String, Long> timedCache = CacheUtil.newTimedCache(NONE_EXPIRED_TIME);
TimedCache<String, Long> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
DefaultCountValidateCache defaultCountValidateCache = new DefaultCountValidateCache(timedCache);
return new DefaultCountValidator(defaultCountValidateCache);
}
@ -66,23 +63,9 @@ public class ValidatorAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WhiteListApi.class)
public WhiteListApi whiteListApi() {
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(NONE_EXPIRED_TIME);
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
WhiteListMemoryCache whiteListMemoryCache = new WhiteListMemoryCache(timedCache);
return new WhiteListService(whiteListMemoryCache);
}
/**
*
*
* @author chenjinlong
* @date 2021/1/15 11:25
*/
@Bean
@ConditionalOnMissingBean(CaptchaApi.class)
public CaptchaApi captchaApi() {
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(NONE_EXPIRED_TIME);
CaptchaMemoryCache captchaMemoryCache = new CaptchaMemoryCache(timedCache);
return new CaptchaService(captchaMemoryCache);
}
}

View File

@ -1,3 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.security.starter.GunsSecurityAutoConfiguration,\
cn.stylefeng.roses.kernel.security.starter.GunsXssAutoConfiguration
cn.stylefeng.roses.kernel.security.starter.GunsXssAutoConfiguration,\
cn.stylefeng.roses.kernel.security.starter.ValidatorAutoConfiguration,\
cn.stylefeng.roses.kernel.security.starter.CaptchaAutoConfiguration

View File

@ -47,6 +47,14 @@
<version>7.0.1</version>
</dependency>
<!--安全模块模块-->
<!--发送短信前的验证码校验,防止暴力发送短信-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>
<!--数据库sdk-->
<!--数据库dao框架-->
<dependency>

View File

@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.security.api.CaptchaApi;
import cn.stylefeng.roses.kernel.sms.api.SmsSenderApi;
import cn.stylefeng.roses.kernel.sms.api.exception.SmsException;
import cn.stylefeng.roses.kernel.sms.api.expander.SmsConfigExpander;
@ -19,7 +20,6 @@ import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.validator.api.CaptchaApi;
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -17,9 +17,6 @@
<modules>
<module>validator-api</module>
<module>validator-sdk-count</module>
<module>validator-sdk-black-white</module>
<module>validator-sdk-captcha</module>
<module>validator-spring-boot-starter</module>
</modules>

View File

@ -28,29 +28,4 @@ public interface ValidatorConstants {
*/
String DEFAULT_LOGIC_DELETE_FIELD_VALUE = "Y";
/**
*
*/
String COUNT_VALIDATE_CACHE_KEY_PREFIX = "COUNT_VALIDATE";
/**
*
*/
String BLACK_LIST_CACHE_KEY_PREFIX = "BLACK_LIST";
/**
*
*/
String WHITE_LIST_CACHE_KEY_PREFIX = "WHITE_LIST";
/**
*
*/
String RECORD_TIME_SECONDS = "RECORD_TIME_SECONDS";
/**
*
*/
String COUNT_NUMBER = "COUNT_NUMBER";
}

View File

@ -1,12 +0,0 @@
package cn.stylefeng.roses.kernel.validator.api.expander;
/**
* XSS
*
* @author fengshuonan
* @date 2021/1/13 23:21
*/
public class XssConfigExpander {
}

View File

@ -1,3 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.validator.starter.ValidatorAutoConfiguration,\
cn.stylefeng.roses.kernel.validator.starter.MethodArgumentResolverAutoConfiguration

View File

@ -62,6 +62,14 @@
<version>7.0.1</version>
</dependency>
<!--安全模块api-->
<!--用在图形验证码-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-api</artifactId>
<version>7.0.1</version>
</dependency>
<!--缓存api-->
<!--用户的查询会使用缓存-->
<dependency>

View File

@ -5,7 +5,7 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.validator.api.CaptchaApi;
import cn.stylefeng.roses.kernel.security.api.CaptchaApi;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;