Commit 15f4a85deca7067eeea70ed9f4f221045f594657

Authored by Volodymyr Babak
1 parent e5753c03

Hide sensitive data from customer

... ... @@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.page.TextPageData;
43 43 import org.thingsboard.server.common.data.page.TextPageLink;
44 44 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
45 45 import org.thingsboard.server.common.data.rule.RuleChain;
  46 +import org.thingsboard.server.common.data.security.Authority;
46 47 import org.thingsboard.server.dao.exception.DataValidationException;
47 48 import org.thingsboard.server.dao.exception.IncorrectParameterException;
48 49 import org.thingsboard.server.dao.model.ModelConstants;
... ... @@ -70,14 +71,18 @@ public class EdgeController extends BaseController {
70 71 return edgesEnabled;
71 72 }
72 73
73   - @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  74 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
74 75 @RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET)
75 76 @ResponseBody
76 77 public Edge getEdgeById(@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
77 78 checkParameter(EDGE_ID, strEdgeId);
78 79 try {
79 80 EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
80   - return checkEdgeId(edgeId, Operation.READ);
  81 + Edge edge = checkEdgeId(edgeId, Operation.READ);
  82 + if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) {
  83 + cleanUpSensitiveData(edge);
  84 + }
  85 + return edge;
81 86 } catch (Exception e) {
82 87 throw handleException(e);
83 88 }
... ... @@ -340,15 +345,23 @@ public class EdgeController extends BaseController {
340 345 @RequestParam(required = false) String textOffset) throws ThingsboardException {
341 346 checkParameter("customerId", strCustomerId);
342 347 try {
343   - TenantId tenantId = getCurrentUser().getTenantId();
  348 + SecurityUser user = getCurrentUser();
  349 + TenantId tenantId = user.getTenantId();
344 350 CustomerId customerId = new CustomerId(toUUID(strCustomerId));
345 351 checkCustomerId(customerId, Operation.READ);
346 352 TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
  353 + TextPageData<Edge> result;
347 354 if (type != null && type.trim().length() > 0) {
348   - return checkNotNull(edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
  355 + result = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink);
349 356 } else {
350   - return checkNotNull(edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink));
  357 + result = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
  358 + }
  359 + if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
  360 + for (Edge edge : result.getData()) {
  361 + cleanUpSensitiveData(edge);
  362 + }
351 363 }
  364 + return checkNotNull(result);
352 365 } catch (Exception e) {
353 366 throw handleException(e);
354 367 }
... ... @@ -368,13 +381,19 @@ public class EdgeController extends BaseController {
368 381 for (String strEdgeId : strEdgeIds) {
369 382 edgeIds.add(new EdgeId(toUUID(strEdgeId)));
370 383 }
371   - ListenableFuture<List<Edge>> edges;
  384 + ListenableFuture<List<Edge>> edgesFuture;
372 385 if (customerId == null || customerId.isNullUid()) {
373   - edges = edgeService.findEdgesByTenantIdAndIdsAsync(tenantId, edgeIds);
  386 + edgesFuture = edgeService.findEdgesByTenantIdAndIdsAsync(tenantId, edgeIds);
374 387 } else {
375   - edges = edgeService.findEdgesByTenantIdCustomerIdAndIdsAsync(tenantId, customerId, edgeIds);
  388 + edgesFuture = edgeService.findEdgesByTenantIdCustomerIdAndIdsAsync(tenantId, customerId, edgeIds);
  389 + }
  390 + List<Edge> edges = edgesFuture.get();
  391 + if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
  392 + for (Edge edge : edges) {
  393 + cleanUpSensitiveData(edge);
  394 + }
376 395 }
377   - return checkNotNull(edges.get());
  396 + return checkNotNull(edges);
378 397 } catch (Exception e) {
379 398 throw handleException(e);
380 399 }
... ... @@ -400,6 +419,11 @@ public class EdgeController extends BaseController {
400 419 return false;
401 420 }
402 421 }).collect(Collectors.toList());
  422 + if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
  423 + for (Edge edge : edges) {
  424 + cleanUpSensitiveData(edge);
  425 + }
  426 + }
403 427 return edges;
404 428 } catch (Exception e) {
405 429 throw handleException(e);
... ... @@ -476,4 +500,12 @@ public class EdgeController extends BaseController {
476 500 throw handleException(e);
477 501 }
478 502 }
  503 +
  504 + private void cleanUpSensitiveData(Edge edge) {
  505 + edge.setEdgeLicenseKey(null);
  506 + edge.setRoutingKey(null);
  507 + edge.setSecret(null);
  508 + edge.setCloudEndpoint(null);
  509 + edge.setRootRuleChainId(null);
  510 + }
479 511 }
... ...
... ... @@ -45,7 +45,7 @@ public class EdgeEventController extends BaseController {
45 45
46 46 public static final String EDGE_ID = "edgeId";
47 47
48   - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
  48 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
49 49 @RequestMapping(value = "/edge/{edgeId}/events", method = RequestMethod.GET)
50 50 @ResponseBody
51 51 public TimePageData<EdgeEvent> getEdgeEvents(
... ...