mirror of https://gitee.com/stylefeng/roses
【8.1.9】【security】安全日志增加次数校验
parent
0e108a99e8
commit
245ff20526
|
@ -47,4 +47,9 @@ public interface LogConstants {
|
|||
*/
|
||||
String LOG_DEFAULT_APP_NAME = "none-app-name";
|
||||
|
||||
/**
|
||||
* 记录安全日志的前缀
|
||||
*/
|
||||
String VALIDATE_COUNT_PREFIX = "SEC_LOG_";
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue