update
This commit is contained in:
@@ -9,20 +9,15 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.jeecg.common.api.dto.LogDTO;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.enums.ModuleType;
|
||||
import org.jeecg.common.constant.enums.OperateTypeEnum;
|
||||
import org.jeecg.common.constant.enums.*;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.IpUtils;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.modules.base.service.BaseCommonService;
|
||||
import org.springframework.core.StandardReflectionParameterNameDiscoverer;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -32,7 +27,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志,切面处理类
|
||||
*
|
||||
@@ -88,7 +82,6 @@ public class AutoLogAspect {
|
||||
String methodName = signature.getName();
|
||||
dto.setMethod(className + "." + methodName + "()");
|
||||
|
||||
|
||||
//设置操作类型
|
||||
if (CommonConstant.LOG_TYPE_2 == dto.getLogType()) {
|
||||
dto.setOperateType(getOperateType(methodName, syslog.operateType()));
|
||||
@@ -110,11 +103,20 @@ public class AutoLogAspect {
|
||||
//耗时
|
||||
dto.setCostTime(time);
|
||||
dto.setCreateTime(new Date());
|
||||
try {
|
||||
//设置客户端
|
||||
if (BrowserUtils.isDesktop(request)) {
|
||||
dto.setClientType(ClientTerminalTypeEnum.PC.getKey());
|
||||
} else {
|
||||
dto.setClientType(ClientTerminalTypeEnum.APP.getKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
//保存系统日志
|
||||
baseCommonService.addLog(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取操作类型
|
||||
*/
|
||||
@@ -138,15 +140,20 @@ public class AutoLogAspect {
|
||||
private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint) {
|
||||
String httpMethod = request.getMethod();
|
||||
String params = "";
|
||||
if (CommonConstant.HTTP_POST.equals(httpMethod) || CommonConstant.HTTP_PUT.equals(httpMethod) || CommonConstant.HTTP_PATCH.equals(httpMethod)) {
|
||||
if (CommonConstant.HTTP_POST.equals(httpMethod) || CommonConstant.HTTP_PUT.equals(httpMethod) || CommonConstant.HTTP_PATCH.equals(
|
||||
httpMethod)) {
|
||||
Object[] paramsArray = joinPoint.getArgs();
|
||||
// java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
||||
// java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e
|
||||
// . isAsyncStarted() returns false)
|
||||
// https://my.oschina.net/mengzhang6/blog/2395893
|
||||
Object[] arguments = new Object[paramsArray.length];
|
||||
for (int i = 0; i < paramsArray.length; i++) {
|
||||
if (paramsArray[i] instanceof BindingResult || paramsArray[i] instanceof ServletRequest || paramsArray[i] instanceof ServletResponse || paramsArray[i] instanceof MultipartFile) {
|
||||
//ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
||||
//ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
|
||||
if (paramsArray[i] instanceof BindingResult || paramsArray[i] instanceof ServletRequest
|
||||
|| paramsArray[i] instanceof ServletResponse || paramsArray[i] instanceof MultipartFile) {
|
||||
//ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current
|
||||
// request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
||||
//ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for
|
||||
// this response
|
||||
continue;
|
||||
}
|
||||
arguments[i] = paramsArray[i];
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.jeecg.modules.base.service;
|
||||
import org.jeecg.common.api.dto.LogDTO;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* common接口
|
||||
*
|
||||
@@ -25,7 +27,7 @@ public interface BaseCommonService {
|
||||
* @param operateType
|
||||
* @param user
|
||||
*/
|
||||
void addLog(String logContent, Integer logType, Integer operateType, LoginUser user);
|
||||
void addLog(String logContent, Integer logType, Integer operateType, LoginUser user, Date beginTime);
|
||||
|
||||
/**
|
||||
* 保存日志
|
||||
|
||||
@@ -8,10 +8,7 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.dto.LogDTO;
|
||||
import org.jeecg.common.constant.enums.ClientTerminalTypeEnum;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.BrowserUtils;
|
||||
import org.jeecg.common.util.IpUtils;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.modules.base.mapper.BaseCommonMapper;
|
||||
import org.jeecg.modules.base.service.BaseCommonService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -45,7 +42,7 @@ public class BaseCommonServiceImpl implements BaseCommonService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user) {
|
||||
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user, Date beginTime) {
|
||||
LogDTO sysLog = new LogDTO();
|
||||
sysLog.setId(String.valueOf(IdWorker.getId()));
|
||||
//注解上的描述,操作日志内容
|
||||
@@ -84,6 +81,7 @@ public class BaseCommonServiceImpl implements BaseCommonService {
|
||||
sysLog.setUsername(user.getRealname());
|
||||
}
|
||||
sysLog.setCreateTime(new Date());
|
||||
sysLog.setCostTime(System.currentTimeMillis() - beginTime.getTime());
|
||||
//保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
|
||||
try {
|
||||
baseCommonMapper.saveLog(sysLog);
|
||||
@@ -95,8 +93,7 @@ public class BaseCommonServiceImpl implements BaseCommonService {
|
||||
|
||||
@Override
|
||||
public void addLog(String logContent, Integer logType, Integer operateType) {
|
||||
addLog(logContent, logType, operateType, null);
|
||||
addLog(logContent, logType, operateType, null, new Date());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.constant.*;
|
||||
import org.jeecg.common.constant.enums.DySmsEnum;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
@@ -24,9 +22,7 @@ import org.jeecg.common.util.*;
|
||||
import org.jeecg.common.util.encryption.EncryptedString;
|
||||
import org.jeecg.config.JeecgBaseConfig;
|
||||
import org.jeecg.modules.base.service.BaseCommonService;
|
||||
import org.jeecg.modules.system.entity.SysDepart;
|
||||
import org.jeecg.modules.system.entity.SysRoleIndex;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.entity.*;
|
||||
import org.jeecg.modules.system.model.SysLoginModel;
|
||||
import org.jeecg.modules.system.service.*;
|
||||
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
|
||||
@@ -46,25 +42,25 @@ import java.util.*;
|
||||
@Tag(name = "用户登录")
|
||||
@Slf4j
|
||||
public class LoginController {
|
||||
private final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
|
||||
private final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysPermissionService sysPermissionService;
|
||||
private ISysPermissionService sysPermissionService;
|
||||
@Autowired
|
||||
private SysBaseApiImpl sysBaseApi;
|
||||
private SysBaseApiImpl sysBaseApi;
|
||||
@Autowired
|
||||
private ISysLogService logService;
|
||||
private ISysLogService logService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
private ISysDictService sysDictService;
|
||||
@Resource
|
||||
private BaseCommonService baseCommonService;
|
||||
private BaseCommonService baseCommonService;
|
||||
@Autowired
|
||||
private JeecgBaseConfig jeecgBaseConfig;
|
||||
private JeecgBaseConfig jeecgBaseConfig;
|
||||
|
||||
@Operation(summary = "登录接口")
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
@@ -78,24 +74,25 @@ public class LoginController {
|
||||
}
|
||||
|
||||
// step.1 验证码check
|
||||
// String captcha = sysLoginModel.getCaptcha();
|
||||
// if(captcha==null){
|
||||
// result.error500("验证码无效");
|
||||
// return result;
|
||||
// }
|
||||
// String lowerCaseCaptcha = captcha.toLowerCase();
|
||||
// // 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
|
||||
// String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();
|
||||
// String realKey = Md5Util.md5Encode(origin, "utf-8");
|
||||
// Object checkCode = redisUtil.get(realKey);
|
||||
// //当进入登录页时,有一定几率出现验证码错误 #1714
|
||||
// if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
|
||||
// log.warn("验证码错误,key= {} , Ui checkCode= {}, Redis checkCode = {}", sysLoginModel.getCheckKey(), lowerCaseCaptcha, checkCode);
|
||||
// result.error500("验证码错误");
|
||||
// // 改成特殊的code 便于前端判断
|
||||
// result.setCode(HttpStatus.PRECONDITION_FAILED.value());
|
||||
// return result;
|
||||
// }
|
||||
// String captcha = sysLoginModel.getCaptcha();
|
||||
// if(captcha==null){
|
||||
// result.error500("验证码无效");
|
||||
// return result;
|
||||
// }
|
||||
// String lowerCaseCaptcha = captcha.toLowerCase();
|
||||
// // 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
|
||||
// String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();
|
||||
// String realKey = Md5Util.md5Encode(origin, "utf-8");
|
||||
// Object checkCode = redisUtil.get(realKey);
|
||||
// //当进入登录页时,有一定几率出现验证码错误 #1714
|
||||
// if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
|
||||
// log.warn("验证码错误,key= {} , Ui checkCode= {}, Redis checkCode = {}", sysLoginModel.getCheckKey(), lowerCaseCaptcha,
|
||||
// checkCode);
|
||||
// result.error500("验证码错误");
|
||||
// // 改成特殊的code 便于前端判断
|
||||
// result.setCode(HttpStatus.PRECONDITION_FAILED.value());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// step.2 校验用户是否存在且有效
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -119,17 +116,16 @@ public class LoginController {
|
||||
userInfo(sysUser, result, request);
|
||||
|
||||
// step.5 登录成功删除验证码
|
||||
// redisUtil.del(realKey);
|
||||
// redisUtil.del(realKey);
|
||||
redisUtil.del(CommonConstant.LOGIN_FAIL + username);
|
||||
|
||||
// step.6 记录用户登录日志
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser);
|
||||
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser, new Date());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 【vue3专用】获取用户信息
|
||||
*/
|
||||
@@ -189,7 +185,7 @@ public class LoginController {
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
if (sysUser != null) {
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登出日志没有记录人员
|
||||
baseCommonService.addLog("用户名: " + sysUser.getRealname() + ",退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser);
|
||||
baseCommonService.addLog("用户名: " + sysUser.getRealname() + ",退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser,new Date());
|
||||
//update-end--Author:wangshuai Date:20200714 for:登出日志没有记录人员
|
||||
log.info(" 用户名: " + sysUser.getRealname() + ",退出成功! ");
|
||||
//清空用户登录Token缓存
|
||||
@@ -260,7 +256,6 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登陆成功选择用户当前部门
|
||||
*
|
||||
@@ -396,7 +391,6 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手机号登录接口
|
||||
*
|
||||
@@ -441,7 +435,6 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
@@ -698,7 +691,6 @@ public class LoginController {
|
||||
return Result.OK("扫码成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户扫码后保存的token
|
||||
*/
|
||||
@@ -808,7 +800,6 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 图形验证码
|
||||
*
|
||||
|
||||
@@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description: 在线用户
|
||||
@@ -112,7 +109,7 @@ public class SysUserOnlineController {
|
||||
String username = JwtUtil.getUsername(online.getToken());
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
if (sysUser != null) {
|
||||
baseCommonService.addLog("强制: " + sysUser.getRealname() + "退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser);
|
||||
baseCommonService.addLog("强制: " + sysUser.getRealname() + "退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser,new Date());
|
||||
log.info(" 强制 " + sysUser.getRealname() + "退出成功! ");
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + online.getToken());
|
||||
|
||||
Reference in New Issue
Block a user