| | |
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.validation.BindingResult;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.servlet.HandlerMapping;
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.ruoyi.common.enums.HttpMethod;
|
| | | import com.ruoyi.common.filter.PropertyPreExcludeFilter;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
| | | public class LogAspect
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
| | |
|
| | | /** 排除敏感属性字段 */
|
| | | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
| | |
|
| | | /**
|
| | | * 处理完请求后执行
|
| | |
| | | // 请求的地址
|
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
| | | operLog.setOperIp(ip);
|
| | | operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
| | | operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
|
| | | if (loginUser != null)
|
| | | {
|
| | | operLog.setOperName(loginUser.getUsername());
|
| | |
| | | catch (Exception exp)
|
| | | {
|
| | | // 记录本地异常日志
|
| | | log.error("==前置通知异常==");
|
| | | log.error("异常信息:{}", exp.getMessage());
|
| | | exp.printStackTrace();
|
| | | }
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
| | | operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
|
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000));
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | try
|
| | | {
|
| | | Object jsonObj = JSON.toJSON(o);
|
| | | String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter());
|
| | | params += jsonObj.toString() + " ";
|
| | | }
|
| | | catch (Exception e)
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 忽略敏感属性
|
| | | */
|
| | | public PropertyPreExcludeFilter excludePropertyPreFilter()
|
| | | {
|
| | | return new PropertyPreExcludeFilter().addExcludes(EXCLUDE_PROPERTIES);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 判断是否需要过滤的对象。
|
| | | *
|
| | | * @param o 对象信息。
|