| | |
| | | String fullClassName = signature.getDeclaringTypeName(); |
| | | |
| | | Integer operationType = 0; |
| | | String operationTypeName = null; |
| | | if(methodName.contains("update")){ |
| | | String operationTypeName = null; |
| | | String operationTypeNameEn = null; |
| | | if (methodName.contains("update")) { |
| | | //提取单项-修改配置 |
| | | if(fullClassName.contains("pageParam")){ |
| | | if (fullClassName.contains("pageParam")) { |
| | | operationTypeName = UserOperation.TYPE_PARAM_CHANGE.getTypeName(); |
| | | operationTypeNameEn = UserOperation.TYPE_PARAM_CHANGE.getTypeNameEn(); |
| | | operationType = UserOperation.TYPE_PARAM_CHANGE.getType(); |
| | | } |
| | | //提取单项-密码修改 |
| | | else if(fullClassName.contains("updatePassword")){ |
| | | else if (fullClassName.contains("updatePassword")) { |
| | | operationTypeName = UserOperation.TYPE_PASSWORD_CHANGE.getTypeName(); |
| | | operationTypeNameEn = UserOperation.TYPE_PASSWORD_CHANGE.getTypeNameEn(); |
| | | operationType = UserOperation.TYPE_PASSWORD_CHANGE.getType(); |
| | | } |
| | | else { |
| | | } else { |
| | | operationTypeName = UserOperation.TYPE_UPDATE.getTypeName(); |
| | | operationTypeNameEn = UserOperation.TYPE_UPDATE.getTypeNameEn(); |
| | | operationType = UserOperation.TYPE_UPDATE.getType(); |
| | | } |
| | | }else if (methodName.contains("add")){ |
| | | operationTypeName = UserOperation.TYPE_ADD.getTypeName(); |
| | | operationTypeNameEn = UserOperation.TYPE_ADD.getTypeNameEn(); |
| | | operationType = UserOperation.TYPE_ADD.getType(); |
| | | }else if (methodName.contains("delete")){ |
| | | operationTypeName = UserOperation.TYPE_DELETE.getTypeName(); |
| | | operationTypeNameEn = UserOperation.TYPE_DELETE.getTypeNameEn(); |
| | | operationType = UserOperation.TYPE_DELETE.getType(); |
| | | }/*else if (methodName.contains("login")){ |
| | | operationTypeName = UserOperation.TYPE_LOGIN.getTypeName(); |
| | |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (!lang.contains("zh")) { |
| | | operationMsg = "executed:" + className + " operation"; |
| | | operationMsg = "executed:" + className + " " + operationTypeNameEn + " operation "; |
| | | operationDetail = "Specific calling method is " + methodName + ",Specific parameters are " + map.toString(); |
| | | } |
| | | service.record(uId, operationType, operationTime, terminalIp, operationMsg, operationDetail); |
| | |
| | | package com.whyc.constant; |
| | | |
| | | /**用户操作类型*/ |
| | | /** |
| | | * 用户操作类型 |
| | | */ |
| | | public enum UserOperation { |
| | | /**操作类型*/ |
| | | TYPE_LOGIN(1,"登录系统"), |
| | | TYPE_LOGOUT(2,"登出系统"), |
| | | TYPE_ADD(3,"新增"), |
| | | TYPE_UPDATE(4,"修改"), |
| | | TYPE_DELETE(5,"删除"), |
| | | TYPE_CANCEL(7,"取消"), |
| | | TYPE_STOP(9,"终止"), |
| | | /** |
| | | * 操作类型 |
| | | */ |
| | | TYPE_LOGIN(1, "登录系统", "LOGIN"), |
| | | TYPE_LOGOUT(2, "登出系统", "LOGOUT"), |
| | | TYPE_ADD(3, "新增", "ADD"), |
| | | TYPE_UPDATE(4, "修改", "UPDATE"), |
| | | TYPE_DELETE(5, "删除", "DELETE"), |
| | | TYPE_CANCEL(7, "取消", "CANCEL"), |
| | | TYPE_STOP(9, "终止", "STOP"), |
| | | |
| | | TYPE_UNRECOGNIZED(-1,"无法识别的操作类型"), |
| | | |
| | | TYPE_UNAUTHORIZED_ACCESS(20,"越权访问"), |
| | | TYPE_EXCEPTION(21,"调用异常"), |
| | | TYPE_UNRECOGNIZED(-1, "无法识别的操作类型", "UNRECOGNIZED"), |
| | | |
| | | /**追加的系统级操作类型*/ |
| | | TYPE_LOGIN_FAIL(31,"登录失败"), |
| | | TYPE_PARAM_CHANGE(32,"参数变更"), |
| | | TYPE_PASSWORD_CHANGE(33,"密码修改"), |
| | | TYPE_LOGIN_TIMEOUT(34,"登录超时"), |
| | | TYPE_LOGIN_NO_PASS(35,"登录系统-用户ID登录"); |
| | | TYPE_UNAUTHORIZED_ACCESS(20, "越权访问", "UNAUTHORIZED_ACCESS"), |
| | | TYPE_EXCEPTION(21, "调用异常", "EXCEPTION"), |
| | | |
| | | /** |
| | | * 追加的系统级操作类型 |
| | | */ |
| | | TYPE_LOGIN_FAIL(31, "登录失败", "LOGIN_FAIL"), |
| | | TYPE_PARAM_CHANGE(32, "参数变更", "PARAM_CHANGE"), |
| | | TYPE_PASSWORD_CHANGE(33, "密码修改", "PASSWORD_CHANGE"), |
| | | TYPE_LOGIN_TIMEOUT(34, "登录超时", "LOGIN_TIMEOUT"), |
| | | TYPE_LOGIN_NO_PASS(35, "登录系统-用户ID登录", "LOGIN_NO_PASS"); |
| | | |
| | | |
| | | private Integer type; |
| | | private String typeName; |
| | | private String typeNameEn; |
| | | |
| | | UserOperation(Integer type, String typeName) { |
| | | UserOperation(Integer type, String typeName, String typeNameEn) { |
| | | this.type = type; |
| | | this.typeName = typeName; |
| | | this.typeNameEn = typeNameEn; |
| | | } |
| | | |
| | | public Integer getType() { |
| | |
| | | public void setTypeName(String typeName) { |
| | | this.typeName = typeName; |
| | | } |
| | | |
| | | public String getTypeNameEn() { |
| | | return typeNameEn; |
| | | } |
| | | |
| | | public void setTypeNameEn(String typeNameEn) { |
| | | this.typeNameEn = typeNameEn; |
| | | } |
| | | } |
| | |
| | | public Response sendErrorResponse2Defined(Exception e, HttpServletResponse response, HttpServletRequest request){ |
| | | String exceptionStr = e.toString(); |
| | | String requestURI = request.getRequestURI(); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | //单项提取-登录超时 |
| | | if(exceptionStr.contains("login") && exceptionStr.contains("imeout")){ |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(),"登录请求超时","异常信息:"+ exceptionStr); |
| | | }else { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), "接口调用异常:调用接口"+requestURI+"发生错误:"+exceptionStr); |
| | | if (exceptionStr.contains("login") && exceptionStr.contains("imeout")) { |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(), "登录请求超时", "异常信息:" + exceptionStr); |
| | | } else { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(), UserOperation.TYPE_LOGIN_TIMEOUT.getTypeNameEn(), "exception message:" + exceptionStr); |
| | | } |
| | | } else { |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr); |
| | | } else { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), UserOperation.TYPE_EXCEPTION.getTypeNameEn() + "Call Interface:" + requestURI + "error occurred:" + exceptionStr); |
| | | } |
| | | } |
| | | return new Response().setII(0,"接口请求异常,请联系软件人员进行处理.异常信息"+ exceptionStr); |
| | | return new Response().setII(0, "接口请求异常,请联系软件人员进行处理.异常信息" + exceptionStr); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | //查询账号密码错误限制次数 |
| | | PageParam loginFailTimesLimit = pageParamMapper.findByCategoryId(9).get(0); |
| | | if((++loginFailTimes)==loginFailTimesLimit.getStatus()){ |
| | | if ((++loginFailTimes) == loginFailTimesLimit.getStatus()) { |
| | | //达到限制次数,锁定账号 |
| | | //userService.lock(subject.getUId()); |
| | | //清除登录错误次数统计 |
| | | loginFailAttributeList.forEach(servletContext::removeAttribute); |
| | | }else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_"+System.currentTimeMillis(), 0); |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | |
| | | return response.set(1, false, "密码错误"); |
| | | } |
| | | return response.set(1, false, message); |
| | |
| | | //查询激活的地图 |
| | | String mapName = mapOutlineService.selectMapName(); |
| | | dataList.add(mapName); |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response().set(1,false,"认证未通过"); |
| | |
| | | } |
| | | //查询账号密码错误限制次数 |
| | | PageParam loginFailTimesLimit = pageParamMapper.findByCategoryId(9).get(0); |
| | | if((++loginFailTimes)==loginFailTimesLimit.getStatus()){ |
| | | if ((++loginFailTimes) == loginFailTimesLimit.getStatus()) { |
| | | //达到限制次数,锁定账号 |
| | | //userService.lock(subject.getUId()); |
| | | //清除登录错误次数统计 |
| | | loginFailAttributeList.forEach(servletContext::removeAttribute); |
| | | }else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_"+System.currentTimeMillis(), 0); |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | return response.set(1, false, "密码错误"); |
| | | } |
| | | return response.set(1, false, message); |
| | |
| | | dataList.add(subject.getPrincipal()); |
| | | int permitGroupId = permitGroupUserService.getPermitGroupId(userInf.getUId()); |
| | | dataList.add(permitGroupId); |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response<>().set(1,false,"密码错误"); |
| | |
| | | servletContext.setAttribute(userInf.getUName(), request.getSession().getId()); |
| | | //Session存储当前用户及权限组列表 |
| | | request.getSession().setAttribute("user", subject.getPrincipal()); |
| | | request.getSession().setMaxInactiveInterval(60*60*24); |
| | | request.getSession().setMaxInactiveInterval(60 * 60 * 24); |
| | | request.getSession().setAttribute("permits", ActionUtil.getGson().toJson(permitGroupUserService.getItemList(userInf.getUId()))); |
| | | |
| | | //回写登录时间到数据库 |
| | |
| | | dataList.add(subject.getPrincipal()); |
| | | int permitGroupId = permitGroupUserService.getPermitGroupId(userInf.getUId()); |
| | | dataList.add(permitGroupId); |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName()); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeNameEn()); |
| | | } |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response().set(1,false,"认证未通过"); |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | private UserLogMapper mapper; |
| | | |
| | | public PageInfo<UserLog>getPage(int pageNum, int pageSize, UserLog userLog) { |
| | | PageHelper.startPage(pageNum,pageSize,true); |
| | | PageHelper.startPage(pageNum, pageSize, true); |
| | | //这个接口要兼容新老审计日志记录的查询 |
| | | List<UserLog> userLogList = mapper.getList(userLog); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | userLogList.stream().forEach(userLog1 -> { |
| | | switch (userLog1.getOperationType()){ |
| | | case 1: userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN.getTypeName());break; |
| | | case 2: userLog1.setOperationTypeStr(UserOperation.TYPE_LOGOUT.getTypeName());break; |
| | | case 3: userLog1.setOperationTypeStr(UserOperation.TYPE_ADD.getTypeName());break; |
| | | case 4: userLog1.setOperationTypeStr(UserOperation.TYPE_UPDATE.getTypeName());break; |
| | | case 5: userLog1.setOperationTypeStr(UserOperation.TYPE_DELETE.getTypeName());break; |
| | | case 20:userLog1.setOperationTypeStr(UserOperation.TYPE_UNAUTHORIZED_ACCESS.getTypeName());break; |
| | | case 21:userLog1.setOperationTypeStr(UserOperation.TYPE_EXCEPTION.getTypeName());break; |
| | | case 31:userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_FAIL.getTypeName());break; |
| | | case 32:userLog1.setOperationTypeStr(UserOperation.TYPE_PARAM_CHANGE.getTypeName());break; |
| | | case 33:userLog1.setOperationTypeStr(UserOperation.TYPE_PASSWORD_CHANGE.getTypeName());break; |
| | | case 34:userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_TIMEOUT.getTypeName());break; |
| | | default:userLog1.setOperationTypeStr(UserOperation.TYPE_UNRECOGNIZED.getTypeName()); |
| | | switch (userLog1.getOperationType()) { |
| | | case 1: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 2: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGOUT.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGOUT.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 3: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_ADD.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_ADD.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 4: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UPDATE.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UPDATE.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 5: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_DELETE.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_DELETE.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 20: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UNAUTHORIZED_ACCESS.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UNAUTHORIZED_ACCESS.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 21: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_EXCEPTION.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_EXCEPTION.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 31: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 32: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_PARAM_CHANGE.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_PARAM_CHANGE.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 33: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_PASSWORD_CHANGE.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_PASSWORD_CHANGE.getTypeNameEn()); |
| | | } |
| | | break; |
| | | case 34: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_TIMEOUT.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_LOGIN_TIMEOUT.getTypeNameEn()); |
| | | } |
| | | break; |
| | | default: |
| | | if (lang.contains("zh")) { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UNRECOGNIZED.getTypeName()); |
| | | } else { |
| | | userLog1.setOperationTypeStr(UserOperation.TYPE_UNRECOGNIZED.getTypeNameEn()); |
| | | } |
| | | } |
| | | }); |
| | | PageInfo<UserLog> pageInfo = new PageInfo<>(userLogList); |
| | |
| | | } |
| | | |
| | | public void exportExcel(HttpServletResponse response, String[][] value) { |
| | | |
| | | String[] columnTitleArr = new String[]{"操作人姓名","操作类型","操作时间","终端IP","操作事件","具体参数"}; |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | String[] columnTitleArr = null; |
| | | if (lang.contains("zh")) { |
| | | columnTitleArr = new String[]{"操作人姓名", "操作类型", "操作时间", "终端IP", "操作事件", "具体参数"}; |
| | | } else { |
| | | columnTitleArr = new String[]{"Operator Name", "Operator Type", "Operator Time", "Operator IP", "Operator EVENT", "Specific parameters"}; |
| | | } |
| | | String now = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(new Date()); |
| | | ExcelUtil.exportExcel("UserLog-"+now,"测试sheet1",columnTitleArr,value,new HSSFWorkbook(),response); |
| | | ExcelUtil.exportExcel("UserLog-" + now, "sheet1", columnTitleArr, value, new HSSFWorkbook(), response); |
| | | } |
| | | |
| | | public void record(long uId, int operationType, String msg) { |