|
|
|
@ -17,7 +17,6 @@ package org.thingsboard.server.dao.audit; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
@ -50,6 +49,7 @@ import org.thingsboard.server.dao.device.provision.ProvisionRequest; |
|
|
|
import org.thingsboard.server.dao.entity.EntityService; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
|
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|
|
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.StringWriter; |
|
|
|
@ -65,8 +65,6 @@ import static org.thingsboard.server.dao.service.Validator.validateId; |
|
|
|
@ConditionalOnProperty(prefix = "audit-log", value = "enabled", havingValue = "true") |
|
|
|
public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
|
|
|
|
private static final ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
|
|
|
|
private static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
|
|
|
private static final int INSERTS_PER_ENTRY = 3; |
|
|
|
|
|
|
|
@ -159,7 +157,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
private <E extends HasName, I extends EntityId> JsonNode constructActionData(I entityId, E entity, |
|
|
|
ActionType actionType, |
|
|
|
Object... additionalInfo) { |
|
|
|
ObjectNode actionData = objectMapper.createObjectNode(); |
|
|
|
ObjectNode actionData = JacksonUtil.newObjectNode(); |
|
|
|
switch (actionType) { |
|
|
|
case ADDED: |
|
|
|
case UPDATED: |
|
|
|
@ -168,7 +166,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
case RELATIONS_DELETED: |
|
|
|
case ASSIGNED_TO_TENANT: |
|
|
|
if (entity != null) { |
|
|
|
ObjectNode entityNode = objectMapper.valueToTree(entity); |
|
|
|
ObjectNode entityNode = (ObjectNode) JacksonUtil.valueToTree(entity); |
|
|
|
if (entityId.getEntityType() == EntityType.DASHBOARD) { |
|
|
|
entityNode.put("configuration", ""); |
|
|
|
} |
|
|
|
@ -177,7 +175,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
if (entityId.getEntityType() == EntityType.RULE_CHAIN) { |
|
|
|
RuleChainMetaData ruleChainMetaData = extractParameter(RuleChainMetaData.class, additionalInfo); |
|
|
|
if (ruleChainMetaData != null) { |
|
|
|
ObjectNode ruleChainMetaDataNode = objectMapper.valueToTree(ruleChainMetaData); |
|
|
|
ObjectNode ruleChainMetaDataNode = (ObjectNode) JacksonUtil.valueToTree(ruleChainMetaData); |
|
|
|
actionData.set("metadata", ruleChainMetaDataNode); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -194,7 +192,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
String scope = extractParameter(String.class, 0, additionalInfo); |
|
|
|
List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); |
|
|
|
actionData.put("scope", scope); |
|
|
|
ObjectNode attrsNode = objectMapper.createObjectNode(); |
|
|
|
ObjectNode attrsNode = JacksonUtil.newObjectNode(); |
|
|
|
if (attributes != null) { |
|
|
|
for (AttributeKvEntry attr : attributes) { |
|
|
|
attrsNode.put(attr.getKey(), attr.getValueAsString()); |
|
|
|
@ -225,7 +223,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
case CREDENTIALS_UPDATED: |
|
|
|
actionData.put("entityId", entityId.toString()); |
|
|
|
DeviceCredentials deviceCredentials = extractParameter(DeviceCredentials.class, additionalInfo); |
|
|
|
actionData.set("credentials", objectMapper.valueToTree(deviceCredentials)); |
|
|
|
actionData.set("credentials", JacksonUtil.valueToTree(deviceCredentials)); |
|
|
|
break; |
|
|
|
case ASSIGNED_TO_CUSTOMER: |
|
|
|
strEntityId = extractParameter(String.class, 0, additionalInfo); |
|
|
|
@ -246,7 +244,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
|
|
|
case RELATION_ADD_OR_UPDATE: |
|
|
|
case RELATION_DELETED: |
|
|
|
EntityRelation relation = extractParameter(EntityRelation.class, 0, additionalInfo); |
|
|
|
actionData.set("relation", objectMapper.valueToTree(relation)); |
|
|
|
actionData.set("relation", JacksonUtil.valueToTree(relation)); |
|
|
|
break; |
|
|
|
case LOGIN: |
|
|
|
case LOGOUT: |
|
|
|
|