|
@@ -1,7 +1,9 @@
|
|
package com.jpsoft.picc.advice;
|
|
package com.jpsoft.picc.advice;
|
|
|
|
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.picc.modules.sys.entity.SysLog;
|
|
import com.jpsoft.picc.modules.sys.service.PermissionService;
|
|
import com.jpsoft.picc.modules.sys.service.PermissionService;
|
|
|
|
+import com.jpsoft.picc.modules.sys.service.SysLogService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
@@ -18,6 +20,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Aspect
|
|
@Aspect
|
|
@@ -26,6 +29,9 @@ public class PermissionAdvice {
|
|
@Autowired
|
|
@Autowired
|
|
private PermissionService permissionService;
|
|
private PermissionService permissionService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysLogService sysLogService;
|
|
|
|
+
|
|
@Pointcut("(execution(public * com.jpsoft.picc..controller.*.*(..)))")
|
|
@Pointcut("(execution(public * com.jpsoft.picc..controller.*.*(..)))")
|
|
public void pointcut(){
|
|
public void pointcut(){
|
|
|
|
|
|
@@ -72,8 +78,15 @@ public class PermissionAdvice {
|
|
|
|
|
|
Object obj = null;
|
|
Object obj = null;
|
|
|
|
|
|
|
|
+ SysLog sysLog = new SysLog();
|
|
|
|
+
|
|
if(requestAttrs!=null) {
|
|
if(requestAttrs!=null) {
|
|
HttpServletRequest request = requestAttrs.getRequest();
|
|
HttpServletRequest request = requestAttrs.getRequest();
|
|
|
|
+ String remoteIP = request.getHeader("remote_addr");
|
|
|
|
+
|
|
|
|
+ sysLog.setRemoteIp(remoteIP);
|
|
|
|
+ sysLog.setUrl(request.getRequestURI());
|
|
|
|
+
|
|
log.warn("访问地址:" + request.getRequestURL().toString());
|
|
log.warn("访问地址:" + request.getRequestURL().toString());
|
|
log.warn("path=" + pathBuilder.toString());
|
|
log.warn("path=" + pathBuilder.toString());
|
|
|
|
|
|
@@ -90,14 +103,23 @@ public class PermissionAdvice {
|
|
|
|
|
|
if(args[i] != null) {
|
|
if(args[i] != null) {
|
|
String value = args[i].toString();
|
|
String value = args[i].toString();
|
|
- value = value.length() > 255 ? value.substring(0, 255) : value;
|
|
|
|
|
|
+ value = value.length() > 100 ? value.substring(0, 100) : value;
|
|
|
|
+
|
|
|
|
+ if (parameterNames[i].equals("password")){
|
|
|
|
+ value = "******";
|
|
|
|
+ }
|
|
|
|
+
|
|
argBuilder.append(parameterNames[i] + "=" + value);
|
|
argBuilder.append(parameterNames[i] + "=" + value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- log.warn(argBuilder.toString());
|
|
|
|
|
|
+// log.warn(argBuilder.toString());
|
|
|
|
+ sysLog.setData(argBuilder.toString());
|
|
|
|
|
|
String userId = (String)request.getAttribute("subject");
|
|
String userId = (String)request.getAttribute("subject");
|
|
|
|
+ sysLog.setUserId(userId);
|
|
|
|
+
|
|
|
|
+ sysLog.setCreateTime(new Date());
|
|
|
|
|
|
boolean existed = permissionService.exist(pathBuilder.toString(), request.getMethod());
|
|
boolean existed = permissionService.exist(pathBuilder.toString(), request.getMethod());
|
|
|
|
|
|
@@ -109,10 +131,14 @@ public class PermissionAdvice {
|
|
log.warn("是否许可当前用户访问:" + permitted);
|
|
log.warn("是否许可当前用户访问:" + permitted);
|
|
|
|
|
|
if(permitted){
|
|
if(permitted){
|
|
|
|
+ sysLog.setRemark("已授权当前用户访问");
|
|
|
|
+
|
|
// 执行切入方法
|
|
// 执行切入方法
|
|
obj = point.proceed();
|
|
obj = point.proceed();
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
|
|
+ sysLog.setRemark("未授权当前用户访问!");
|
|
|
|
+
|
|
MessageResult<String> msgResult = new MessageResult<>();
|
|
MessageResult<String> msgResult = new MessageResult<>();
|
|
msgResult.setCode(401);
|
|
msgResult.setCode(401);
|
|
msgResult.setResult(false);
|
|
msgResult.setResult(false);
|
|
@@ -123,6 +149,7 @@ public class PermissionAdvice {
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
log.warn(pathBuilder.toString() + "未加入权限控制");
|
|
log.warn(pathBuilder.toString() + "未加入权限控制");
|
|
|
|
+ sysLog.setRemark("当前url未加入权限控制");
|
|
|
|
|
|
// 执行切入方法
|
|
// 执行切入方法
|
|
obj = point.proceed();
|
|
obj = point.proceed();
|
|
@@ -133,6 +160,10 @@ public class PermissionAdvice {
|
|
|
|
|
|
System.out.println(classType);
|
|
System.out.println(classType);
|
|
log.warn(String.format("调用类%s方法%s耗时%s毫秒",clazzSimpleName,methodName,elapse));
|
|
log.warn(String.format("调用类%s方法%s耗时%s毫秒",clazzSimpleName,methodName,elapse));
|
|
|
|
+ sysLog.setElapse(elapse);
|
|
|
|
+ sysLog.setPointcut(clazzSimpleName + "->" + methodName);
|
|
|
|
+
|
|
|
|
+ sysLogService.insert(sysLog);
|
|
|
|
|
|
return obj;
|
|
return obj;
|
|
}
|
|
}
|