|
10 | 10 | import com.milesight.beaveriot.context.constants.ExchangeContextKeys;
|
11 | 11 | import com.milesight.beaveriot.context.integration.model.Device;
|
12 | 12 | import com.milesight.beaveriot.context.integration.model.ExchangePayload;
|
| 13 | +import com.milesight.beaveriot.context.security.SecurityUserContext; |
13 | 14 | import com.milesight.beaveriot.context.security.TenantContext;
|
14 | 15 | import com.milesight.beaveriot.eventbus.annotations.EventSubscribe;
|
15 | 16 | import com.milesight.beaveriot.eventbus.api.Event;
|
@@ -92,8 +93,15 @@ private void updateScheduled(boolean enabled) {
|
92 | 93 |
|
93 | 94 | private Future<?> runSyncTask(boolean delta) {
|
94 | 95 | val tenantId = TenantContext.getTenantId();
|
| 96 | + val user = SecurityUserContext.getSecurityUser(); |
95 | 97 | return executor.submit(() -> {
|
96 | 98 | TenantContext.setTenantId(tenantId);
|
| 99 | + if (user != null) { |
| 100 | + SecurityUserContext.setSecurityUser(user); |
| 101 | + } else { |
| 102 | + SecurityUserContext.clear(); |
| 103 | + } |
| 104 | + |
97 | 105 | val lockConfiguration = ScopedLockConfiguration.builder(LockScope.TENANT)
|
98 | 106 | .name("msc-integration:sync-all")
|
99 | 107 | .lockAtLeastFor(Duration.ofSeconds(0))
|
@@ -143,6 +151,7 @@ public void disable(String tenantId) {
|
143 | 151 | enabledEntity = "msc-integration.integration.scheduled_data_fetch.enabled"
|
144 | 152 | )
|
145 | 153 | public void scheduledSync() {
|
| 154 | + SecurityUserContext.clear(); |
146 | 155 | runSyncTask(true);
|
147 | 156 | }
|
148 | 157 |
|
@@ -238,10 +247,18 @@ public CompletableFuture<Boolean> syncDeviceData(Task task) {
|
238 | 247 | log.info("Skip execution because device task is running: {}", task.identifier);
|
239 | 248 | return CompletableFuture.completedFuture(null);
|
240 | 249 | }
|
| 250 | + |
241 | 251 | val tenantId = TenantContext.getTenantId();
|
| 252 | + val user = SecurityUserContext.getSecurityUser(); |
242 | 253 | return CompletableFuture.supplyAsync(() -> {
|
243 | 254 | try {
|
244 | 255 | TenantContext.setTenantId(tenantId);
|
| 256 | + if (user != null) { |
| 257 | + SecurityUserContext.setSecurityUser(user); |
| 258 | + } else { |
| 259 | + SecurityUserContext.clear(); |
| 260 | + } |
| 261 | + |
245 | 262 | Device device = null;
|
246 | 263 | switch (task.type) {
|
247 | 264 | case ADD_LOCAL_DEVICE -> device = addLocalDevice(task);
|
|
0 commit comments