|
16 | 16 |
|
17 | 17 | package com.oceanbase.odc.service.onlineschemachange; |
18 | 18 |
|
| 19 | +import java.util.Objects; |
19 | 20 | import java.util.Optional; |
20 | 21 |
|
21 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
|
32 | 33 | import com.oceanbase.odc.core.shared.constant.ErrorCodes; |
33 | 34 | import com.oceanbase.odc.core.shared.constant.ResourceType; |
34 | 35 | import com.oceanbase.odc.core.shared.constant.TaskType; |
| 36 | +import com.oceanbase.odc.core.shared.exception.NotFoundException; |
35 | 37 | import com.oceanbase.odc.metadb.connection.DatabaseEntity; |
36 | 38 | import com.oceanbase.odc.metadb.connection.DatabaseRepository; |
37 | 39 | import com.oceanbase.odc.metadb.schedule.ScheduleEntity; |
|
40 | 42 | import com.oceanbase.odc.metadb.schedule.ScheduleTaskRepository; |
41 | 43 | import com.oceanbase.odc.service.connection.ConnectionService; |
42 | 44 | import com.oceanbase.odc.service.connection.model.ConnectionConfig; |
| 45 | +import com.oceanbase.odc.service.flow.factory.FlowFactory; |
| 46 | +import com.oceanbase.odc.service.flow.instance.FlowInstance; |
| 47 | +import com.oceanbase.odc.service.iam.HorizontalDataPermissionValidator; |
| 48 | +import com.oceanbase.odc.service.iam.auth.AuthenticationFacade; |
43 | 49 | import com.oceanbase.odc.service.onlineschemachange.model.OnlineSchemaChangeParameters; |
44 | 50 | import com.oceanbase.odc.service.onlineschemachange.model.OnlineSchemaChangeScheduleTaskResult; |
45 | 51 | import com.oceanbase.odc.service.onlineschemachange.model.OscLockDatabaseUserInfo; |
@@ -69,6 +75,13 @@ public class OscService { |
69 | 75 | private ScheduleTaskRepository scheduleTaskRepository; |
70 | 76 | @Autowired |
71 | 77 | private ScheduleRepository scheduleRepository; |
| 78 | + @Autowired |
| 79 | + private AuthenticationFacade authenticationFacade; |
| 80 | + @Autowired |
| 81 | + private HorizontalDataPermissionValidator permissionValidator; |
| 82 | + @Autowired |
| 83 | + private FlowFactory flowFactory; |
| 84 | + |
72 | 85 |
|
73 | 86 | @SkipAuthorize("internal authenticated") |
74 | 87 | public OscLockDatabaseUserInfo getOscDatabaseInfo(@NonNull Long id) { |
@@ -102,6 +115,21 @@ public OscSwapTableVO swapTable(@PathVariable Long scheduleTaskId) { |
102 | 115 | OnlineSchemaChangeParameters oscParameters = JsonUtils.fromJson(scheduleEntity.get().getJobParametersJson(), |
103 | 116 | OnlineSchemaChangeParameters.class); |
104 | 117 |
|
| 118 | + Optional<FlowInstance> optional = flowFactory.getFlowInstance(oscParameters.getFlowInstanceId()); |
| 119 | + FlowInstance flowInstance = optional.orElseThrow( |
| 120 | + () -> new NotFoundException(ResourceType.ODC_FLOW_INSTANCE, "id", oscParameters.getFlowInstanceId())); |
| 121 | + try { |
| 122 | + permissionValidator.checkCurrentOrganization(flowInstance); |
| 123 | + } finally { |
| 124 | + flowInstance.dealloc(); |
| 125 | + } |
| 126 | + |
| 127 | + // check user permission, only creator can swap table manual |
| 128 | + PreConditions.validHasPermission( |
| 129 | + Objects.equals(authenticationFacade.currentUserId(), scheduleEntity.get().getCreatorId()), |
| 130 | + ErrorCodes.AccessDenied, |
| 131 | + "no permission swap table."); |
| 132 | + |
105 | 133 | OnlineSchemaChangeScheduleTaskResult result = JsonUtils.fromJson(scheduleTask.getResultJson(), |
106 | 134 | OnlineSchemaChangeScheduleTaskResult.class); |
107 | 135 |
|
|
0 commit comments