Commit dc41e63091076c278db36f4f4fb3ff581cc10979

Authored by Igor Kulikov
1 parent a2d56c2e

Add executor to Access Validator

@@ -50,6 +50,10 @@ import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity; @@ -50,6 +50,10 @@ import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity;
50 import org.thingsboard.server.service.security.model.SecurityUser; 50 import org.thingsboard.server.service.security.model.SecurityUser;
51 51
52 import javax.annotation.Nullable; 52 import javax.annotation.Nullable;
  53 +import javax.annotation.PostConstruct;
  54 +import javax.annotation.PreDestroy;
  55 +import java.util.concurrent.ExecutorService;
  56 +import java.util.concurrent.Executors;
53 import java.util.function.BiConsumer; 57 import java.util.function.BiConsumer;
54 58
55 /** 59 /**
@@ -83,6 +87,20 @@ public class AccessValidator { @@ -83,6 +87,20 @@ public class AccessValidator {
83 @Autowired 87 @Autowired
84 protected RuleChainService ruleChainService; 88 protected RuleChainService ruleChainService;
85 89
  90 + private ExecutorService executor;
  91 +
  92 + @PostConstruct
  93 + public void initExecutor() {
  94 + executor = Executors.newSingleThreadExecutor();
  95 + }
  96 +
  97 + @PreDestroy
  98 + public void shutdownExecutor() {
  99 + if (executor != null) {
  100 + executor.shutdownNow();
  101 + }
  102 + }
  103 +
86 public DeferredResult<ResponseEntity> validateEntityAndCallback(SecurityUser currentUser, String entityType, String entityIdStr, 104 public DeferredResult<ResponseEntity> validateEntityAndCallback(SecurityUser currentUser, String entityType, String entityIdStr,
87 BiConsumer<DeferredResult<ResponseEntity>, EntityId> onSuccess) throws ThingsboardException { 105 BiConsumer<DeferredResult<ResponseEntity>, EntityId> onSuccess) throws ThingsboardException {
88 return validateEntityAndCallback(currentUser, entityType, entityIdStr, onSuccess, (result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); 106 return validateEntityAndCallback(currentUser, entityType, entityIdStr, onSuccess, (result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR));
@@ -162,7 +180,7 @@ public class AccessValidator { @@ -162,7 +180,7 @@ public class AccessValidator {
162 return ValidationResult.ok(); 180 return ValidationResult.ok();
163 } 181 }
164 } 182 }
165 - })); 183 + }), executor);
166 } 184 }
167 } 185 }
168 186
@@ -183,7 +201,7 @@ public class AccessValidator { @@ -183,7 +201,7 @@ public class AccessValidator {
183 return ValidationResult.ok(); 201 return ValidationResult.ok();
184 } 202 }
185 } 203 }
186 - })); 204 + }), executor);
187 } 205 }
188 } 206 }
189 207
@@ -205,7 +223,7 @@ public class AccessValidator { @@ -205,7 +223,7 @@ public class AccessValidator {
205 return ValidationResult.ok(); 223 return ValidationResult.ok();
206 } 224 }
207 } 225 }
208 - })); 226 + }), executor);
209 } 227 }
210 } 228 }
211 229
@@ -226,7 +244,7 @@ public class AccessValidator { @@ -226,7 +244,7 @@ public class AccessValidator {
226 return ValidationResult.ok(); 244 return ValidationResult.ok();
227 } 245 }
228 } 246 }
229 - })); 247 + }), executor);
230 } 248 }
231 } 249 }
232 250
@@ -245,7 +263,7 @@ public class AccessValidator { @@ -245,7 +263,7 @@ public class AccessValidator {
245 } else { 263 } else {
246 return ValidationResult.ok(); 264 return ValidationResult.ok();
247 } 265 }
248 - })); 266 + }), executor);
249 } 267 }
250 } 268 }
251 269