【8.1.9】【security】安全日志增加次数校验

dev-8.1.9
stylefeng 2024-07-11 23:28:11 +08:00
parent 0e108a99e8
commit 245ff20526
3 changed files with 25 additions and 0 deletions

View File

@ -47,4 +47,9 @@ public interface LogConstants {
*/
String LOG_DEFAULT_APP_NAME = "none-app-name";
/**
*
*/
String VALIDATE_COUNT_PREFIX = "SEC_LOG_";
}

View File

@ -17,6 +17,13 @@
<dependencies>
<!--系统安全的api-->
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>security-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--日志api模块-->
<dependency>
<groupId>com.javaguns.roses</groupId>

View File

@ -11,14 +11,19 @@ import cn.stylefeng.roses.kernel.log.security.enums.LogSecurityExceptionEnum;
import cn.stylefeng.roses.kernel.log.security.mapper.LogSecurityMapper;
import cn.stylefeng.roses.kernel.log.security.service.LogSecurityService;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
import cn.stylefeng.roses.kernel.security.api.CountValidatorApi;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import static cn.stylefeng.roses.kernel.log.api.constants.LogConstants.VALIDATE_COUNT_PREFIX;
/**
*
*
@ -28,8 +33,16 @@ import java.util.List;
@Service
public class LogSecurityServiceImpl extends ServiceImpl<LogSecurityMapper, LogSecurity> implements LogSecurityService {
@Resource
private CountValidatorApi countValidatorApi;
@Override
public void add(LogSecurityRequest logSecurityRequest) {
// 同一个IP一个小时内不能超过100条防止刷接口
countValidatorApi.countAndValidate(VALIDATE_COUNT_PREFIX + HttpServletUtil.getRequestClientIp(HttpServletUtil.getRequest()),
3600L, 100L);
LogSecurity logSecurity = new LogSecurity();
BeanUtil.copyProperties(logSecurityRequest, logSecurity);
this.save(logSecurity);