diff --git a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java index 3ae44db1b0..6d4a582abf 100644 --- a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java @@ -31,7 +31,8 @@ import static org.thingsboard.server.common.data.query.EntityKeyType.TIME_SERIES @DaoSqlTest @TestPropertySource(properties = { "sql.attributes.value_no_xss_validation=true", - "sql.ts.value_no_xss_validation=true" + "sql.ts.value_no_xss_validation=true", + "audit-log.logging-level.mask.device=RW" }) public class TelemetryControllerTest extends AbstractControllerTest { @@ -291,6 +292,19 @@ public class TelemetryControllerTest extends AbstractControllerTest { Assert.assertTrue(tsDataAfterDeletion.get("key3").get(0).get("value").isNull()); } + @Test + public void testGetAttributesWithoutScopeBySysAdmin() throws Exception { + loginSysAdmin(); + doGetAsync("/api/plugins/telemetry/TENANT/" + tenantId + "/values/attributes").andExpect(status().isOk()); + } + + @Test + public void testGetAttributesWithoutScopeWhenReadAuditEnabled() throws Exception { + loginTenantAdmin(); + Device device = createDevice(); + doGetAsync("/api/plugins/telemetry/DEVICE/" + device.getId() + "/values/attributes").andExpect(status().isOk()); + } + private Device createDevice() throws Exception { String testToken = "TEST_TOKEN"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java index b6824cb21b..5e2b3d72c2 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/audit/AuditLogServiceImpl.java @@ -107,7 +107,7 @@ public class AuditLogServiceImpl implements AuditLogService { public ListenableFuture logEntityAction(TenantId tenantId, CustomerId customerId, UserId userId, String userName, @NotNull I entityId, E entity, ActionType actionType, Exception e, Object... additionalInfo) { - if (canLog(entityId.getEntityType(), actionType) || (tenantId != null && tenantId.isSysTenantId())) { + if (canLog(entityId.getEntityType(), actionType) || (tenantId != null && tenantId.isSysTenantId() && !actionType.isRead())) { JsonNode actionData = constructActionData(entityId, entity, actionType, additionalInfo); ActionStatus actionStatus = ActionStatus.SUCCESS; String failureDetails = ""; @@ -223,7 +223,7 @@ public class AuditLogServiceImpl implements AuditLogService { case ATTRIBUTES_READ: actionData.put("entityId", entityId.toString()); scope = extractParameter(AttributeScope.class, 0, additionalInfo); - actionData.put("scope", scope.name()); + actionData.put("scope", scope != null ? scope.name() : null); @SuppressWarnings("unchecked") List keys = extractParameter(List.class, 1, additionalInfo); ArrayNode attrsArrayNode = actionData.putArray("attributes");