旺阳
7 months ago
committed by
GitHub
85 changed files with 2715 additions and 637 deletions
@ -1,96 +0,0 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.common.enums.AuditResourceType; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import java.util.Date; |
||||
|
||||
public class AuditMessage { |
||||
|
||||
private User user; |
||||
|
||||
private Date auditDate; |
||||
|
||||
private AuditResourceType resourceType; |
||||
|
||||
private AuditOperationType operation; |
||||
|
||||
private Integer resourceId; |
||||
|
||||
public AuditMessage(User user, Date auditDate, AuditResourceType resourceType, AuditOperationType operation, |
||||
Integer resourceId) { |
||||
this.user = user; |
||||
this.auditDate = auditDate; |
||||
this.resourceType = resourceType; |
||||
this.operation = operation; |
||||
this.resourceId = resourceId; |
||||
} |
||||
|
||||
public User getUser() { |
||||
return user; |
||||
} |
||||
|
||||
public void setUser(User user) { |
||||
this.user = user; |
||||
} |
||||
|
||||
public Date getAuditDate() { |
||||
return auditDate; |
||||
} |
||||
|
||||
public void setAuditDate(Date auditDate) { |
||||
this.auditDate = auditDate; |
||||
} |
||||
|
||||
public AuditResourceType getResourceType() { |
||||
return resourceType; |
||||
} |
||||
|
||||
public void setResourceType(AuditResourceType resourceType) { |
||||
this.resourceType = resourceType; |
||||
} |
||||
|
||||
public AuditOperationType getOperation() { |
||||
return operation; |
||||
} |
||||
|
||||
public void setOperation(AuditOperationType operation) { |
||||
this.operation = operation; |
||||
} |
||||
|
||||
public Integer getResourceId() { |
||||
return resourceId; |
||||
} |
||||
|
||||
public void setResourceId(Integer resourceId) { |
||||
this.resourceId = resourceId; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "AuditMessage{" |
||||
+ "user=" + user |
||||
+ ", Date=" + auditDate |
||||
+ ", resourceType" + resourceType |
||||
+ ", operation=" + operation |
||||
+ ", resourceId='" + resourceId + '\''; |
||||
} |
||||
} |
@ -1,92 +0,0 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.api.configuration.ApiConfig; |
||||
|
||||
import java.util.List; |
||||
import java.util.concurrent.BlockingQueue; |
||||
import java.util.concurrent.LinkedBlockingQueue; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
@Slf4j |
||||
public class AuditPublishService { |
||||
|
||||
private final BlockingQueue<AuditMessage> auditMessageQueue = new LinkedBlockingQueue<>(); |
||||
|
||||
@Autowired |
||||
private List<AuditSubscriber> subscribers; |
||||
|
||||
@Autowired |
||||
private ApiConfig apiConfig; |
||||
|
||||
/** |
||||
* create a daemon thread to process the message queue |
||||
*/ |
||||
@PostConstruct |
||||
private void init() { |
||||
if (apiConfig.isAuditEnable()) { |
||||
Thread thread = new Thread(this::doPublish); |
||||
thread.setDaemon(true); |
||||
thread.setName("Audit-Log-Consume-Thread"); |
||||
thread.start(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* publish a new audit message |
||||
* |
||||
* @param message audit message |
||||
*/ |
||||
public void publish(AuditMessage message) { |
||||
if (apiConfig.isAuditEnable() && !auditMessageQueue.offer(message)) { |
||||
log.error("Publish audit message failed, message:{}", message); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* subscribers execute the message processor method |
||||
*/ |
||||
private void doPublish() { |
||||
AuditMessage message = null; |
||||
while (true) { |
||||
try { |
||||
message = auditMessageQueue.take(); |
||||
for (AuditSubscriber subscriber : subscribers) { |
||||
try { |
||||
subscriber.execute(message); |
||||
} catch (Exception e) { |
||||
log.error("Consume audit message failed, message:{}", message, e); |
||||
} |
||||
} |
||||
} catch (InterruptedException e) { |
||||
log.error("Consume audit message failed, message:{}", message, e); |
||||
Thread.currentThread().interrupt(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
|
||||
import java.lang.annotation.Documented; |
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
/** |
||||
* Custom annotation for logging and auditing operator actions in the system. |
||||
* This annotation can be applied to methods to indicate the type of operation, object type, |
||||
* and specific parameters to be recorded in the logs. |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface OperatorLog { |
||||
|
||||
AuditType auditType(); |
||||
} |
@ -0,0 +1,61 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.api.audit.operator.AuditOperator; |
||||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
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.reflect.MethodSignature; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
|
||||
@Aspect |
||||
@Slf4j |
||||
@Component |
||||
public class OperatorLogAspect { |
||||
|
||||
@Pointcut("@annotation(org.apache.dolphinscheduler.api.audit.OperatorLog)") |
||||
public void logPointCut() { |
||||
} |
||||
|
||||
@Around("logPointCut()") |
||||
public Object around(ProceedingJoinPoint point) throws Throwable { |
||||
MethodSignature signature = (MethodSignature) point.getSignature(); |
||||
Method method = signature.getMethod(); |
||||
|
||||
OperatorLog operatorLog = method.getAnnotation(OperatorLog.class); |
||||
|
||||
Operation operation = method.getAnnotation(Operation.class); |
||||
if (operation == null) { |
||||
log.warn("Operation is null of method: {}", method.getName()); |
||||
return point.proceed(); |
||||
} |
||||
|
||||
AuditOperator operator = SpringApplicationContext.getBean(operatorLog.auditType().getOperatorClass()); |
||||
return operator.recordAudit(point, operation.description(), operatorLog.auditType()); |
||||
} |
||||
} |
@ -0,0 +1,206 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.enums.ExecuteType; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.enums.AuditModelType; |
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
|
||||
@Slf4j |
||||
public class OperatorUtils { |
||||
|
||||
protected void changeObjectForVersionRelated(AuditOperationType auditOperationType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
switch (auditOperationType) { |
||||
case SWITCH_VERSION: |
||||
case DELETE_VERSION: |
||||
auditLogList.get(0).setModelName(paramsMap.get("version").toString()); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
public static boolean resultFail(Result<?> result) { |
||||
return result != null && result.isFailed(); |
||||
} |
||||
|
||||
public static List<AuditLog> buildAuditLogList(String apiDescription, AuditType auditType, User user) { |
||||
List<AuditLog> auditLogList = new ArrayList<>(); |
||||
AuditLog auditLog = new AuditLog(); |
||||
auditLog.setUserId(user.getId()); |
||||
auditLog.setModelType(auditType.getAuditModelType().getName()); |
||||
auditLog.setOperationType(auditType.getAuditOperationType().getName()); |
||||
auditLog.setDescription(apiDescription); |
||||
auditLog.setTime(new Date()); |
||||
auditLogList.add(auditLog); |
||||
|
||||
return auditLogList; |
||||
} |
||||
|
||||
public static User getUser(Map<String, Object> paramsMap) { |
||||
for (Object object : paramsMap.values()) { |
||||
if (object instanceof User) { |
||||
return (User) object; |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public static Map<String, Object> getParamsMap(ProceedingJoinPoint point, MethodSignature signature) { |
||||
Object[] args = point.getArgs(); |
||||
String[] strings = signature.getParameterNames(); |
||||
|
||||
Map<String, Object> paramsMap = new HashMap<>(); |
||||
for (int i = 0; i < strings.length; i++) { |
||||
paramsMap.put(strings[i], args[i]); |
||||
} |
||||
|
||||
return paramsMap; |
||||
} |
||||
|
||||
public static AuditOperationType modifyReleaseOperationType(AuditType auditType, Map<String, Object> paramsMap) { |
||||
switch (auditType.getAuditOperationType()) { |
||||
case RELEASE: |
||||
ReleaseState releaseState = (ReleaseState) paramsMap.get("releaseState"); |
||||
if (releaseState == null) { |
||||
break; |
||||
} |
||||
switch (releaseState) { |
||||
case ONLINE: |
||||
return AuditOperationType.ONLINE; |
||||
case OFFLINE: |
||||
return AuditOperationType.OFFLINE; |
||||
default: |
||||
break; |
||||
} |
||||
break; |
||||
case EXECUTE: |
||||
ExecuteType executeType = (ExecuteType) paramsMap.get("executeType"); |
||||
if (executeType == null) { |
||||
break; |
||||
} |
||||
switch (executeType) { |
||||
case REPEAT_RUNNING: |
||||
return AuditOperationType.RERUN; |
||||
case RECOVER_SUSPENDED_PROCESS: |
||||
return AuditOperationType.RESUME_PAUSE; |
||||
case START_FAILURE_TASK_PROCESS: |
||||
return AuditOperationType.RESUME_FAILURE; |
||||
case STOP: |
||||
return AuditOperationType.STOP; |
||||
case PAUSE: |
||||
return AuditOperationType.PAUSE; |
||||
case EXECUTE_TASK: |
||||
return AuditOperationType.EXECUTE; |
||||
default: |
||||
break; |
||||
} |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
return auditType.getAuditOperationType(); |
||||
} |
||||
|
||||
public static long getObjectIdentityByParma(String[] paramNameArr, Map<String, Object> paramsMap) { |
||||
for (String name : paramNameArr) { |
||||
if (paramsMap.get(name) instanceof String) { |
||||
String param = (String) paramsMap.get(name); |
||||
try { |
||||
if (param.matches("\\d+")) { |
||||
return Long.parseLong(param); |
||||
} |
||||
} catch (NumberFormatException e) { |
||||
return -1; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return -1; |
||||
} |
||||
|
||||
public static Map<String, Object> getObjectIfFromReturnObject(Object obj, String[] params) { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
|
||||
try { |
||||
Class<?> clazz = obj.getClass(); |
||||
|
||||
if (clazz.equals(Long.class)) { |
||||
map.put(params[0], obj); |
||||
} |
||||
|
||||
while (clazz != null) { |
||||
Field[] fields = clazz.getDeclaredFields(); |
||||
for (Field field : fields) { |
||||
field.setAccessible(true); |
||||
|
||||
if (field.getName().equals(params[0])) { |
||||
map.put(params[0], field.get(obj)); |
||||
} |
||||
} |
||||
|
||||
clazz = clazz.getSuperclass(); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("get object if from return object error", e); |
||||
} |
||||
|
||||
return map; |
||||
} |
||||
|
||||
public static boolean isUdfResource(Map<String, Object> paramsMap) { |
||||
ResourceType resourceType = (ResourceType) paramsMap.get("type"); |
||||
return resourceType != null && resourceType.equals(ResourceType.UDF); |
||||
} |
||||
|
||||
public static boolean isFolder(String name) { |
||||
return name != null && name.endsWith("/"); |
||||
} |
||||
|
||||
public static String getFileAuditObject(AuditType auditType, Map<String, Object> paramsMap, String name) { |
||||
boolean isUdfResource = isUdfResource(paramsMap); |
||||
boolean isFolder = auditType == AuditType.FOLDER_CREATE || isFolder(name); |
||||
if (isUdfResource) { |
||||
return isFolder ? AuditModelType.UDF_FOLDER.getName() : AuditModelType.UDF_FILE.getName(); |
||||
} else { |
||||
return isFolder ? AuditModelType.FOLDER.getName() : AuditModelType.FILE.getName(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,48 @@
|
||||
/* |
||||
* 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.constants; |
||||
|
||||
public final class AuditLogConstants { |
||||
|
||||
private AuditLogConstants() { |
||||
throw new UnsupportedOperationException("Construct Constants"); |
||||
} |
||||
|
||||
public static final String CODE = "code"; |
||||
public static final String CODES = "codes"; |
||||
public static final String VERSION = "version"; |
||||
public static final String PROCESS_DEFINITION_CODE = "processDefinitionCode"; |
||||
public static final String PROCESS_DEFINITION_CODES = "processDefinitionCodes"; |
||||
public static final String PROCESS_INSTANCE_IDS = "processInstanceIds"; |
||||
public static final String PROCESS_INSTANCE_ID = "processInstanceId"; |
||||
public static final String WORKFLOW_DEFINITION_CODE = "workflowDefinitionCode"; |
||||
public static final String TYPE = "type"; |
||||
public static final String NAME = "name"; |
||||
public static final String ID = "id"; |
||||
public static final String USER_ID = "userId"; |
||||
public static final String QUEUE_ID = "queueId"; |
||||
public static final String PRIORITY = "priority"; |
||||
public static final String CLUSTER_CODE = "clusterCode"; |
||||
public static final String ENVIRONMENT_CODE = "environmentCode"; |
||||
public static final String ALIAS = "alias"; |
||||
public static final String FILE_NAME = "fileName"; |
||||
public static final String FULL_NAME = "fullName"; |
||||
public static final String FUNC_NAME = "funcName"; |
||||
public static final String UDF_FUNC_ID = "udfFuncId"; |
||||
|
||||
} |
@ -0,0 +1,252 @@
|
||||
/* |
||||
* 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.enums; |
||||
|
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ALIAS; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CLUSTER_CODE; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CODE; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CODES; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ENVIRONMENT_CODE; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FILE_NAME; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FULL_NAME; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FUNC_NAME; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ID; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.NAME; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PRIORITY; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_DEFINITION_CODE; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_DEFINITION_CODES; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_INSTANCE_ID; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_INSTANCE_IDS; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.QUEUE_ID; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.TYPE; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.UDF_FUNC_ID; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.USER_ID; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.VERSION; |
||||
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.WORKFLOW_DEFINITION_CODE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ALARM_GROUP; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ALARM_INSTANCE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.CLUSTER; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.DATASOURCE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ENVIRONMENT; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.FILE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.FOLDER; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.K8S_NAMESPACE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROCESS; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROCESS_INSTANCE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROJECT; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.SCHEDULE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK_GROUP; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK_INSTANCE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TENANT; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TOKEN; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.UDF_FUNCTION; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.USER; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.WORKER_GROUP; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditModelType.YARN_QUEUE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_DELETE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_RERUN; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_START; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.CLOSE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.COPY; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.CREATE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.DELETE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.DELETE_VERSION; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.EXECUTE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.EXPORT; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.FORCE_SUCCESS; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.IMPORT; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.MODIFY; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.OFFLINE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.ONLINE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.RELEASE; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.START; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.SWITCH_VERSION; |
||||
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.UPDATE; |
||||
|
||||
import org.apache.dolphinscheduler.api.audit.operator.AuditOperator; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.AlertGroupAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.AlertInstanceAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ClusterAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.DatasourceAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.EnvironmentAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.K8SNamespaceAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ProcessAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ProcessInstanceAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ProjectAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ResourceAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.ScheduleAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskGroupAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskInstancesAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.TenantAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.TokenAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.UdfFunctionAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.UserAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.WorkerGroupAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.api.audit.operator.impl.YarnQueueAuditOperatorImpl; |
||||
import org.apache.dolphinscheduler.common.enums.AuditModelType; |
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
@Getter |
||||
public enum AuditType { |
||||
|
||||
PROJECT_CREATE(PROJECT, CREATE, ProjectAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
PROJECT_UPDATE(PROJECT, UPDATE, ProjectAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
PROJECT_DELETE(PROJECT, DELETE, ProjectAuditOperatorImpl.class, new String[]{CODE}, new String[]{}), |
||||
|
||||
PROCESS_CREATE(PROCESS, CREATE, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
PROCESS_UPDATE(PROCESS, UPDATE, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
PROCESS_SWITCH_VERSION(PROCESS, SWITCH_VERSION, ProcessAuditOperatorImpl.class, new String[]{CODE, VERSION}, |
||||
new String[]{}), |
||||
PROCESS_DELETE_VERSION(PROCESS, DELETE_VERSION, ProcessAuditOperatorImpl.class, new String[]{CODE, VERSION}, |
||||
new String[]{}), |
||||
PROCESS_RELEASE(PROCESS, RELEASE, ProcessAuditOperatorImpl.class, new String[]{WORKFLOW_DEFINITION_CODE}, |
||||
new String[]{}), |
||||
PROCESS_COPY(PROCESS, COPY, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}), |
||||
PROCESS_EXPORT(PROCESS, EXPORT, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}), |
||||
PROCESS_DELETE(PROCESS, DELETE, ProcessAuditOperatorImpl.class, new String[]{CODE}, new String[]{}), |
||||
PROCESS_BATCH_DELETE(PROCESS, BATCH_DELETE, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}), |
||||
PROCESS_START(PROCESS, START, ProcessAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODE}, |
||||
new String[]{}), |
||||
PROCESS_BATCH_START(PROCESS, BATCH_START, ProcessAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODES}, |
||||
new String[]{}), |
||||
PROCESS_BATCH_RERUN(PROCESS, BATCH_RERUN, ProcessInstanceAuditOperatorImpl.class, |
||||
new String[]{PROCESS_INSTANCE_IDS}, |
||||
new String[]{}), |
||||
PROCESS_EXECUTE(PROCESS, EXECUTE, ProcessInstanceAuditOperatorImpl.class, new String[]{PROCESS_INSTANCE_ID}, |
||||
new String[]{}), |
||||
PROCESS_IMPORT(PROCESS, IMPORT, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
PROCESS_INSTANCE_UPDATE(PROCESS_INSTANCE, UPDATE, ProcessInstanceAuditOperatorImpl.class, new String[]{ID}, |
||||
new String[]{}), |
||||
PROCESS_INSTANCE_DELETE(PROCESS_INSTANCE, DELETE, ProcessInstanceAuditOperatorImpl.class, new String[]{ID}, |
||||
new String[]{}), |
||||
PROCESS_INSTANCE_BATCH_DELETE(PROCESS_INSTANCE, BATCH_DELETE, ProcessInstanceAuditOperatorImpl.class, |
||||
new String[]{PROCESS_INSTANCE_IDS}, new String[]{}), |
||||
|
||||
TASK_CREATE(TASK, CREATE, TaskAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
TASK_UPDATE(TASK, UPDATE, TaskAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
TASK_SWITCH_VERSION(TASK, SWITCH_VERSION, TaskAuditOperatorImpl.class, new String[]{CODE, VERSION}, new String[]{}), |
||||
TASK_DELETE_VERSION(TASK, DELETE_VERSION, TaskAuditOperatorImpl.class, new String[]{CODE, VERSION}, new String[]{}), |
||||
TASK_DELETE(TASK, DELETE, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}), |
||||
TASK_RELEASE(TASK, RELEASE, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}), |
||||
TASK_START(TASK, START, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}), |
||||
TASK_INSTANCE_FORCE_SUCCESS(TASK_INSTANCE, FORCE_SUCCESS, TaskInstancesAuditOperatorImpl.class, new String[]{ID}, |
||||
new String[]{}), |
||||
|
||||
SCHEDULE_CREATE(SCHEDULE, CREATE, ScheduleAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODE}, |
||||
new String[]{ID}), |
||||
SCHEDULE_UPDATE(SCHEDULE, UPDATE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
SCHEDULE_ONLINE(SCHEDULE, ONLINE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
SCHEDULE_OFFLINE(SCHEDULE, OFFLINE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
SCHEDULE_DELETE(SCHEDULE, DELETE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
FOLDER_CREATE(FOLDER, CREATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, ALIAS}, new String[]{}), |
||||
FILE_CREATE(FILE, CREATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, FILE_NAME, ALIAS}, new String[]{}), |
||||
FILE_UPDATE(FILE, UPDATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, FILE_NAME, ALIAS}, new String[]{}), |
||||
FILE_DELETE(FILE, DELETE, ResourceAuditOperatorImpl.class, new String[]{FULL_NAME}, new String[]{}), |
||||
|
||||
UDF_FUNCTION_CREATE(UDF_FUNCTION, CREATE, UdfFunctionAuditOperatorImpl.class, new String[]{FUNC_NAME}, |
||||
new String[]{}), |
||||
UDF_FUNCTION_UPDATE(UDF_FUNCTION, UPDATE, UdfFunctionAuditOperatorImpl.class, new String[]{FUNC_NAME}, |
||||
new String[]{}), |
||||
UDF_FUNCTION_DELETE(UDF_FUNCTION, DELETE, UdfFunctionAuditOperatorImpl.class, new String[]{UDF_FUNC_ID}, |
||||
new String[]{}), |
||||
|
||||
TASK_GROUP_CREATE(TASK_GROUP, CREATE, TaskGroupAuditOperatorImpl.class, new String[]{NAME}, new String[]{}), |
||||
TASK_GROUP_UPDATE(TASK_GROUP, UPDATE, TaskGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
TASK_GROUP_CLOSE(TASK_GROUP, CLOSE, TaskGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
TASK_GROUP_START(TASK_GROUP, START, TaskGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
TASK_GROUP_MODIFY(TASK_GROUP, MODIFY, TaskGroupAuditOperatorImpl.class, new String[]{QUEUE_ID, PRIORITY}, |
||||
new String[]{}), |
||||
|
||||
DATASOURCE_CREATE(DATASOURCE, CREATE, DatasourceAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
DATASOURCE_UPDATE(DATASOURCE, UPDATE, DatasourceAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
DATASOURCE_DELETE(DATASOURCE, DELETE, DatasourceAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
TENANT_CREATE(TENANT, CREATE, TenantAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
TENANT_UPDATE(TENANT, UPDATE, TenantAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
TENANT_DELETE(TENANT, DELETE, TenantAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
USER_CREATE(USER, CREATE, UserAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
USER_UPDATE(USER, UPDATE, UserAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
USER_DELETE(USER, DELETE, UserAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
ALARM_GROUP_CREATE(ALARM_GROUP, CREATE, AlertGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
ALARM_GROUP_UPDATE(ALARM_GROUP, UPDATE, AlertGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
ALARM_GROUP_DELETE(ALARM_GROUP, DELETE, AlertGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
ALARM_INSTANCE_CREATE(ALARM_INSTANCE, CREATE, AlertInstanceAuditOperatorImpl.class, new String[]{}, |
||||
new String[]{ID}), |
||||
ALARM_INSTANCE_UPDATE(ALARM_INSTANCE, UPDATE, AlertInstanceAuditOperatorImpl.class, new String[]{}, |
||||
new String[]{ID}), |
||||
ALARM_INSTANCE_DELETE(ALARM_INSTANCE, DELETE, AlertInstanceAuditOperatorImpl.class, new String[]{ID}, |
||||
new String[]{}), |
||||
|
||||
WORKER_GROUP_CREATE(WORKER_GROUP, CREATE, WorkerGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
WORKER_GROUP_DELETE(WORKER_GROUP, DELETE, WorkerGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
YARN_QUEUE_CREATE(YARN_QUEUE, CREATE, YarnQueueAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
YARN_QUEUE_UPDATE(YARN_QUEUE, UPDATE, YarnQueueAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
YARN_QUEUE_DELETE(YARN_QUEUE, DELETE, YarnQueueAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
ENVIRONMENT_CREATE(ENVIRONMENT, CREATE, EnvironmentAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
ENVIRONMENT_UPDATE(ENVIRONMENT, UPDATE, EnvironmentAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
ENVIRONMENT_DELETE(ENVIRONMENT, DELETE, EnvironmentAuditOperatorImpl.class, new String[]{ENVIRONMENT_CODE}, |
||||
new String[]{}), |
||||
|
||||
CLUSTER_CREATE(CLUSTER, CREATE, ClusterAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
CLUSTER_UPDATE(CLUSTER, UPDATE, ClusterAuditOperatorImpl.class, new String[]{}, new String[]{CODE}), |
||||
CLUSTER_DELETE(CLUSTER, DELETE, ClusterAuditOperatorImpl.class, new String[]{CLUSTER_CODE}, new String[]{}), |
||||
|
||||
K8S_NAMESPACE_CREATE(K8S_NAMESPACE, CREATE, K8SNamespaceAuditOperatorImpl.class, new String[]{}, new String[]{ID}), |
||||
K8S_NAMESPACE_DELETE(K8S_NAMESPACE, DELETE, K8SNamespaceAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
|
||||
TOKEN_CREATE(TOKEN, CREATE, TokenAuditOperatorImpl.class, new String[]{}, new String[]{USER_ID}), |
||||
TOKEN_UPDATE(TOKEN, UPDATE, TokenAuditOperatorImpl.class, new String[]{}, new String[]{USER_ID}), |
||||
TOKEN_DELETE(TOKEN, DELETE, TokenAuditOperatorImpl.class, new String[]{ID}, new String[]{}), |
||||
; |
||||
|
||||
private final Class<? extends AuditOperator> operatorClass; |
||||
private final AuditModelType auditModelType; |
||||
private final AuditOperationType auditOperationType; |
||||
|
||||
/** |
||||
* The names of the fields in the API request to be recorded. |
||||
* Represents an array of key-value pairs, e.g., [ID, "status"]. |
||||
*/ |
||||
private final String[] requestParamName; |
||||
|
||||
/** |
||||
* The names of the fields in the returned object to be recorded. |
||||
* Represents an array of field names, e.g., [ID, CODE]. |
||||
* Specify the field names to record from the returned object. |
||||
*/ |
||||
private final String[] returnObjectFieldName; |
||||
|
||||
AuditType(AuditModelType auditModelType, AuditOperationType auditOperationType, |
||||
Class<? extends AuditOperator> operatorClass, String[] requestParamName, String[] returnObjectFieldName) { |
||||
this.auditModelType = auditModelType; |
||||
this.auditOperationType = auditOperationType; |
||||
this.operatorClass = operatorClass; |
||||
this.requestParamName = requestParamName; |
||||
this.returnObjectFieldName = returnObjectFieldName; |
||||
} |
||||
} |
@ -0,0 +1,208 @@
|
||||
/* |
||||
* 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 org.apache.commons.lang3.math.NumberUtils; |
||||
|
||||
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 BaseAuditOperator implements AuditOperator { |
||||
|
||||
@Autowired |
||||
private AuditService auditService; |
||||
|
||||
@Override |
||||
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).getModelId() == null) { |
||||
auditLogList.get(0).setModelId(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).setModelName(value.toString()); |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
long objectId = Long.parseLong(value.toString()); |
||||
auditLogList.get(0).setModelId(objectId); |
||||
} catch (NumberFormatException e) { |
||||
log.error("value is not long, value: {}", value); |
||||
} |
||||
|
||||
auditLogList.get(0).setModelName(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 = toLong(identityString); |
||||
|
||||
String value = getObjectNameFromReturnIdentity(identity); |
||||
|
||||
if (value == null) { |
||||
continue; |
||||
} |
||||
|
||||
auditLog.setModelId(identity); |
||||
auditLog.setModelName(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.setModelName(getObjectNameFromReturnIdentity(auditLog.getModelId()))); |
||||
} |
||||
|
||||
protected void modifyObjectFromReturnObject(String[] params, Map<String, Object> returnObjectMap, |
||||
List<AuditLog> auditLogList) { |
||||
if (returnObjectMap.isEmpty() || returnObjectMap.get(params[0]) == null) { |
||||
return; |
||||
} |
||||
|
||||
Long objId = toLong(returnObjectMap.get(params[0])); |
||||
|
||||
if (objId != -1) { |
||||
auditLogList.get(0).setModelId(objId); |
||||
} |
||||
} |
||||
|
||||
protected Long toLong(Object str) { |
||||
if (str == null) { |
||||
return -1L; |
||||
} |
||||
|
||||
return NumberUtils.toLong(str.toString(), -1); |
||||
} |
||||
|
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
return identity.toString(); |
||||
} |
||||
|
||||
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) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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.Service; |
||||
|
||||
@Service |
||||
public class AlertInstanceAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private AlertPluginInstanceMapper alertPluginInstanceMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
AlertPluginInstance obj = alertPluginInstanceMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getInstanceName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.Cluster; |
||||
import org.apache.dolphinscheduler.dao.mapper.ClusterMapper; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class ClusterAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private ClusterMapper clusterMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
Cluster obj = clusterMapper.queryByClusterCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 DatasourceAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private DataSourceMapper dataSourceMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
DataSource obj = dataSourceMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.Environment; |
||||
import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class EnvironmentAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private EnvironmentMapper environmentMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
Environment obj = environmentMapper.queryByEnvironmentCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 K8SNamespaceAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private K8sNamespaceMapper k8sNamespaceMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
K8sNamespace obj = k8sNamespaceMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getNamespace(); |
||||
} |
||||
} |
@ -0,0 +1,77 @@
|
||||
/* |
||||
* 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.OperatorUtils; |
||||
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class ProcessAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private ProcessDefinitionMapper processDefinitionMapper; |
||||
|
||||
@Override |
||||
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap); |
||||
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName())); |
||||
} |
||||
|
||||
@Override |
||||
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
if (paramNameArr[0].equals(AuditLogConstants.CODES) |
||||
|| paramNameArr[0].equals(AuditLogConstants.PROCESS_DEFINITION_CODES) |
||||
|| paramNameArr[0].equals(AuditLogConstants.PROCESS_INSTANCE_IDS)) { |
||||
super.setObjectByParmaArr(paramNameArr, paramsMap, auditLogList); |
||||
} else { |
||||
super.setObjectByParma(paramNameArr, paramsMap, auditLogList); |
||||
} |
||||
if (paramsMap.containsKey(AuditLogConstants.VERSION)) { |
||||
if (paramsMap.get(AuditLogConstants.VERSION) != null) { |
||||
auditLogList.get(0).setDetail(paramsMap.get(AuditLogConstants.VERSION).toString()); |
||||
} else { |
||||
auditLogList.get(0).setDetail("latest"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
ProcessDefinition obj = processDefinitionMapper.queryByCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
/* |
||||
* 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.OperatorUtils; |
||||
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class ProcessInstanceAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private ProcessInstanceMapper processInstanceMapper; |
||||
|
||||
@Override |
||||
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap); |
||||
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName())); |
||||
} |
||||
|
||||
@Override |
||||
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
if (paramNameArr[0].equals(AuditLogConstants.PROCESS_INSTANCE_IDS)) { |
||||
super.setObjectByParmaArr(paramNameArr, paramsMap, auditLogList); |
||||
} else { |
||||
super.setObjectByParma(paramNameArr, paramsMap, auditLogList); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
int objId = NumberUtils.toInt(identity.toString(), -1); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
ProcessInstance obj = processInstanceMapper.queryDetailById(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.Project; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class ProjectAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private ProjectMapper projectMapper; |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
Project obj = projectMapper.queryByCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
/* |
||||
* 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.OperatorUtils; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class ResourceAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Override |
||||
public void modifyAuditObjectType(AuditType auditType, Map<String, Object> paramsMap, List<AuditLog> auditLogList) { |
||||
auditLogList.forEach(auditLog -> auditLog |
||||
.setModelType(OperatorUtils.getFileAuditObject(auditType, paramsMap, auditLog.getModelName()))); |
||||
} |
||||
|
||||
@Override |
||||
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
|
||||
Object objName = getFileNameFromParam(paramNameArr, paramsMap); |
||||
|
||||
if (objName == null) { |
||||
return; |
||||
} |
||||
|
||||
auditLogList.get(0).setModelName(objName.toString()); |
||||
} |
||||
|
||||
private String getFileNameFromParam(String[] paramNameArr, Map<String, Object> paramsMap) { |
||||
for (String param : paramNameArr) { |
||||
if (!param.equals("type") && paramsMap.containsKey(param)) { |
||||
return paramsMap.get(param).toString(); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
/* |
||||
* 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.OperatorUtils; |
||||
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||
import org.apache.dolphinscheduler.dao.entity.Schedule; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
||||
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class ScheduleAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private ScheduleMapper scheduleMapper; |
||||
|
||||
@Autowired |
||||
private ProcessDefinitionMapper processDefinitionMapper; |
||||
|
||||
@Override |
||||
public void modifyRequestParams(String[] paramNameArr, Map<String, Object> paramsMap, List<AuditLog> auditLogList) { |
||||
if (!paramNameArr[0].equals(AuditLogConstants.ID)) { |
||||
return; |
||||
} |
||||
int id = (int) paramsMap.get(paramNameArr[0]); |
||||
Schedule schedule = scheduleMapper.selectById(id); |
||||
if (schedule != null) { |
||||
paramsMap.put(AuditLogConstants.CODE, schedule.getProcessDefinitionCode()); |
||||
paramNameArr[0] = AuditLogConstants.CODE; |
||||
auditLogList.forEach(auditLog -> auditLog.setDetail(String.valueOf(id))); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
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); |
||||
auditLogList |
||||
.forEach(auditLog -> auditLog.setDetail(returnObjectMap.get(returnObjectFieldNameArr[0]).toString())); |
||||
} |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
ProcessDefinition obj = processDefinitionMapper.queryByCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,68 @@
|
||||
/* |
||||
* 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.OperatorUtils; |
||||
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
||||
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class TaskAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private TaskDefinitionMapper taskDefinitionMapper; |
||||
|
||||
@Override |
||||
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap); |
||||
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName())); |
||||
} |
||||
|
||||
@Override |
||||
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
|
||||
super.setObjectByParma(paramNameArr, paramsMap, auditLogList); |
||||
if (paramsMap.containsKey(AuditLogConstants.VERSION)) { |
||||
auditLogList.get(0).setDetail(paramsMap.get(AuditLogConstants.VERSION).toString()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
TaskDefinition obj = taskDefinitionMapper.queryByCode(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.TaskGroup; |
||||
import org.apache.dolphinscheduler.dao.mapper.TaskGroupMapper; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class TaskGroupAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private TaskGroupMapper taskGroupMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
TaskGroup obj = taskGroupMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 TaskInstancesAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private TaskInstanceMapper taskInstanceMapper; |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
TaskInstance obj = taskInstanceMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 TenantAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private TenantMapper tenantMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
Tenant obj = tenantMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getTenantCode(); |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
/* |
||||
* 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.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
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 TokenAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private AccessTokenMapper accessTokenMapper; |
||||
|
||||
@Autowired |
||||
private UserMapper userMapper; |
||||
|
||||
@Override |
||||
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
if (paramsMap.get(AuditLogConstants.USER_ID) != null) { |
||||
User user = userMapper.selectById(paramsMap.get(AuditLogConstants.USER_ID).toString()); |
||||
auditLogList.forEach(auditLog -> { |
||||
auditLog.setModelName(user.getUserName()); |
||||
auditLog.setModelId(Long.valueOf(user.getId())); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
AccessToken obj = accessTokenMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getUserName(); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
import org.apache.dolphinscheduler.dao.entity.UdfFunc; |
||||
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; |
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class UdfFunctionAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private UdfFuncMapper udfFuncMapper; |
||||
|
||||
@Override |
||||
protected String getObjectNameFromReturnIdentity(Object identity) { |
||||
int objId = NumberUtils.toInt(identity.toString(), -1); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
UdfFunc obj = udfFuncMapper.selectUdfById(objId); |
||||
return obj == null ? "" : obj.getFuncName(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 UserAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private UserMapper userMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
User obj = userMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getUserName(); |
||||
} |
||||
} |
@ -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.constants.AuditLogConstants; |
||||
import org.apache.dolphinscheduler.api.audit.enums.AuditType; |
||||
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator; |
||||
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 WorkerGroupAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private WorkerGroupMapper workerGroupMapper; |
||||
|
||||
@Override |
||||
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap, |
||||
List<AuditLog> auditLogList) { |
||||
if (auditType.getAuditOperationType() == AuditOperationType.CREATE |
||||
&& paramsMap.get(AuditLogConstants.ID) != null && |
||||
!paramsMap.get(AuditLogConstants.ID).toString().equals("0")) { |
||||
auditLogList.forEach(auditLog -> auditLog.setOperationType(AuditOperationType.UPDATE.getName())); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
WorkerGroup obj = workerGroupMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getName(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.BaseAuditOperator; |
||||
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 YarnQueueAuditOperatorImpl extends BaseAuditOperator { |
||||
|
||||
@Autowired |
||||
private QueueMapper queueMapper; |
||||
|
||||
@Override |
||||
public String getObjectNameFromReturnIdentity(Object identity) { |
||||
Long objId = toLong(identity); |
||||
if (objId == -1) { |
||||
return ""; |
||||
} |
||||
|
||||
Queue obj = queueMapper.selectById(objId); |
||||
return obj == null ? "" : obj.getQueueName(); |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.dto.auditLog; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.AuditModelType; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class AuditModelTypeDto { |
||||
|
||||
private String name; |
||||
|
||||
private List<AuditModelTypeDto> child = null; |
||||
|
||||
public static List<AuditModelTypeDto> getModelTypeDtoList() { |
||||
List<AuditModelTypeDto> dtoList = new ArrayList<>(); |
||||
transFromEnumListToDto(dtoList, AuditModelType.getAuditModelTreeList()); |
||||
return dtoList; |
||||
} |
||||
|
||||
public static List<AuditModelTypeDto> transFromEnumListToDto(List<AuditModelTypeDto> dtoList, |
||||
List<AuditModelType> objectTypeList) { |
||||
for (AuditModelType operationType : objectTypeList) { |
||||
dtoList.add(transFromEnumToDto(operationType)); |
||||
} |
||||
|
||||
return dtoList; |
||||
} |
||||
|
||||
public static AuditModelTypeDto transFromEnumToDto(AuditModelType operationType) { |
||||
AuditModelTypeDto dto = new AuditModelTypeDto(); |
||||
dto.setName(operationType.getName()); |
||||
|
||||
if (!operationType.getChild().isEmpty()) { |
||||
dto.setChild(transFromEnumListToDto(new ArrayList<>(), operationType.getChild())); |
||||
} |
||||
|
||||
return dto; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
/* |
||||
* 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.dto.auditLog; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class AuditOperationTypeDto { |
||||
|
||||
private String name; |
||||
|
||||
public static List<AuditOperationTypeDto> getOperationTypeDtoList() { |
||||
List<AuditOperationTypeDto> dtoList = new ArrayList<>(); |
||||
for (AuditOperationType operationType : AuditOperationType.getOperationList()) { |
||||
AuditOperationTypeDto dto = new AuditOperationTypeDto(); |
||||
dto.setName(operationType.getName()); |
||||
dtoList.add(dto); |
||||
} |
||||
|
||||
return dtoList; |
||||
} |
||||
} |
@ -1,50 +0,0 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.AuditOperationType; |
||||
import org.apache.dolphinscheduler.common.enums.AuditResourceType; |
||||
import org.apache.dolphinscheduler.dao.entity.AuditLog; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
public class AuditSubscriberTest { |
||||
|
||||
@Mock |
||||
private AuditLogMapper logMapper; |
||||
|
||||
@InjectMocks |
||||
private AuditSubscriberImpl auditSubscriber; |
||||
|
||||
@Test |
||||
public void testExecute() { |
||||
Mockito.when(logMapper.insert(Mockito.any(AuditLog.class))).thenReturn(1); |
||||
auditSubscriber.execute( |
||||
new AuditMessage(new User(), new Date(), AuditResourceType.USER_MODULE, AuditOperationType.CREATE, 1)); |
||||
} |
||||
} |
@ -0,0 +1,98 @@
|
||||
/* |
||||
* 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.common.enums; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* Audit Model type |
||||
*/ |
||||
@Getter |
||||
public enum AuditModelType { |
||||
|
||||
PROJECT("Project", null), // 1
|
||||
PROCESS("Process", PROJECT), |
||||
PROCESS_INSTANCE("ProcessInstance", PROCESS), |
||||
TASK("Task", PROCESS), |
||||
TASK_INSTANCE("TaskInstance", TASK), |
||||
SCHEDULE("Schedule", PROCESS), |
||||
|
||||
RESOURCE("Resource", null), |
||||
FOLDER("Folder", RESOURCE), |
||||
FILE("File", FOLDER), |
||||
UDF_FOLDER("UDFFolder", RESOURCE), |
||||
UDF_FILE("UDFFile", UDF_FOLDER), |
||||
UDF_FUNCTION("UDFFunction", RESOURCE), |
||||
TASK_GROUP("TaskGroup", RESOURCE), |
||||
|
||||
DATASOURCE("Datasource", null), |
||||
|
||||
SECURITY("Security", null), |
||||
TENANT("Tenant", SECURITY), |
||||
USER("User", SECURITY), |
||||
ALARM_GROUP("AlarmGroup", SECURITY), |
||||
ALARM_INSTANCE("AlarmInstance", SECURITY), |
||||
WORKER_GROUP("WorkerGroup", SECURITY), |
||||
YARN_QUEUE("YarnQueue", SECURITY), |
||||
ENVIRONMENT("Environment", SECURITY), |
||||
CLUSTER("Cluster", SECURITY), |
||||
K8S_NAMESPACE("K8sNamespace", SECURITY), |
||||
TOKEN("Token", SECURITY), |
||||
; |
||||
private final String name; |
||||
private final AuditModelType parentType; |
||||
private final List<AuditModelType> child = new ArrayList<>(); |
||||
|
||||
private static final HashMap<String, AuditModelType> AUDIT_MODEL_MAP = new HashMap<>(); |
||||
private static final List<AuditModelType> AUDIT_MODEL_TREE_LIST = new ArrayList<>(); |
||||
|
||||
static { |
||||
for (AuditModelType auditModelType : values()) { |
||||
AUDIT_MODEL_MAP.put(auditModelType.name, auditModelType); |
||||
} |
||||
|
||||
for (AuditModelType auditModelType : values()) { |
||||
if (auditModelType.parentType != null) { |
||||
of(auditModelType.parentType.name).child.add(auditModelType); |
||||
} else { |
||||
AUDIT_MODEL_TREE_LIST.add(auditModelType); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static List<AuditModelType> getAuditModelTreeList() { |
||||
return AUDIT_MODEL_TREE_LIST; |
||||
} |
||||
|
||||
public static AuditModelType of(String name) { |
||||
if (AUDIT_MODEL_MAP.containsKey(name)) { |
||||
return AUDIT_MODEL_MAP.get(name); |
||||
} |
||||
|
||||
throw new IllegalArgumentException("invalid audit operation type name " + name); |
||||
} |
||||
|
||||
AuditModelType(String name, AuditModelType parentType) { |
||||
this.name = name; |
||||
this.parentType = parentType; |
||||
} |
||||
} |
@ -1,61 +0,0 @@
|
||||
/* |
||||
* 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.common.enums; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* Audit Module type |
||||
*/ |
||||
public enum AuditResourceType { |
||||
|
||||
// TODO: add other audit resource enums
|
||||
USER_MODULE(0, "USER"), |
||||
PROJECT_MODULE(1, "PROJECT"); |
||||
|
||||
private final int code; |
||||
private final String enMsg; |
||||
|
||||
private static HashMap<Integer, AuditResourceType> AUDIT_RESOURCE_MAP = new HashMap<>(); |
||||
|
||||
static { |
||||
for (AuditResourceType auditResourceType : AuditResourceType.values()) { |
||||
AUDIT_RESOURCE_MAP.put(auditResourceType.code, auditResourceType); |
||||
} |
||||
} |
||||
|
||||
AuditResourceType(int code, String enMsg) { |
||||
this.code = code; |
||||
this.enMsg = enMsg; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return this.code; |
||||
} |
||||
|
||||
public String getMsg() { |
||||
return this.enMsg; |
||||
} |
||||
|
||||
public static AuditResourceType of(int status) { |
||||
if (AUDIT_RESOURCE_MAP.containsKey(status)) { |
||||
return AUDIT_RESOURCE_MAP.get(status); |
||||
} |
||||
throw new IllegalArgumentException("invalid audit resource type code " + status); |
||||
} |
||||
} |
Loading…
Reference in new issue