操作日志记录支持排除敏感属性字段

pull/229/head
RuoYi 2 years ago
parent 428255ddcf
commit d6df1fe7b3

@ -21,6 +21,7 @@ import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessStatus;
import com.ruoyi.common.log.filter.PropertyPreExcludeFilter;
import com.ruoyi.common.log.service.AsyncLogService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysOperLog;
@ -35,7 +36,10 @@ import com.ruoyi.system.api.domain.SysOperLog;
public class LogAspect
{
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
/** 排除敏感属性字段 */
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
@Autowired
private AsyncLogService asyncLogService;
@ -162,7 +166,7 @@ public class LogAspect
{
try
{
Object jsonObj = JSON.toJSON(o);
String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter());
params += jsonObj.toString() + " ";
}
catch (Exception e)
@ -174,6 +178,14 @@ public class LogAspect
return params.trim();
}
/**
*
*/
public PropertyPreExcludeFilter excludePropertyPreFilter()
{
return new PropertyPreExcludeFilter().addExcludes(EXCLUDE_PROPERTIES);
}
/**
*
*

@ -0,0 +1,24 @@
package com.ruoyi.common.log.filter;
import com.alibaba.fastjson2.filter.SimplePropertyPreFilter;
/**
* JSON
*
* @author ruoyi
*/
public class PropertyPreExcludeFilter extends SimplePropertyPreFilter
{
public PropertyPreExcludeFilter()
{
}
public PropertyPreExcludeFilter addExcludes(String... filters)
{
for (int i = 0; i < filters.length; i++)
{
this.getExcludes().add(filters[i]);
}
return this;
}
}
Loading…
Cancel
Save