github-advanced-security[bot] commented on code in PR #15554:
URL: 
https://github.com/apache/dolphinscheduler/pull/15554#discussion_r1517398566


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AuditLogController.java:
##########
@@ -57,8 +59,8 @@
      *
      * @param loginUser         login user
      * @param pageNo            page number
-     * @param resourceType     resource type
-     * @param operationType     operation type
+     * @param objectTypeCodes       object type codes

Review Comment:
   ## Spurious Javadoc @param tags
   
   @param tag "objectTypeCodes" does not match any actual parameter of method 
"queryAuditLogListPaging()".
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3983)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AuditLogController.java:
##########
@@ -57,8 +59,8 @@
      *
      * @param loginUser         login user
      * @param pageNo            page number
-     * @param resourceType     resource type
-     * @param operationType     operation type
+     * @param objectTypeCodes       object type codes
+     * @param operationTypeCodes    operation type codes

Review Comment:
   ## Spurious Javadoc @param tags
   
   @param tag "operationTypeCodes" does not match any actual parameter of 
method "queryAuditLogListPaging()".
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3984)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskInstanceOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TaskInstanceOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private TaskInstanceMapper taskInstanceMapper;
+
+    @Override
+    protected String getObjectNameFromReturnIdentity(Object identity) {
+        TaskInstance obj = 
taskInstanceMapper.selectById(Integer.parseInt(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3994)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseOperator.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator;
+
+import org.apache.dolphinscheduler.api.audit.OperatorUtils;
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.service.AuditService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+import java.util.Map;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.common.base.Strings;
+
+@Service
+@Slf4j
+public abstract class BaseOperator implements Operator {
+
+    @Autowired
+    private AuditService auditService;
+
+    public Object recordAudit(ProceedingJoinPoint point, String describe, 
AuditType auditType) throws Throwable {
+        long beginTime = System.currentTimeMillis();
+
+        MethodSignature signature = (MethodSignature) point.getSignature();
+        Map<String, Object> paramsMap = OperatorUtils.getParamsMap(point, 
signature);
+
+        User user = OperatorUtils.getUser(paramsMap);
+
+        if (user == null) {
+            log.error("user is null");
+            return point.proceed();
+        }
+
+        List<AuditLog> auditLogList = 
OperatorUtils.buildAuditLogList(describe, auditType, user);
+        setRequestParam(auditType, auditLogList, paramsMap);
+
+        Result result = (Result) point.proceed();
+        if (OperatorUtils.resultFail(result)) {
+            log.error("request fail, code {}", result.getCode());
+            return result;
+        }
+
+        setObjectIdentityFromReturnObject(auditType, result, auditLogList);
+
+        modifyAuditOperationType(auditType, paramsMap, auditLogList);
+        modifyAuditObjectType(auditType, paramsMap, auditLogList);
+
+        long latency = System.currentTimeMillis() - beginTime;
+        auditService.addAudit(auditLogList, latency);
+
+        return result;
+    }
+
+    protected void setRequestParam(AuditType auditType, List<AuditLog> 
auditLogList, Map<String, Object> paramsMap) {
+        String[] paramNameArr = auditType.getRequestParamName();
+
+        if (paramNameArr.length == 0) {
+            return;
+        }
+
+        modifyRequestParams(paramNameArr, paramsMap, auditLogList);
+        setObjectByParma(paramNameArr, paramsMap, auditLogList);
+
+        if (auditLogList.get(0).getObjectId() == null) {
+            
auditLogList.get(0).setObjectId(OperatorUtils.getObjectIdentityByParma(paramNameArr,
 paramsMap));
+        }
+    }
+
+    protected void setObjectByParma(String[] paramNameArr, Map<String, Object> 
paramsMap,
+                                    List<AuditLog> auditLogList) {
+
+        String name = paramNameArr[0];
+        Object value = paramsMap.get(name);
+
+        if (value == null) {
+            return;
+        }
+
+        String objName = getObjectNameFromReturnIdentity(value);
+
+        if (Strings.isNullOrEmpty(objName)) {
+            auditLogList.get(0).setObjectName(value.toString());
+            return;
+        }
+
+        auditLogList.get(0).setObjectId(Long.parseLong(value.toString()));
+        auditLogList.get(0).setObjectName(objName);
+    }
+
+    protected void setObjectByParmaArr(String[] paramNameArr, Map<String, 
Object> paramsMap,
+                                       List<AuditLog> auditLogList) {
+
+        AuditLog auditLog = auditLogList.get(0);
+        for (String param : paramNameArr) {
+            if (!paramsMap.containsKey(param)) {
+                continue;
+            }
+
+            String[] identityArr = ((String) paramsMap.get(param)).split(",");
+            for (String identityString : identityArr) {
+                long identity;
+                try {
+                    identity = Long.parseLong(identityString);
+                } catch (Exception e) {
+                    log.error("code is not long, code: {}", identityString);
+                    continue;
+                }
+
+                String value = getObjectNameFromReturnIdentity(identity);
+
+                if (value == null) {
+                    continue;
+                }
+
+                auditLog.setObjectId(identity);
+                auditLog.setObjectName(value);
+                auditLogList.add(auditLog);
+                auditLog = AuditLog.copyNewOne(auditLog);
+            }
+        }
+        auditLogList.remove(0);
+    }
+
+    protected void setObjectIdentityFromReturnObject(AuditType auditType, 
Result result,
+                                                     List<AuditLog> 
auditLogList) {
+        String[] returnObjectFieldNameArr = 
auditType.getReturnObjectFieldName();
+        if (returnObjectFieldNameArr.length == 0) {
+            return;
+        }
+        Map<String, Object> returnObjectMap =
+                OperatorUtils.getObjectIfFromReturnObject(result.getData(), 
returnObjectFieldNameArr);
+        modifyObjectFromReturnObject(returnObjectFieldNameArr, 
returnObjectMap, auditLogList);
+        setObjectNameFromReturnIdentity(auditLogList);
+    }
+
+    protected void setObjectNameFromReturnIdentity(List<AuditLog> 
auditLogList) {
+        auditLogList
+                .forEach(auditLog -> 
auditLog.setObjectName(getObjectNameFromReturnIdentity(auditLog.getObjectId())));
+    }
+
+    protected String getObjectNameFromReturnIdentity(Object identity) {
+        return "";
+    }
+
+    protected void modifyRequestParams(String[] paramNameArr, Map<String, 
Object> paramsMap,
+                                       List<AuditLog> auditLogList) {
+    }
+
+    protected void modifyAuditObjectType(AuditType auditType, Map<String, 
Object> paramsMap,
+                                         List<AuditLog> auditLogList) {
+
+    }
+
+    protected void modifyAuditOperationType(AuditType auditType, Map<String, 
Object> paramsMap,
+                                            List<AuditLog> auditLogList) {
+
+    }
+
+    protected void modifyObjectFromReturnObject(String[] params, Map<String, 
Object> returnObjectMap,
+                                                List<AuditLog> auditLogList) {
+        if (returnObjectMap.isEmpty()) {
+            return;
+        }
+
+        auditLogList
+                .forEach(auditLog -> 
auditLog.setObjectId(Long.parseLong(returnObjectMap.get(params[0]).toString())));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3988)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseOperator.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator;
+
+import org.apache.dolphinscheduler.api.audit.OperatorUtils;
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.service.AuditService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+import java.util.Map;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.common.base.Strings;
+
+@Service
+@Slf4j
+public abstract class BaseOperator implements Operator {
+
+    @Autowired
+    private AuditService auditService;
+
+    public Object recordAudit(ProceedingJoinPoint point, String describe, 
AuditType auditType) throws Throwable {
+        long beginTime = System.currentTimeMillis();
+
+        MethodSignature signature = (MethodSignature) point.getSignature();
+        Map<String, Object> paramsMap = OperatorUtils.getParamsMap(point, 
signature);
+
+        User user = OperatorUtils.getUser(paramsMap);
+
+        if (user == null) {
+            log.error("user is null");
+            return point.proceed();
+        }
+
+        List<AuditLog> auditLogList = 
OperatorUtils.buildAuditLogList(describe, auditType, user);
+        setRequestParam(auditType, auditLogList, paramsMap);
+
+        Result result = (Result) point.proceed();
+        if (OperatorUtils.resultFail(result)) {
+            log.error("request fail, code {}", result.getCode());
+            return result;
+        }
+
+        setObjectIdentityFromReturnObject(auditType, result, auditLogList);
+
+        modifyAuditOperationType(auditType, paramsMap, auditLogList);
+        modifyAuditObjectType(auditType, paramsMap, auditLogList);
+
+        long latency = System.currentTimeMillis() - beginTime;
+        auditService.addAudit(auditLogList, latency);
+
+        return result;
+    }
+
+    protected void setRequestParam(AuditType auditType, List<AuditLog> 
auditLogList, Map<String, Object> paramsMap) {
+        String[] paramNameArr = auditType.getRequestParamName();
+
+        if (paramNameArr.length == 0) {
+            return;
+        }
+
+        modifyRequestParams(paramNameArr, paramsMap, auditLogList);
+        setObjectByParma(paramNameArr, paramsMap, auditLogList);
+
+        if (auditLogList.get(0).getObjectId() == null) {
+            
auditLogList.get(0).setObjectId(OperatorUtils.getObjectIdentityByParma(paramNameArr,
 paramsMap));
+        }
+    }
+
+    protected void setObjectByParma(String[] paramNameArr, Map<String, Object> 
paramsMap,
+                                    List<AuditLog> auditLogList) {
+
+        String name = paramNameArr[0];
+        Object value = paramsMap.get(name);
+
+        if (value == null) {
+            return;
+        }
+
+        String objName = getObjectNameFromReturnIdentity(value);
+
+        if (Strings.isNullOrEmpty(objName)) {
+            auditLogList.get(0).setObjectName(value.toString());
+            return;
+        }
+
+        auditLogList.get(0).setObjectId(Long.parseLong(value.toString()));
+        auditLogList.get(0).setObjectName(objName);
+    }
+
+    protected void setObjectByParmaArr(String[] paramNameArr, Map<String, 
Object> paramsMap,
+                                       List<AuditLog> auditLogList) {
+
+        AuditLog auditLog = auditLogList.get(0);
+        for (String param : paramNameArr) {
+            if (!paramsMap.containsKey(param)) {
+                continue;
+            }
+
+            String[] identityArr = ((String) paramsMap.get(param)).split(",");
+            for (String identityString : identityArr) {
+                long identity;
+                try {
+                    identity = Long.parseLong(identityString);
+                } catch (Exception e) {
+                    log.error("code is not long, code: {}", identityString);
+                    continue;
+                }
+
+                String value = getObjectNameFromReturnIdentity(identity);
+
+                if (value == null) {
+                    continue;
+                }
+
+                auditLog.setObjectId(identity);
+                auditLog.setObjectName(value);
+                auditLogList.add(auditLog);
+                auditLog = AuditLog.copyNewOne(auditLog);
+            }
+        }
+        auditLogList.remove(0);
+    }
+
+    protected void setObjectIdentityFromReturnObject(AuditType auditType, 
Result result,
+                                                     List<AuditLog> 
auditLogList) {
+        String[] returnObjectFieldNameArr = 
auditType.getReturnObjectFieldName();
+        if (returnObjectFieldNameArr.length == 0) {
+            return;
+        }
+        Map<String, Object> returnObjectMap =
+                OperatorUtils.getObjectIfFromReturnObject(result.getData(), 
returnObjectFieldNameArr);
+        modifyObjectFromReturnObject(returnObjectFieldNameArr, 
returnObjectMap, auditLogList);
+        setObjectNameFromReturnIdentity(auditLogList);
+    }
+
+    protected void setObjectNameFromReturnIdentity(List<AuditLog> 
auditLogList) {
+        auditLogList
+                .forEach(auditLog -> 
auditLog.setObjectName(getObjectNameFromReturnIdentity(auditLog.getObjectId())));
+    }
+
+    protected String getObjectNameFromReturnIdentity(Object identity) {
+        return "";
+    }
+
+    protected void modifyRequestParams(String[] paramNameArr, Map<String, 
Object> paramsMap,
+                                       List<AuditLog> auditLogList) {
+    }
+
+    protected void modifyAuditObjectType(AuditType auditType, Map<String, 
Object> paramsMap,

Review Comment:
   ## Useless parameter
   
   The parameter 'auditType' is never used.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3982)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseOperator.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator;
+
+import org.apache.dolphinscheduler.api.audit.OperatorUtils;
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.service.AuditService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+import java.util.Map;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.common.base.Strings;
+
+@Service
+@Slf4j
+public abstract class BaseOperator implements Operator {
+
+    @Autowired
+    private AuditService auditService;
+
+    public Object recordAudit(ProceedingJoinPoint point, String describe, 
AuditType auditType) throws Throwable {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [Operator.recordAudit](1); it is advisable to add an 
Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3986)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseOperator.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator;
+
+import org.apache.dolphinscheduler.api.audit.OperatorUtils;
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.service.AuditService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+
+import java.util.List;
+import java.util.Map;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.common.base.Strings;
+
+@Service
+@Slf4j
+public abstract class BaseOperator implements Operator {
+
+    @Autowired
+    private AuditService auditService;
+
+    public Object recordAudit(ProceedingJoinPoint point, String describe, 
AuditType auditType) throws Throwable {
+        long beginTime = System.currentTimeMillis();
+
+        MethodSignature signature = (MethodSignature) point.getSignature();
+        Map<String, Object> paramsMap = OperatorUtils.getParamsMap(point, 
signature);
+
+        User user = OperatorUtils.getUser(paramsMap);
+
+        if (user == null) {
+            log.error("user is null");
+            return point.proceed();
+        }
+
+        List<AuditLog> auditLogList = 
OperatorUtils.buildAuditLogList(describe, auditType, user);
+        setRequestParam(auditType, auditLogList, paramsMap);
+
+        Result result = (Result) point.proceed();
+        if (OperatorUtils.resultFail(result)) {
+            log.error("request fail, code {}", result.getCode());
+            return result;
+        }
+
+        setObjectIdentityFromReturnObject(auditType, result, auditLogList);
+
+        modifyAuditOperationType(auditType, paramsMap, auditLogList);
+        modifyAuditObjectType(auditType, paramsMap, auditLogList);
+
+        long latency = System.currentTimeMillis() - beginTime;
+        auditService.addAudit(auditLogList, latency);
+
+        return result;
+    }
+
+    protected void setRequestParam(AuditType auditType, List<AuditLog> 
auditLogList, Map<String, Object> paramsMap) {
+        String[] paramNameArr = auditType.getRequestParamName();
+
+        if (paramNameArr.length == 0) {
+            return;
+        }
+
+        modifyRequestParams(paramNameArr, paramsMap, auditLogList);
+        setObjectByParma(paramNameArr, paramsMap, auditLogList);
+
+        if (auditLogList.get(0).getObjectId() == null) {
+            
auditLogList.get(0).setObjectId(OperatorUtils.getObjectIdentityByParma(paramNameArr,
 paramsMap));
+        }
+    }
+
+    protected void setObjectByParma(String[] paramNameArr, Map<String, Object> 
paramsMap,
+                                    List<AuditLog> auditLogList) {
+
+        String name = paramNameArr[0];
+        Object value = paramsMap.get(name);
+
+        if (value == null) {
+            return;
+        }
+
+        String objName = getObjectNameFromReturnIdentity(value);
+
+        if (Strings.isNullOrEmpty(objName)) {
+            auditLogList.get(0).setObjectName(value.toString());
+            return;
+        }
+
+        auditLogList.get(0).setObjectId(Long.parseLong(value.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3987)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertInstanceOperatorImpl.java:
##########
@@ -15,28 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.api.audit;
+package org.apache.dolphinscheduler.api.audit.operator.impl;
 
-import org.apache.dolphinscheduler.dao.entity.AuditLog;
-import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
+import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
 
-@Component
-public class AuditSubscriberImpl implements AuditSubscriber {
+@Service
+public class AlertInstanceOperatorImpl extends BaseOperator {
 
     @Autowired
-    private AuditLogMapper logMapper;
+    private AlertPluginInstanceMapper alertPluginInstanceMapper;
 
     @Override
-    public void execute(AuditMessage message) {
-        AuditLog auditLog = new AuditLog();
-        auditLog.setUserId(message.getUser().getId());
-        auditLog.setResourceType(message.getResourceType().getCode());
-        auditLog.setOperation(message.getOperation().getCode());
-        auditLog.setTime(message.getAuditDate());
-        auditLog.setResourceId(message.getResourceId());
-        logMapper.insert(auditLog);
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        AlertPluginInstance obj = 
alertPluginInstanceMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3990)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertGroupOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.AlertGroup;
+import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AlertGroupOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private AlertGroupMapper alertGroupMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        AlertGroup obj = 
alertGroupMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3989)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/DatasourceOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.DataSource;
+import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DatasourceOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private DataSourceMapper dataSourceMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        DataSource obj = 
dataSourceMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3991)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TenantOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.Tenant;
+import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TenantOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private TenantMapper tenantMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        Tenant obj = 
tenantMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3995)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/UserOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.UserMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UserOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private UserMapper userMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        User obj = userMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3996)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TokenOperatorImpl.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.AccessToken;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.User;
+import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper;
+import org.apache.dolphinscheduler.dao.mapper.UserMapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TokenOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private AccessTokenMapper accessTokenMapper;
+
+    @Autowired
+    private UserMapper userMapper;
+
+    @Override
+    public void modifyAuditOperationType(AuditType auditType, Map<String, 
Object> paramsMap,
+                                         List<AuditLog> auditLogList) {
+        if (paramsMap.get("userId") != null) {
+            User user = 
userMapper.selectById(paramsMap.get("userId").toString());
+            auditLogList.forEach(auditLog -> {
+                auditLog.setObjectName(user.getUserName());
+                auditLog.setObjectId(Long.valueOf(user.getId()));
+            });
+        }
+    }
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        AccessToken obj = 
accessTokenMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3997)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProcessInstanceOperatorImpl.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
+import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ProcessInstanceOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private ProcessInstanceMapper processInstanceMapper;
+
+    @Override
+    protected void setObjectByParma(String[] paramNameArr, Map<String, Object> 
paramsMap,
+                                    List<AuditLog> auditLogList) {
+        if (paramNameArr[0].equals("processInstanceIds")) {
+            super.setObjectByParmaArr(paramNameArr, paramsMap, auditLogList);
+        } else {
+            super.setObjectByParma(paramNameArr, paramsMap, auditLogList);
+        }
+    }
+
+    @Override
+    protected String getObjectNameFromReturnIdentity(Object identity) {
+        ProcessInstance obj = 
processInstanceMapper.queryDetailById(Integer.parseInt(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3993)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/YarnQueueOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.Queue;
+import org.apache.dolphinscheduler.dao.mapper.QueueMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class YarnQueueOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private QueueMapper queueMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        Queue obj = 
queueMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3998)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/K8sNamespaceOperatorImpl.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.dao.entity.K8sNamespace;
+import org.apache.dolphinscheduler.dao.mapper.K8sNamespaceMapper;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class K8sNamespaceOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private K8sNamespaceMapper k8sNamespaceMapper;
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        K8sNamespace obj = 
k8sNamespaceMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3992)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkerGroupOperatorImpl.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.audit.operator.impl;
+
+import org.apache.dolphinscheduler.api.audit.enums.AuditType;
+import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
+import org.apache.dolphinscheduler.common.enums.AuditOperationType;
+import org.apache.dolphinscheduler.dao.entity.AuditLog;
+import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class WorkerGroupOperatorImpl extends BaseOperator {
+
+    @Autowired
+    private WorkerGroupMapper workerGroupMapper;
+
+    @Override
+    public void modifyAuditOperationType(AuditType auditType, Map<String, 
Object> paramsMap,
+                                         List<AuditLog> auditLogList) {
+        if (auditType.getAuditOperationType() == AuditOperationType.CREATE
+                && paramsMap.get("id") != null &&
+                !paramsMap.get("id").toString().equals("0")) {
+            auditLogList.forEach(auditLog -> 
auditLog.setOperationType(AuditOperationType.UPDATE.getName()));
+        }
+    }
+
+    @Override
+    public String getObjectNameFromReturnIdentity(Object identity) {
+        WorkerGroup obj = 
workerGroupMapper.selectById(Long.parseLong(identity.toString()));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/3999)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to