Unverified Commit 3b4b431e authored by luoshangjie's avatar luoshangjie Committed by GitHub

[Improve] Improve the implementation logic for task operation permission check (#3610)

parent 7cdc3bf8
...@@ -21,20 +21,14 @@ package org.dinky.aop; ...@@ -21,20 +21,14 @@ package org.dinky.aop;
import org.dinky.data.annotations.CheckTaskOwner; import org.dinky.data.annotations.CheckTaskOwner;
import org.dinky.data.constant.BaseConstant; import org.dinky.data.constant.BaseConstant;
import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.dto.TaskRollbackVersionDTO;
import org.dinky.data.dto.TaskSaveDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.enums.TaskOwnerLockStrategyEnum; import org.dinky.data.enums.TaskOwnerLockStrategyEnum;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.model.Catalogue;
import org.dinky.data.model.SystemConfiguration; import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.Task;
import org.dinky.service.TaskService;
import org.dinky.service.catalogue.CatalogueService;
import java.util.List; import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Objects; import java.util.Objects;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -42,22 +36,20 @@ import javax.annotation.Resource; ...@@ -42,22 +36,20 @@ import javax.annotation.Resource;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Aspect @Aspect
@Slf4j @Slf4j
@Component @Component
public class TaskOperationCheckAspect { public class TaskOperationPermissionAspect {
@Resource @Resource
private TaskService taskService; private ApplicationContext applicationContext;
@Resource
private CatalogueService catalogueService;
/** /**
* Check whether the user has the permission to perform the task. * Check whether the user has the permission to perform the task.
...@@ -72,22 +64,15 @@ public class TaskOperationCheckAspect { ...@@ -72,22 +64,15 @@ public class TaskOperationCheckAspect {
if (!TaskOwnerLockStrategyEnum.ALL.equals( if (!TaskOwnerLockStrategyEnum.ALL.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy()) SystemConfiguration.getInstances().getTaskOwnerLockStrategy())
&& BaseConstant.ADMIN_ID != StpUtil.getLoginIdAsInt()) { && BaseConstant.ADMIN_ID != StpUtil.getLoginIdAsInt()) {
Class serviceType = checkTaskOwner.serviceType(); Class checkParam = checkTaskOwner.checkParam();
Integer id = getId(joinPoint); Object param = getParam(joinPoint, checkParam);
if (Objects.nonNull(id)) { if (Objects.nonNull(param)) {
Task task = null; Object bean = applicationContext.getBean(checkTaskOwner.checkInterface());
if (TaskService.class.equals(serviceType)) { Class<?> clazz = bean.getClass();
task = taskService.getById(id); Method method = clazz.getMethod(checkTaskOwner.checkMethod(), param.getClass());
} else if (CatalogueService.class.equals(serviceType)) { Object invoke = method.invoke(bean, param);
Catalogue catalogue = catalogueService.getById(id); if (invoke != null && !(Boolean) invoke) {
if (BeanUtil.isNotEmpty(catalogue) && catalogue.getIsLeaf()) { throw new BusException(Status.TASK_NOT_OPERATE_PERMISSION);
task = taskService.getById(catalogue.getTaskId());
}
}
if (Objects.nonNull(task)) {
if (!hasPermission(task.getFirstLevelOwner(), task.getSecondLevelOwners())) {
throw new BusException(Status.TASK_NOT_OPERATE_PERMISSION);
}
} }
} }
} }
...@@ -101,37 +86,41 @@ public class TaskOperationCheckAspect { ...@@ -101,37 +86,41 @@ public class TaskOperationCheckAspect {
return result; return result;
} }
private Boolean hasPermission(Integer firstLevelOwner, List<Integer> secondLevelOwners) { private Object getParam(ProceedingJoinPoint joinPoint, Class paramAnno) throws IllegalAccessException {
boolean isFirstLevelOwner = firstLevelOwner != null && firstLevelOwner == StpUtil.getLoginIdAsInt(); Object[] params = joinPoint.getArgs();
if (TaskOwnerLockStrategyEnum.OWNER.equals( if (params.length == 0) {
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) { return null;
return isFirstLevelOwner;
} else if (TaskOwnerLockStrategyEnum.OWNER_AND_MAINTAINER.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) {
return isFirstLevelOwner
|| (secondLevelOwners != null && secondLevelOwners.contains(StpUtil.getLoginIdAsInt()));
} }
return true;
}
private Integer getId(ProceedingJoinPoint joinPoint) { Object paramObj = null;
Integer id = null; // Get the method, here you can convert the signature strong to MethodSignature
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Object[] args = joinPoint.getArgs(); Annotation[][] annotations = method.getParameterAnnotations();
if (args[0] instanceof Integer) { for (int i = 0; i < annotations.length; i++) {
id = (Integer) args[0]; Object param = params[i];
} else if (args[0] instanceof TaskDTO) { if (param == null) {
id = ((TaskDTO) args[0]).getId(); continue;
} else if (args[0] instanceof TaskSaveDTO) { }
id = ((TaskSaveDTO) args[0]).getId(); Annotation[] paramAnn = annotations[i];
} else if (args[0] instanceof TaskRollbackVersionDTO) { for (Annotation annotation : paramAnn) {
id = ((TaskRollbackVersionDTO) args[0]).getTaskId(); if (annotation.annotationType() == paramAnno) {
} else if (args[0] instanceof CatalogueTaskDTO) { paramObj = param;
id = ((CatalogueTaskDTO) args[0]).getTaskId(); break;
} else if (args[0] instanceof Catalogue) { }
id = ((Catalogue) args[0]).getTaskId(); }
if (paramObj == null) {
Field[] fields = param.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(paramAnno)) {
field.setAccessible(true);
paramObj = field.get(param);
break;
}
}
}
} }
return paramObj;
return id;
} }
} }
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
package org.dinky.controller; package org.dinky.controller;
import org.dinky.data.annotations.CatalogueId;
import org.dinky.data.annotations.CheckTaskOwner; import org.dinky.data.annotations.CheckTaskOwner;
import org.dinky.data.annotations.Log; import org.dinky.data.annotations.Log;
import org.dinky.data.annotations.TaskId;
import org.dinky.data.dto.CatalogueTaskDTO; import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.dto.CatalogueTreeQueryDTO; import org.dinky.data.dto.CatalogueTreeQueryDTO;
import org.dinky.data.enums.BusinessType; import org.dinky.data.enums.BusinessType;
...@@ -165,7 +167,7 @@ public class CatalogueController { ...@@ -165,7 +167,7 @@ public class CatalogueController {
required = true, required = true,
dataType = "CatalogueTaskDTO", dataType = "CatalogueTaskDTO",
dataTypeClass = CatalogueTaskDTO.class) dataTypeClass = CatalogueTaskDTO.class)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Catalogue> createTask(@RequestBody CatalogueTaskDTO catalogueTaskDTO) { public Result<Catalogue> createTask(@RequestBody CatalogueTaskDTO catalogueTaskDTO) {
if (catalogueService.checkCatalogueTaskNameIsExistById(catalogueTaskDTO.getName(), catalogueTaskDTO.getId())) { if (catalogueService.checkCatalogueTaskNameIsExistById(catalogueTaskDTO.getName(), catalogueTaskDTO.getId())) {
return Result.failed(Status.TASK_IS_EXIST); return Result.failed(Status.TASK_IS_EXIST);
...@@ -201,9 +203,9 @@ public class CatalogueController { ...@@ -201,9 +203,9 @@ public class CatalogueController {
dataType = "Integer", dataType = "Integer",
dataTypeClass = Integer.class) dataTypeClass = Integer.class)
}) })
@CheckTaskOwner(serviceType = CatalogueService.class) @CheckTaskOwner(checkParam = CatalogueId.class, checkInterface = CatalogueService.class)
public Result<Boolean> moveCatalogue( public Result<Boolean> moveCatalogue(
@RequestParam("originCatalogueId") Integer originCatalogueId, @CatalogueId @RequestParam("originCatalogueId") Integer originCatalogueId,
@RequestParam("targetParentId") Integer targetParentId) { @RequestParam("targetParentId") Integer targetParentId) {
if (catalogueService.moveCatalogue(originCatalogueId, targetParentId)) { if (catalogueService.moveCatalogue(originCatalogueId, targetParentId)) {
return Result.succeed(true, Status.MOVE_SUCCESS); return Result.succeed(true, Status.MOVE_SUCCESS);
...@@ -226,7 +228,7 @@ public class CatalogueController { ...@@ -226,7 +228,7 @@ public class CatalogueController {
dataType = "Catalogue", dataType = "Catalogue",
dataTypeClass = Catalogue.class) dataTypeClass = Catalogue.class)
@ApiOperation("Copy Task") @ApiOperation("Copy Task")
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Void> copyTask(@RequestBody Catalogue catalogue) { public Result<Void> copyTask(@RequestBody Catalogue catalogue) {
if (catalogueService.copyTask(catalogue)) { if (catalogueService.copyTask(catalogue)) {
return Result.succeed(Status.COPY_SUCCESS); return Result.succeed(Status.COPY_SUCCESS);
...@@ -244,8 +246,8 @@ public class CatalogueController { ...@@ -244,8 +246,8 @@ public class CatalogueController {
@Log(title = "Delete Catalogue By Id", businessType = BusinessType.DELETE) @Log(title = "Delete Catalogue By Id", businessType = BusinessType.DELETE)
@ApiOperation("Delete Catalogue By Id") @ApiOperation("Delete Catalogue By Id")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer", dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer", dataTypeClass = Integer.class)
@CheckTaskOwner(serviceType = CatalogueService.class) @CheckTaskOwner(checkParam = CatalogueId.class, checkInterface = CatalogueService.class)
public Result<Void> deleteCatalogueById(@RequestParam Integer id) { public Result<Void> deleteCatalogueById(@CatalogueId @RequestParam Integer id) {
return catalogueService.deleteCatalogueById(id); return catalogueService.deleteCatalogueById(id);
} }
} }
...@@ -23,6 +23,7 @@ import org.dinky.data.annotations.CheckTaskOwner; ...@@ -23,6 +23,7 @@ import org.dinky.data.annotations.CheckTaskOwner;
import org.dinky.data.annotations.ExecuteProcess; import org.dinky.data.annotations.ExecuteProcess;
import org.dinky.data.annotations.Log; import org.dinky.data.annotations.Log;
import org.dinky.data.annotations.ProcessId; import org.dinky.data.annotations.ProcessId;
import org.dinky.data.annotations.TaskId;
import org.dinky.data.dto.TaskDTO; import org.dinky.data.dto.TaskDTO;
import org.dinky.data.dto.TaskRollbackVersionDTO; import org.dinky.data.dto.TaskRollbackVersionDTO;
import org.dinky.data.dto.TaskSaveDTO; import org.dinky.data.dto.TaskSaveDTO;
...@@ -78,8 +79,8 @@ public class TaskController { ...@@ -78,8 +79,8 @@ public class TaskController {
@ApiOperation("Submit Task") @ApiOperation("Submit Task")
@Log(title = "Submit Task", businessType = BusinessType.SUBMIT) @Log(title = "Submit Task", businessType = BusinessType.SUBMIT)
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT) @ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<JobResult> submitTask(@ProcessId @RequestParam Integer id) throws Exception { public Result<JobResult> submitTask(@TaskId @ProcessId @RequestParam Integer id) throws Exception {
JobResult jobResult = JobResult jobResult =
taskService.submitTask(TaskSubmitDto.builder().id(id).build()); taskService.submitTask(TaskSubmitDto.builder().id(id).build());
if (jobResult.isSuccess()) { if (jobResult.isSuccess()) {
...@@ -99,7 +100,7 @@ public class TaskController { ...@@ -99,7 +100,7 @@ public class TaskController {
dataType = "DebugDTO", dataType = "DebugDTO",
paramType = "body") paramType = "body")
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT) @ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<JobResult> debugTask(@RequestBody TaskDTO task) throws Exception { public Result<JobResult> debugTask(@RequestBody TaskDTO task) throws Exception {
JobResult result = taskService.debugTask(task); JobResult result = taskService.debugTask(task);
if (result.isSuccess()) { if (result.isSuccess()) {
...@@ -111,9 +112,9 @@ public class TaskController { ...@@ -111,9 +112,9 @@ public class TaskController {
@GetMapping("/cancel") @GetMapping("/cancel")
@Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER) @Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
@ApiOperation("Cancel Flink Job") @ApiOperation("Cancel Flink Job")
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Void> cancel( public Result<Void> cancel(
@RequestParam Integer id, @TaskId @RequestParam Integer id,
@RequestParam(defaultValue = "false") boolean withSavePoint, @RequestParam(defaultValue = "false") boolean withSavePoint,
@RequestParam(defaultValue = "false") boolean forceCancel) { @RequestParam(defaultValue = "false") boolean forceCancel) {
if (taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint, forceCancel)) { if (taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint, forceCancel)) {
...@@ -129,8 +130,8 @@ public class TaskController { ...@@ -129,8 +130,8 @@ public class TaskController {
@GetMapping(value = "/restartTask") @GetMapping(value = "/restartTask")
@ApiOperation("Restart Task") @ApiOperation("Restart Task")
@Log(title = "Restart Task", businessType = BusinessType.REMOTE_OPERATION) @Log(title = "Restart Task", businessType = BusinessType.REMOTE_OPERATION)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<JobResult> restartTask(@RequestParam Integer id, String savePointPath) throws Exception { public Result<JobResult> restartTask(@TaskId @RequestParam Integer id, String savePointPath) throws Exception {
JobResult jobResult = taskService.restartTask(id, savePointPath); JobResult jobResult = taskService.restartTask(id, savePointPath);
if (jobResult.isSuccess()) { if (jobResult.isSuccess()) {
return Result.succeed(jobResult, Status.RESTART_SUCCESS); return Result.succeed(jobResult, Status.RESTART_SUCCESS);
...@@ -141,8 +142,8 @@ public class TaskController { ...@@ -141,8 +142,8 @@ public class TaskController {
@GetMapping("/savepoint") @GetMapping("/savepoint")
@Log(title = "Savepoint Trigger", businessType = BusinessType.TRIGGER) @Log(title = "Savepoint Trigger", businessType = BusinessType.TRIGGER)
@ApiOperation("Savepoint Trigger") @ApiOperation("Savepoint Trigger")
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<SavePointResult> savepoint(@RequestParam Integer taskId, @RequestParam String savePointType) { public Result<SavePointResult> savepoint(@TaskId @RequestParam Integer taskId, @RequestParam String savePointType) {
return Result.succeed( return Result.succeed(
taskService.savepointTaskJob( taskService.savepointTaskJob(
taskService.getTaskInfoById(taskId), SavePointType.valueOf(savePointType.toUpperCase())), taskService.getTaskInfoById(taskId), SavePointType.valueOf(savePointType.toUpperCase())),
...@@ -152,8 +153,8 @@ public class TaskController { ...@@ -152,8 +153,8 @@ public class TaskController {
@GetMapping("/changeTaskLife") @GetMapping("/changeTaskLife")
@Log(title = "changeTaskLife", businessType = BusinessType.TRIGGER) @Log(title = "changeTaskLife", businessType = BusinessType.TRIGGER)
@ApiOperation("changeTaskLife") @ApiOperation("changeTaskLife")
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Boolean> changeTaskLife(@RequestParam Integer taskId, @RequestParam Integer lifeCycle) public Result<Boolean> changeTaskLife(@TaskId @RequestParam Integer taskId, @RequestParam Integer lifeCycle)
throws SqlExplainExcepition { throws SqlExplainExcepition {
if (taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.get(lifeCycle))) { if (taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.get(lifeCycle))) {
return Result.succeed(lifeCycle == 2 ? Status.PUBLISH_SUCCESS : Status.OFFLINE_SUCCESS); return Result.succeed(lifeCycle == 2 ? Status.PUBLISH_SUCCESS : Status.OFFLINE_SUCCESS);
...@@ -164,7 +165,7 @@ public class TaskController { ...@@ -164,7 +165,7 @@ public class TaskController {
@PostMapping("/explainSql") @PostMapping("/explainSql")
@ApiOperation("Explain Sql") @ApiOperation("Explain Sql")
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<List<SqlExplainResult>> explainSql(@RequestBody TaskDTO taskDTO) throws NotSupportExplainExcepition { public Result<List<SqlExplainResult>> explainSql(@RequestBody TaskDTO taskDTO) throws NotSupportExplainExcepition {
return Result.succeed(taskService.explainTask(taskDTO), Status.EXECUTE_SUCCESS); return Result.succeed(taskService.explainTask(taskDTO), Status.EXECUTE_SUCCESS);
} }
...@@ -172,7 +173,7 @@ public class TaskController { ...@@ -172,7 +173,7 @@ public class TaskController {
@PostMapping("/getJobPlan") @PostMapping("/getJobPlan")
@ApiOperation("Get Job Plan") @ApiOperation("Get Job Plan")
@ExecuteProcess(type = ProcessType.FLINK_JOB_PLAN) @ExecuteProcess(type = ProcessType.FLINK_JOB_PLAN)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<ObjectNode> getJobPlan(@RequestBody TaskDTO taskDTO) { public Result<ObjectNode> getJobPlan(@RequestBody TaskDTO taskDTO) {
ObjectNode jobPlan = null; ObjectNode jobPlan = null;
jobPlan = taskService.getJobPlan(taskDTO); jobPlan = taskService.getJobPlan(taskDTO);
...@@ -189,7 +190,7 @@ public class TaskController { ...@@ -189,7 +190,7 @@ public class TaskController {
dataType = "TaskSaveDTO", dataType = "TaskSaveDTO",
paramType = "body", paramType = "body",
dataTypeClass = TaskSaveDTO.class) dataTypeClass = TaskSaveDTO.class)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Void> saveOrUpdateTask(@RequestBody TaskSaveDTO task) { public Result<Void> saveOrUpdateTask(@RequestBody TaskSaveDTO task) {
if (taskService.saveOrUpdateTask(task.toTaskEntity())) { if (taskService.saveOrUpdateTask(task.toTaskEntity())) {
return Result.succeed(Status.SAVE_SUCCESS); return Result.succeed(Status.SAVE_SUCCESS);
...@@ -233,7 +234,7 @@ public class TaskController { ...@@ -233,7 +234,7 @@ public class TaskController {
@PostMapping("/rollbackTask") @PostMapping("/rollbackTask")
@ApiOperation("Rollback Task") @ApiOperation("Rollback Task")
@Log(title = "Rollback Task", businessType = BusinessType.UPDATE) @Log(title = "Rollback Task", businessType = BusinessType.UPDATE)
@CheckTaskOwner(serviceType = TaskService.class) @CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Void> rollbackTask(@RequestBody TaskRollbackVersionDTO dto) { public Result<Void> rollbackTask(@RequestBody TaskRollbackVersionDTO dto) {
if (taskService.rollbackTask(dto)) { if (taskService.rollbackTask(dto)) {
return Result.succeed(Status.VERSION_ROLLBACK_SUCCESS); return Result.succeed(Status.VERSION_ROLLBACK_SUCCESS);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.TaskId;
import org.dinky.data.model.ext.TaskExtConfig; import org.dinky.data.model.ext.TaskExtConfig;
import org.dinky.data.typehandler.ListTypeHandler; import org.dinky.data.typehandler.ListTypeHandler;
...@@ -51,6 +52,7 @@ public class CatalogueTaskDTO { ...@@ -51,6 +52,7 @@ public class CatalogueTaskDTO {
private Integer parentId; private Integer parentId;
@ApiModelProperty(value = "Task ID", dataType = "Integer", example = "3", notes = "The ID of the associated task") @ApiModelProperty(value = "Task ID", dataType = "Integer", example = "3", notes = "The ID of the associated task")
@TaskId
private Integer taskId; private Integer taskId;
@ApiModelProperty( @ApiModelProperty(
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.ProcessId; import org.dinky.data.annotations.ProcessId;
import org.dinky.data.annotations.TaskId;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
import org.dinky.data.model.alert.AlertGroup; import org.dinky.data.model.alert.AlertGroup;
import org.dinky.data.model.ext.TaskExtConfig; import org.dinky.data.model.ext.TaskExtConfig;
...@@ -50,6 +51,7 @@ public class TaskDTO extends AbstractStatementDTO { ...@@ -50,6 +51,7 @@ public class TaskDTO extends AbstractStatementDTO {
@ApiModelProperty(value = "ID", dataType = "Integer", example = "6", notes = "The identifier of the execution") @ApiModelProperty(value = "ID", dataType = "Integer", example = "6", notes = "The identifier of the execution")
@ProcessId @ProcessId
@TaskId
private Integer id; private Integer id;
@ApiModelProperty(value = "Name", required = true, dataType = "String", example = "Name") @ApiModelProperty(value = "Name", required = true, dataType = "String", example = "Name")
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.TaskId;
import java.io.Serializable; import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -31,6 +33,7 @@ import lombok.Data; ...@@ -31,6 +33,7 @@ import lombok.Data;
public class TaskRollbackVersionDTO implements Serializable { public class TaskRollbackVersionDTO implements Serializable {
@ApiModelProperty(value = "ID", dataType = "Integer", example = "1", notes = "The identifier of the task") @ApiModelProperty(value = "ID", dataType = "Integer", example = "1", notes = "The identifier of the task")
@TaskId
private Integer taskId; private Integer taskId;
@ApiModelProperty( @ApiModelProperty(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.TaskId;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
import org.dinky.data.model.ext.TaskExtConfig; import org.dinky.data.model.ext.TaskExtConfig;
import org.dinky.data.typehandler.JSONObjectHandler; import org.dinky.data.typehandler.JSONObjectHandler;
...@@ -45,6 +46,7 @@ public class TaskSaveDTO { ...@@ -45,6 +46,7 @@ public class TaskSaveDTO {
/** 主键ID */ /** 主键ID */
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "ID", required = true, dataType = "Integer", example = "1", notes = "Primary Key") @ApiModelProperty(value = "ID", required = true, dataType = "Integer", example = "1", notes = "Primary Key")
@TaskId
private Integer id; private Integer id;
@NotNull( @NotNull(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.data.model; package org.dinky.data.model;
import org.dinky.data.annotations.TaskId;
import org.dinky.mybatis.model.SuperEntity; import org.dinky.mybatis.model.SuperEntity;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -47,6 +48,7 @@ public class Catalogue extends SuperEntity<Catalogue> { ...@@ -47,6 +48,7 @@ public class Catalogue extends SuperEntity<Catalogue> {
private Integer tenantId; private Integer tenantId;
@ApiModelProperty(value = "Task ID", required = true, dataType = "Integer", example = "1") @ApiModelProperty(value = "Task ID", required = true, dataType = "Integer", example = "1")
@TaskId
private Integer taskId; private Integer taskId;
@ApiModelProperty(value = "Type", required = true, dataType = "String", example = "Flinksql") @ApiModelProperty(value = "Type", required = true, dataType = "String", example = "Flinksql")
......
...@@ -288,4 +288,12 @@ public interface TaskService extends ISuperService<Task> { ...@@ -288,4 +288,12 @@ public interface TaskService extends ISuperService<Task> {
* @return * @return
*/ */
JobConfig buildJobSubmitConfig(TaskDTO task); JobConfig buildJobSubmitConfig(TaskDTO task);
/**
* Check task operate permission.
* Contains reflection invocation. Please do not delete.
* @param taskId
* @return
*/
Boolean checkTaskOperatePermission(Integer taskId);
} }
...@@ -149,4 +149,12 @@ public interface CatalogueService extends ISuperService<Catalogue> { ...@@ -149,4 +149,12 @@ public interface CatalogueService extends ISuperService<Catalogue> {
* @return true if the catalogue task name is exist * @return true if the catalogue task name is exist
*/ */
boolean checkCatalogueTaskNameIsExistById(String name, Integer id); boolean checkCatalogueTaskNameIsExistById(String name, Integer id);
/**
* Check task operate permission.
* Contains reflection invocation. Please do not delete.
* @param catalogueId
* @return
*/
Boolean checkTaskOperatePermission(Integer catalogueId);
} }
...@@ -61,6 +61,7 @@ import java.util.ArrayList; ...@@ -61,6 +61,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -586,4 +587,13 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -586,4 +587,13 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
catalogueTaskDTO.setLeaf(true); catalogueTaskDTO.setLeaf(true);
return catalogueTaskDTO; return catalogueTaskDTO;
} }
@Override
public Boolean checkTaskOperatePermission(Integer catalogueId) {
Catalogue catalogue = getById(catalogueId);
if (Objects.nonNull(catalogue) && catalogue.getIsLeaf() && Objects.nonNull(catalogue.getTaskId())) {
return taskService.checkTaskOperatePermission(catalogue.getTaskId());
}
return null;
}
} }
...@@ -36,6 +36,7 @@ import org.dinky.data.enums.JobLifeCycle; ...@@ -36,6 +36,7 @@ import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.JobStatus; import org.dinky.data.enums.JobStatus;
import org.dinky.data.enums.ProcessStepType; import org.dinky.data.enums.ProcessStepType;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.enums.TaskOwnerLockStrategyEnum;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.exception.NotSupportExplainExcepition; import org.dinky.data.exception.NotSupportExplainExcepition;
import org.dinky.data.exception.SqlExplainExcepition; import org.dinky.data.exception.SqlExplainExcepition;
...@@ -129,6 +130,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -129,6 +130,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.lang.tree.Tree;
...@@ -1008,4 +1010,26 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -1008,4 +1010,26 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
} }
return treeNodes; return treeNodes;
} }
@Override
public Boolean checkTaskOperatePermission(Integer taskId) {
TaskDTO taskDTO = getTaskInfoById(taskId);
if (Objects.nonNull(taskDTO)) {
return hasTaskOperatePermission(taskDTO.getFirstLevelOwner(), taskDTO.getSecondLevelOwners());
}
return null;
}
private Boolean hasTaskOperatePermission(Integer firstLevelOwner, List<Integer> secondLevelOwners) {
boolean isFirstLevelOwner = firstLevelOwner != null && firstLevelOwner == StpUtil.getLoginIdAsInt();
if (TaskOwnerLockStrategyEnum.OWNER.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) {
return isFirstLevelOwner;
} else if (TaskOwnerLockStrategyEnum.OWNER_AND_MAINTAINER.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) {
return isFirstLevelOwner
|| (secondLevelOwners != null && secondLevelOwners.contains(StpUtil.getLoginIdAsInt()));
}
return true;
}
} }
/*
*
* 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.dinky.data.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface CatalogueId {}
...@@ -29,5 +29,9 @@ import java.lang.annotation.Target; ...@@ -29,5 +29,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
public @interface CheckTaskOwner { public @interface CheckTaskOwner {
Class serviceType(); Class checkParam();
String checkMethod() default "checkTaskOperatePermission";
Class checkInterface();
} }
/*
*
* 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.dinky.data.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface TaskId {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment