mirror of https://gitee.com/stylefeng/roses
【8.1.9】【安全日志】更新日志记录报错的提示
parent
245ff20526
commit
7e83fc7d4f
|
@ -4,6 +4,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
|
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.log.api.SecurityLogServiceApi;
|
import cn.stylefeng.roses.kernel.log.api.SecurityLogServiceApi;
|
||||||
import cn.stylefeng.roses.kernel.log.api.pojo.security.LogSecurityRequest;
|
import cn.stylefeng.roses.kernel.log.api.pojo.security.LogSecurityRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
@ -15,6 +16,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @since 2024/7/10 17:25
|
* @since 2024/7/10 17:25
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class AsyncLogManager {
|
public class AsyncLogManager {
|
||||||
|
|
||||||
// 异步操作记录日志的线程池
|
// 异步操作记录日志的线程池
|
||||||
|
@ -51,8 +53,12 @@ public class AsyncLogManager {
|
||||||
this.executeLog(new TimerTask() {
|
this.executeLog(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LoginLogServiceApi loginLogServiceApi = SpringUtil.getBean(LoginLogServiceApi.class);
|
try {
|
||||||
loginLogServiceApi.loginFail(account);
|
LoginLogServiceApi loginLogServiceApi = SpringUtil.getBean(LoginLogServiceApi.class);
|
||||||
|
loginLogServiceApi.loginFail(account);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("记录登录失败日志异常!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,8 +73,12 @@ public class AsyncLogManager {
|
||||||
this.executeLog(new TimerTask() {
|
this.executeLog(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SecurityLogServiceApi securityLogServiceApi = SpringUtil.getBean(SecurityLogServiceApi.class);
|
try {
|
||||||
securityLogServiceApi.add(logSecurityRequest);
|
SecurityLogServiceApi securityLogServiceApi = SpringUtil.getBean(SecurityLogServiceApi.class);
|
||||||
|
securityLogServiceApi.add(logSecurityRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("记录安全日志异常!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ 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.mapper.LogSecurityMapper;
|
||||||
import cn.stylefeng.roses.kernel.log.security.service.LogSecurityService;
|
import cn.stylefeng.roses.kernel.log.security.service.LogSecurityService;
|
||||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
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 cn.stylefeng.roses.kernel.security.api.CountValidatorApi;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -40,7 +39,7 @@ public class LogSecurityServiceImpl extends ServiceImpl<LogSecurityMapper, LogSe
|
||||||
public void add(LogSecurityRequest logSecurityRequest) {
|
public void add(LogSecurityRequest logSecurityRequest) {
|
||||||
|
|
||||||
// 同一个IP一个小时内不能超过100条,防止刷接口
|
// 同一个IP一个小时内不能超过100条,防止刷接口
|
||||||
countValidatorApi.countAndValidate(VALIDATE_COUNT_PREFIX + HttpServletUtil.getRequestClientIp(HttpServletUtil.getRequest()),
|
countValidatorApi.countAndValidate(VALIDATE_COUNT_PREFIX + logSecurityRequest.getClientIp(),
|
||||||
3600L, 100L);
|
3600L, 100L);
|
||||||
|
|
||||||
LogSecurity logSecurity = new LogSecurity();
|
LogSecurity logSecurity = new LogSecurity();
|
||||||
|
|
Loading…
Reference in New Issue