1614 changed files with 9873 additions and 3109 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,112 @@ |
|||||
|
-- |
||||
|
-- Copyright © 2016-2018 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. |
||||
|
-- |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_entity_id ( |
||||
|
tenant_id timeuuid, |
||||
|
id timeuuid, |
||||
|
customer_id timeuuid, |
||||
|
entity_id timeuuid, |
||||
|
entity_type text, |
||||
|
entity_name text, |
||||
|
user_id timeuuid, |
||||
|
user_name text, |
||||
|
action_type text, |
||||
|
action_data text, |
||||
|
action_status text, |
||||
|
action_failure_details text, |
||||
|
PRIMARY KEY ((tenant_id, entity_id, entity_type), id) |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_customer_id ( |
||||
|
tenant_id timeuuid, |
||||
|
id timeuuid, |
||||
|
customer_id timeuuid, |
||||
|
entity_id timeuuid, |
||||
|
entity_type text, |
||||
|
entity_name text, |
||||
|
user_id timeuuid, |
||||
|
user_name text, |
||||
|
action_type text, |
||||
|
action_data text, |
||||
|
action_status text, |
||||
|
action_failure_details text, |
||||
|
PRIMARY KEY ((tenant_id, customer_id), id) |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_user_id ( |
||||
|
tenant_id timeuuid, |
||||
|
id timeuuid, |
||||
|
customer_id timeuuid, |
||||
|
entity_id timeuuid, |
||||
|
entity_type text, |
||||
|
entity_name text, |
||||
|
user_id timeuuid, |
||||
|
user_name text, |
||||
|
action_type text, |
||||
|
action_data text, |
||||
|
action_status text, |
||||
|
action_failure_details text, |
||||
|
PRIMARY KEY ((tenant_id, user_id), id) |
||||
|
); |
||||
|
|
||||
|
|
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id ( |
||||
|
tenant_id timeuuid, |
||||
|
id timeuuid, |
||||
|
partition bigint, |
||||
|
customer_id timeuuid, |
||||
|
entity_id timeuuid, |
||||
|
entity_type text, |
||||
|
entity_name text, |
||||
|
user_id timeuuid, |
||||
|
user_name text, |
||||
|
action_type text, |
||||
|
action_data text, |
||||
|
action_status text, |
||||
|
action_failure_details text, |
||||
|
PRIMARY KEY ((tenant_id, partition), id) |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id_partitions ( |
||||
|
tenant_id timeuuid, |
||||
|
partition bigint, |
||||
|
PRIMARY KEY (( tenant_id ), partition) |
||||
|
) WITH CLUSTERING ORDER BY ( partition ASC ) |
||||
|
AND compaction = { 'class' : 'LeveledCompactionStrategy' }; |
||||
|
|
||||
|
DROP MATERIALIZED VIEW IF EXISTS thingsboard.dashboard_by_tenant_and_search_text; |
||||
|
DROP MATERIALIZED VIEW IF EXISTS thingsboard.dashboard_by_customer_and_search_text; |
||||
|
|
||||
|
DROP TABLE IF EXISTS thingsboard.dashboard; |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS thingsboard.dashboard ( |
||||
|
id timeuuid, |
||||
|
tenant_id timeuuid, |
||||
|
title text, |
||||
|
search_text text, |
||||
|
assigned_customers text, |
||||
|
configuration text, |
||||
|
PRIMARY KEY (id, tenant_id) |
||||
|
); |
||||
|
|
||||
|
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.dashboard_by_tenant_and_search_text AS |
||||
|
SELECT * |
||||
|
from thingsboard.dashboard |
||||
|
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
||||
|
PRIMARY KEY ( tenant_id, search_text, id ) |
||||
|
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
||||
|
|
||||
@ -0,0 +1,41 @@ |
|||||
|
-- |
||||
|
-- Copyright © 2016-2018 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. |
||||
|
-- |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS audit_log ( |
||||
|
id varchar(31) NOT NULL CONSTRAINT audit_log_pkey PRIMARY KEY, |
||||
|
tenant_id varchar(31), |
||||
|
customer_id varchar(31), |
||||
|
entity_id varchar(31), |
||||
|
entity_type varchar(255), |
||||
|
entity_name varchar(255), |
||||
|
user_id varchar(31), |
||||
|
user_name varchar(255), |
||||
|
action_type varchar(255), |
||||
|
action_data varchar(1000000), |
||||
|
action_status varchar(255), |
||||
|
action_failure_details varchar(1000000) |
||||
|
); |
||||
|
|
||||
|
DROP TABLE IF EXISTS dashboard; |
||||
|
|
||||
|
CREATE TABLE IF NOT EXISTS dashboard ( |
||||
|
id varchar(31) NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, |
||||
|
configuration varchar(10000000), |
||||
|
assigned_customers varchar(1000000), |
||||
|
search_text varchar(255), |
||||
|
tenant_id varchar(31), |
||||
|
title varchar(255) |
||||
|
); |
||||
@ -0,0 +1,43 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 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.config; |
||||
|
|
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.thingsboard.server.common.data.EntityType; |
||||
|
import org.thingsboard.server.common.data.audit.ActionType; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Configuration |
||||
|
@ConfigurationProperties(prefix = "audit_log.logging_level") |
||||
|
public class AuditLogLevelProperties { |
||||
|
|
||||
|
private Map<String, String> mask = new HashMap<>(); |
||||
|
|
||||
|
public AuditLogLevelProperties() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public void setMask(Map<String, String> mask) { |
||||
|
this.mask = mask; |
||||
|
} |
||||
|
|
||||
|
public Map<String, String> getMask() { |
||||
|
return this.mask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,114 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 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.controller; |
||||
|
|
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import org.thingsboard.server.common.data.audit.AuditLog; |
||||
|
import org.thingsboard.server.common.data.id.CustomerId; |
||||
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.id.UserId; |
||||
|
import org.thingsboard.server.common.data.page.TimePageData; |
||||
|
import org.thingsboard.server.common.data.page.TimePageLink; |
||||
|
import org.thingsboard.server.exception.ThingsboardException; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/api") |
||||
|
public class AuditLogController extends BaseController { |
||||
|
|
||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')") |
||||
|
@RequestMapping(value = "/audit/logs/customer/{customerId}", params = {"limit"}, method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public TimePageData<AuditLog> getAuditLogsByCustomerId( |
||||
|
@PathVariable("customerId") String strCustomerId, |
||||
|
@RequestParam int limit, |
||||
|
@RequestParam(required = false) Long startTime, |
||||
|
@RequestParam(required = false) Long endTime, |
||||
|
@RequestParam(required = false, defaultValue = "false") boolean ascOrder, |
||||
|
@RequestParam(required = false) String offset) throws ThingsboardException { |
||||
|
try { |
||||
|
checkParameter("CustomerId", strCustomerId); |
||||
|
TenantId tenantId = getCurrentUser().getTenantId(); |
||||
|
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset); |
||||
|
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndCustomerId(tenantId, new CustomerId(UUID.fromString(strCustomerId)), pageLink)); |
||||
|
} catch (Exception e) { |
||||
|
throw handleException(e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')") |
||||
|
@RequestMapping(value = "/audit/logs/user/{userId}", params = {"limit"}, method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public TimePageData<AuditLog> getAuditLogsByUserId( |
||||
|
@PathVariable("userId") String strUserId, |
||||
|
@RequestParam int limit, |
||||
|
@RequestParam(required = false) Long startTime, |
||||
|
@RequestParam(required = false) Long endTime, |
||||
|
@RequestParam(required = false, defaultValue = "false") boolean ascOrder, |
||||
|
@RequestParam(required = false) String offset) throws ThingsboardException { |
||||
|
try { |
||||
|
checkParameter("UserId", strUserId); |
||||
|
TenantId tenantId = getCurrentUser().getTenantId(); |
||||
|
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset); |
||||
|
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndUserId(tenantId, new UserId(UUID.fromString(strUserId)), pageLink)); |
||||
|
} catch (Exception e) { |
||||
|
throw handleException(e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')") |
||||
|
@RequestMapping(value = "/audit/logs/entity/{entityType}/{entityId}", params = {"limit"}, method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public TimePageData<AuditLog> getAuditLogsByEntityId( |
||||
|
@PathVariable("entityType") String strEntityType, |
||||
|
@PathVariable("entityId") String strEntityId, |
||||
|
@RequestParam int limit, |
||||
|
@RequestParam(required = false) Long startTime, |
||||
|
@RequestParam(required = false) Long endTime, |
||||
|
@RequestParam(required = false, defaultValue = "false") boolean ascOrder, |
||||
|
@RequestParam(required = false) String offset) throws ThingsboardException { |
||||
|
try { |
||||
|
checkParameter("EntityId", strEntityId); |
||||
|
checkParameter("EntityType", strEntityType); |
||||
|
TenantId tenantId = getCurrentUser().getTenantId(); |
||||
|
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset); |
||||
|
return checkNotNull(auditLogService.findAuditLogsByTenantIdAndEntityId(tenantId, EntityIdFactory.getByTypeAndId(strEntityType, strEntityId), pageLink)); |
||||
|
} catch (Exception e) { |
||||
|
throw handleException(e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')") |
||||
|
@RequestMapping(value = "/audit/logs", params = {"limit"}, method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public TimePageData<AuditLog> getAuditLogs( |
||||
|
@RequestParam int limit, |
||||
|
@RequestParam(required = false) Long startTime, |
||||
|
@RequestParam(required = false) Long endTime, |
||||
|
@RequestParam(required = false, defaultValue = "false") boolean ascOrder, |
||||
|
@RequestParam(required = false) String offset) throws ThingsboardException { |
||||
|
try { |
||||
|
TenantId tenantId = getCurrentUser().getTenantId(); |
||||
|
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset); |
||||
|
return checkNotNull(auditLogService.findAuditLogsByTenantId(tenantId, pageLink)); |
||||
|
} catch (Exception e) { |
||||
|
throw handleException(e); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue