forked from github/dataease
Merge pull request #6140 from dataease/pr@dev@feat_api_key_log
fix(日志): apikey记录日志
This commit is contained in:
commit
3fba4a0f50
@ -4,7 +4,6 @@ package io.dataease.auth.aop;
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.AopUtils;
|
||||
import io.dataease.commons.utils.DeLogUtils;
|
||||
import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.dto.SysLogDTO;
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
@ -37,7 +36,7 @@ public class DeLogAnnotationHandler {
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
private static List<Integer> before = new ArrayList<>();
|
||||
private static final List<Integer> before = new ArrayList<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
@ -46,7 +45,7 @@ public class DeLogAnnotationHandler {
|
||||
before.add(SysLogConstants.OPERATE_TYPE.UNAUTHORIZE.getValue());
|
||||
}
|
||||
|
||||
private SysLogDTO exec(JoinPoint point, DeLog deLog) throws Exception{
|
||||
private SysLogDTO exec(JoinPoint point, DeLog deLog) throws Exception {
|
||||
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtils.isEmpty(args)) return null;
|
||||
@ -73,7 +72,7 @@ public class DeLogAnnotationHandler {
|
||||
|
||||
// 填充资源位置信息
|
||||
int positionIndex = deLog.positionIndex();
|
||||
if (positionIndex > -1 && args.length > positionIndex){
|
||||
if (positionIndex > -1 && args.length > positionIndex) {
|
||||
String positionKey = deLog.positionKey();
|
||||
Object positionArg = args[positionIndex];
|
||||
Object bottomPositionValue = AopUtils.getParamValue(positionArg, positionKey, 0);
|
||||
@ -83,7 +82,7 @@ public class DeLogAnnotationHandler {
|
||||
List<FolderItem> items = new ArrayList<>();
|
||||
items.add(folderItem);
|
||||
sysLogDTO.setPositions(items);
|
||||
}else {
|
||||
} else {
|
||||
List<FolderItem> parentsAndSelf = logManager.parentsAndSelf(bottomPositionValue.toString(), sourcetype);
|
||||
sysLogDTO.setPositions(parentsAndSelf);
|
||||
}
|
||||
@ -92,7 +91,7 @@ public class DeLogAnnotationHandler {
|
||||
}
|
||||
// 填充资源目标位置信息
|
||||
int targetIndex = deLog.targetIndex();
|
||||
if (targetIndex > -1 && args.length > targetIndex){
|
||||
if (targetIndex > -1 && args.length > targetIndex) {
|
||||
String targetKey = deLog.targetKey();
|
||||
Object targetArg = args[targetIndex];
|
||||
SysLogConstants.SOURCE_TYPE targetType = deLog.targetType();
|
||||
@ -110,11 +109,11 @@ public class DeLogAnnotationHandler {
|
||||
SysLogDTO logDTO = null;
|
||||
Object result = null;
|
||||
DeLog log = getLog(point);
|
||||
if(before.contains(log.operatetype().getValue())) {
|
||||
if (before.contains(log.operatetype().getValue())) {
|
||||
// 前置处理 比如删除操作 需要在数据删除之前查询
|
||||
logDTO = exec(point, log);
|
||||
result = point.proceed(point.getArgs());
|
||||
}else {
|
||||
} else {
|
||||
// 后置处理 比如保存操作 需要在保存之后才有主键
|
||||
result = point.proceed(point.getArgs());
|
||||
logDTO = exec(point, log);
|
||||
@ -128,15 +127,9 @@ public class DeLogAnnotationHandler {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private DeLog getLog(JoinPoint point) {
|
||||
MethodSignature ms = (MethodSignature) point.getSignature();
|
||||
Method method = ms.getMethod();
|
||||
DeLog deLog = method.getAnnotation(DeLog.class);
|
||||
return deLog;
|
||||
return method.getAnnotation(DeLog.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ public class SysLogConstants {
|
||||
ROLE(8, "SOURCE_TYPE_ROLE"),
|
||||
DRIVER(9, "SOURCE_TYPE_DRIVER"),
|
||||
DRIVER_FILE(10, "SOURCE_TYPE_DRIVER_FILE"),
|
||||
MENU(11, "SOURCE_TYPE_MENU");
|
||||
MENU(11, "SOURCE_TYPE_MENU"),
|
||||
APIKEY(12, "SOURCE_TYPE_APIKEY");
|
||||
private Integer value;
|
||||
private String name;
|
||||
|
||||
|
@ -195,6 +195,17 @@
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 12">
|
||||
id, access_key as name
|
||||
from user_key
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.dataease.plugins.server;
|
||||
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.plugins.config.SpringContextUtil;
|
||||
import io.dataease.plugins.xpack.ukey.dto.request.XpackUkeyDto;
|
||||
@ -18,7 +20,6 @@ public class XUserKeysServer {
|
||||
|
||||
@PostMapping("info")
|
||||
public List<XpackUkeyDto> getUserKeysInfo() {
|
||||
|
||||
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
|
||||
Long userId = AuthUtils.getUser().getUserId();
|
||||
return ukeyXpackService.getUserKeysInfo(userId);
|
||||
@ -29,19 +30,33 @@ public class XUserKeysServer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.APIKEY,
|
||||
value = "id"
|
||||
)
|
||||
@PostMapping("generate")
|
||||
public void generateUserKey() {
|
||||
public void generateUserKey(@RequestBody XpackUkeyDto ukeyDto) {
|
||||
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
|
||||
Long userId = AuthUtils.getUser().getUserId();
|
||||
ukeyXpackService.generateUserKey(userId);
|
||||
XpackUkeyDto xpackUkeyDto = ukeyXpackService.generateUserKey(userId);
|
||||
ukeyDto.setId(xpackUkeyDto.getId());
|
||||
}
|
||||
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.DELETE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.APIKEY
|
||||
)
|
||||
@PostMapping("delete/{id}")
|
||||
public void deleteUserKey(@PathVariable Long id) {
|
||||
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
|
||||
ukeyXpackService.deleteUserKey(id);
|
||||
}
|
||||
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.APIKEY
|
||||
)
|
||||
@PostMapping("changeStatus/{id}")
|
||||
public void changeStatus(@PathVariable Long id) {
|
||||
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
|
||||
|
@ -32,36 +32,34 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class LogService {
|
||||
|
||||
private static final String LOG_RETENTION = "30";
|
||||
private Gson gson = new Gson();
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
// 仪表板的额外操作 分享以及公共链接
|
||||
private static Integer[] panel_ext_ope = {4, 5, 8, 9, 10};
|
||||
private static final Integer[] panel_ext_ope = {4, 5, 8, 9, 10};
|
||||
|
||||
private static Integer[] link_ext_ope = {13, 14};
|
||||
private static final Integer[] link_ext_ope = {13, 14};
|
||||
|
||||
// 驱动文件操作 上传, 删除
|
||||
private static Integer[] driver_file_ope = {11, 3};
|
||||
private static final Integer[] driver_file_ope = {11, 3};
|
||||
|
||||
private static Integer[] COMMON_SOURCE = {1, 2, 3, 6, 7, 8, 9};
|
||||
private static final Integer[] COMMON_SOURCE = {1, 2, 3, 6, 7, 8, 9, 12};
|
||||
|
||||
// 增 改 删 针对公共资源的操作
|
||||
private static Integer[] COMMON_SOURCE_OPERATE = {1, 2, 3};
|
||||
private static final Integer[] COMMON_SOURCE_OPERATE = {1, 2, 3};
|
||||
|
||||
// 授权相关操作
|
||||
private static Integer[] AUTH_OPERATE = {6, 7};
|
||||
private static final Integer[] AUTH_OPERATE = {6, 7};
|
||||
|
||||
// 授权相关资源 数据源 仪表板 数据集 菜单
|
||||
private static Integer[] AUTH_SOURCE = {1, 2, 3, 11};
|
||||
private static final Integer[] AUTH_SOURCE = {1, 2, 3, 11};
|
||||
|
||||
|
||||
@Resource
|
||||
@ -108,14 +106,12 @@ public class LogService {
|
||||
List<FolderItem> results = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < COMMON_SOURCE.length; i++) {
|
||||
for (Integer sourceVal : COMMON_SOURCE) {
|
||||
|
||||
Integer sourceVal = COMMON_SOURCE[i];
|
||||
String sourceTypeName = SysLogConstants.sourceTypeName(sourceVal);
|
||||
|
||||
for (int j = 0; j < COMMON_SOURCE_OPERATE.length; j++) {
|
||||
for (Integer operateVal : COMMON_SOURCE_OPERATE) {
|
||||
|
||||
Integer operateVal = COMMON_SOURCE_OPERATE[j];
|
||||
String operateTypeName = SysLogConstants.operateTypeName(operateVal);
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(operateVal + "-" + sourceVal);
|
||||
@ -125,23 +121,21 @@ public class LogService {
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < driver_file_ope.length; i++) {
|
||||
for (Integer integer : driver_file_ope) {
|
||||
SysLogConstants.SOURCE_TYPE sourceType = SysLogConstants.SOURCE_TYPE.DRIVER_FILE;
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(driver_file_ope[i] + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(driver_file_ope[i]);
|
||||
folderItem.setId(integer + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(integer);
|
||||
String sourceTypeName = sourceType.getName();
|
||||
folderItem.setName(Translator.get(operateTypeName) + Translator.get(sourceTypeName));
|
||||
results.add(folderItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < AUTH_SOURCE.length; i++) {
|
||||
Integer sourceVal = AUTH_SOURCE[i];
|
||||
for (Integer sourceVal : AUTH_SOURCE) {
|
||||
String sourceTypeName = SysLogConstants.sourceTypeName(sourceVal);
|
||||
|
||||
for (int j = 0; j < AUTH_OPERATE.length; j++) {
|
||||
for (Integer operateVal : AUTH_OPERATE) {
|
||||
|
||||
Integer operateVal = AUTH_OPERATE[j];
|
||||
String operateTypeName = SysLogConstants.operateTypeName(operateVal);
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(operateVal + "-" + sourceVal);
|
||||
@ -150,21 +144,21 @@ public class LogService {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < panel_ext_ope.length; i++) {
|
||||
for (Integer integer : panel_ext_ope) {
|
||||
SysLogConstants.SOURCE_TYPE sourceType = SysLogConstants.SOURCE_TYPE.PANEL;
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(panel_ext_ope[i] + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(panel_ext_ope[i]);
|
||||
folderItem.setId(integer + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(integer);
|
||||
String sourceTypeName = sourceType.getName();
|
||||
folderItem.setName(Translator.get(operateTypeName) + Translator.get(sourceTypeName));
|
||||
results.add(folderItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < link_ext_ope.length; i++) {
|
||||
for (Integer integer : link_ext_ope) {
|
||||
SysLogConstants.SOURCE_TYPE sourceType = SysLogConstants.SOURCE_TYPE.LINK;
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(link_ext_ope[i] + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(link_ext_ope[i]);
|
||||
folderItem.setId(integer + "-" + sourceType.getValue());
|
||||
String operateTypeName = SysLogConstants.operateTypeName(integer);
|
||||
String sourceTypeName = sourceType.getName();
|
||||
folderItem.setName(Translator.get(operateTypeName) + Translator.get(sourceTypeName));
|
||||
results.add(folderItem);
|
||||
@ -194,13 +188,10 @@ public class LogService {
|
||||
|
||||
private List<FolderItem> typesByArr(Integer[] opTypes, Integer[] sourceTypes) {
|
||||
List<FolderItem> results = new ArrayList<>();
|
||||
for (int i = 0; i < sourceTypes.length; i++) {
|
||||
Integer sourceVal = sourceTypes[i];
|
||||
for (Integer sourceVal : sourceTypes) {
|
||||
String sourceTypeName = SysLogConstants.sourceTypeName(sourceVal);
|
||||
|
||||
for (int j = 0; j < opTypes.length; j++) {
|
||||
|
||||
Integer operateVal = opTypes[j];
|
||||
for (Integer operateVal : opTypes) {
|
||||
|
||||
String operateTypeName = SysLogConstants.operateTypeName(operateVal);
|
||||
FolderItem folderItem = new FolderItem();
|
||||
@ -249,7 +240,7 @@ public class LogService {
|
||||
sysLogWithBLOBs.setUserId(user.getUserId());
|
||||
sysLogWithBLOBs.setLoginName(user.getUsername());
|
||||
sysLogWithBLOBs.setNickName(user.getNickName());
|
||||
} else if (sysLogDTO.getOperateType() == SysLogConstants.OPERATE_TYPE.LOGIN.getValue()) {
|
||||
} else if (Objects.equals(sysLogDTO.getOperateType(), SysLogConstants.OPERATE_TYPE.LOGIN.getValue())) {
|
||||
sysLogWithBLOBs.setUserId(Long.parseLong(sysLogDTO.getSourceId()));
|
||||
sysLogWithBLOBs.setLoginName(sysLogDTO.getSourceName());
|
||||
sysLogWithBLOBs.setNickName(sysLogDTO.getSourceName());
|
||||
@ -320,7 +311,7 @@ public class LogService {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
//文件名称
|
||||
String fileName = "DataEase操作日志";
|
||||
String encodeFileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + encodeFileName + ".xlsx");
|
||||
wb.write(outputStream);
|
||||
outputStream.flush();
|
||||
|
@ -170,6 +170,7 @@ SOURCE_TYPE_DRIVER=DRIVER
|
||||
SOURCE_TYPE_DRIVER_FILE=DRIVER FILE
|
||||
SOURCE_TYPE_MENU=MENU
|
||||
SOURCE_TYPE_LINK=PUBLIC LINK
|
||||
SOURCE_TYPE_APIKEY=APIKEY
|
||||
I18N_OPERATE_TYPE=Operation type
|
||||
I18N_DETAIL=Operation details
|
||||
I18N_USER=Operator
|
||||
|
@ -170,6 +170,7 @@ SOURCE_TYPE_DRIVER=\u9A71\u52A8
|
||||
SOURCE_TYPE_DRIVER_FILE=\u9A71\u52A8\u6587\u4EF6
|
||||
SOURCE_TYPE_MENU=\u83DC\u5355
|
||||
SOURCE_TYPE_LINK=\u516C\u5171\u94FE\u63A5
|
||||
SOURCE_TYPE_APIKEY=APIKEY
|
||||
I18N_OPERATE_TYPE=\u64CD\u4F5C\u7C7B\u578B
|
||||
I18N_DETAIL=\u64CD\u4F5C\u8BE6\u60C5
|
||||
I18N_USER=\u64CD\u4F5C\u4EBA
|
||||
|
@ -170,6 +170,7 @@ SOURCE_TYPE_DRIVER=\u9A45\u52D5
|
||||
SOURCE_TYPE_DRIVER_FILE=\u9A45\u52D5\u6587\u4EF6
|
||||
SOURCE_TYPE_MENU=\u83DC\u55AE
|
||||
SOURCE_TYPE_LINK=\u516C\u5171\u93C8\u63A5
|
||||
SOURCE_TYPE_APIKEY=APIKEY
|
||||
I18N_DRIVER_NOT_DELETE=\u4F7F\u7528\u4E2D\u7684\u9A45\u52D5\u4E0D\u5141\u8A31\u5220\u9664
|
||||
I18N_DRIVER_REPEAT_NAME=\u540D\u7A31\u91CD\u8907
|
||||
I18N_DRIVER_NOT_FOUND=\u672A\u627E\u5230\u9A45\u52D5
|
||||
|
Loading…
Reference in New Issue
Block a user