diff --git a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallConfiguration.java b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallConfiguration.java new file mode 100644 index 0000000000..d0132f8461 --- /dev/null +++ b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallConfiguration.java @@ -0,0 +1,34 @@ +/** + * Copyright © 2016-2017 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.thingsboard.server.install; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.thingsboard.server.dao.audit.AuditLogLevelFilter; + +import java.util.HashMap; + +@Configuration +@Profile("install") +public class ThingsboardInstallConfiguration { + + @Bean + public AuditLogLevelFilter emptyAuditLogLevelFilter() { + return new AuditLogLevelFilter(new HashMap<>()); + } +} diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 7ea68c73d3..f7a3a80738 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -310,10 +310,10 @@ audit_log: # Allowed values: OFF (disable), W (log write operations), RW (log read and write operations) logging_level: mask: - "device": "W" - "asset": "W" - "dashboard": "W" - "customer": "W" - "user": "W" - "rule": "W" - "plugin": "W" + "device": "${AUDIT_LOG_MASK_DEVICE:W}" + "asset": "${AUDIT_LOG_MASK_ASSET:W}" + "dashboard": "${AUDIT_LOG_MASK_DASHBOARD:W}" + "customer": "${AUDIT_LOG_MASK_CUSTOMER:W}" + "user": "${AUDIT_LOG_MASK_USER:W}" + "rule": "${AUDIT_LOG_MASK_RULE:W}" + "plugin": "${AUDIT_LOG_MASK_PLUGIN:W}" diff --git a/dao/src/main/java/org/thingsboard/server/dao/audit/CassandraAuditLogDao.java b/dao/src/main/java/org/thingsboard/server/dao/audit/CassandraAuditLogDao.java index 085d798ea5..fa32b5de0e 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/audit/CassandraAuditLogDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/audit/CassandraAuditLogDao.java @@ -48,10 +48,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; @@ -135,12 +132,7 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao null); } @@ -149,7 +141,7 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao null); } @@ -158,7 +150,7 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao null); } @@ -167,12 +159,12 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao null); } - private BoundStatement setSaveStmtVariables(BoundStatement stmt, AuditLog auditLog) { - return stmt.setUUID(0, auditLog.getId().getId()) + private BoundStatement setSaveStmtVariables(BoundStatement stmt, AuditLog auditLog, long partition) { + stmt.setUUID(0, auditLog.getId().getId()) .setUUID(1, auditLog.getTenantId().getId()) .setUUID(2, auditLog.getCustomerId().getId()) .setUUID(3, auditLog.getEntityId().getId()) @@ -184,6 +176,10 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao -1) { + stmt.setLong(12, partition); + } + return stmt; } @Override @@ -198,42 +194,57 @@ public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao null); } + private PreparedStatement getSaveByTenantStmt() { + if (saveByTenantStmt == null) { + saveByTenantStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_TENANT_ID_CF, true); + } + return saveByTenantStmt; + } + private PreparedStatement getSaveByTenantIdAndEntityIdStmt() { if (saveByTenantIdAndEntityIdStmt == null) { - saveByTenantIdAndEntityIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_ENTITY_ID_CF); + saveByTenantIdAndEntityIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_ENTITY_ID_CF, false); } return saveByTenantIdAndEntityIdStmt; } private PreparedStatement getSaveByTenantIdAndCustomerIdStmt() { if (saveByTenantIdAndCustomerIdStmt == null) { - saveByTenantIdAndCustomerIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_CUSTOMER_ID_CF); + saveByTenantIdAndCustomerIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_CUSTOMER_ID_CF, false); } return saveByTenantIdAndCustomerIdStmt; } private PreparedStatement getSaveByTenantIdAndUserIdStmt() { if (saveByTenantIdAndUserIdStmt == null) { - saveByTenantIdAndUserIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_USER_ID_CF); + saveByTenantIdAndUserIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_USER_ID_CF, false); } return saveByTenantIdAndUserIdStmt; } - private PreparedStatement getSaveByTenantIdAndCFName(String cfName) { - return getSession().prepare(INSERT_INTO + cfName + - "(" + ModelConstants.AUDIT_LOG_ID_PROPERTY + - "," + ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY + - "," + ModelConstants.AUDIT_LOG_CUSTOMER_ID_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ENTITY_ID_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ENTITY_TYPE_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ENTITY_NAME_PROPERTY + - "," + ModelConstants.AUDIT_LOG_USER_ID_PROPERTY + - "," + ModelConstants.AUDIT_LOG_USER_NAME_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ACTION_TYPE_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ACTION_STATUS_PROPERTY + - "," + ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY + ")" + - " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + private PreparedStatement getSaveByTenantIdAndCFName(String cfName, boolean hasPartition) { + List columnsList = new ArrayList(); + columnsList.add(ModelConstants.AUDIT_LOG_ID_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_CUSTOMER_ID_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_ID_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_TYPE_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_NAME_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_USER_ID_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_USER_NAME_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ACTION_TYPE_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ACTION_STATUS_PROPERTY); + columnsList.add(ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY); + if (hasPartition) { + columnsList.add(ModelConstants.AUDIT_LOG_PARTITION_PROPERTY); + } + StringJoiner values = new StringJoiner(","); + for (int i=0;i { @Override public AuditLog toData() { AuditLog auditLog = new AuditLog(new AuditLogId(id)); + auditLog.setCreatedTime(UUIDs.unixTimestamp(id)); if (tenantId != null) { auditLog.setTenantId(new TenantId(tenantId)); } - if (entityId != null & entityType != null) { + if (entityId != null && entityType != null) { auditLog.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); } if (customerId != null) {