...
|
...
|
@@ -47,13 +47,20 @@ import java.util.stream.Collectors; |
47
|
47
|
@RequestMapping("/api")
|
48
|
48
|
public class AuditLogController extends BaseController {
|
49
|
49
|
|
50
|
|
- protected final String AUDIT_LOG_ACTION_TYPES_DESCRIPTION = "A String value representing action types parameter. The value is not required, but it can be any value of ActionType class. " +
|
51
|
|
- "For example, 'ADDED,DELETED,UPDATED,LOGIN,LOGOUT'.";
|
52
|
|
- protected final String SORT_AUDIT_LOG_PROPERTY_DESCRIPTION = "Property of logs to sort by";
|
53
|
|
- protected final String SORT_AUDIT_LOG_PROPERTY_ALLOWABLE_VALUES = "createdTime, entityName, entityType, user, type, status";
|
|
50
|
+ private static final String AUDIT_LOG_QUERY_START_TIME_DESCRIPTION = "The start timestamp in milliseconds of the search time range over the AuditLog class field: 'createdTime'.";
|
|
51
|
+ private static final String AUDIT_LOG_QUERY_END_TIME_DESCRIPTION = "The end timestamp in milliseconds of the search time range over the AuditLog class field: 'createdTime'.";
|
|
52
|
+ private static final String AUDIT_LOG_QUERY_ACTION_TYPES_DESCRIPTION = "A String value representing comma-separated list of action types. " +
|
|
53
|
+ "This parameter is optional, but it can be used to filter results to fetch only audit logs of specific action types. " +
|
|
54
|
+ "For example, 'LOGIN', 'LOGOUT'. See the 'Model' tab of the Response Class for more details.";
|
|
55
|
+ private static final String AUDIT_LOG_SORT_PROPERTY_DESCRIPTION = "Property of audit log to sort by. " +
|
|
56
|
+ "See the 'Model' tab of the Response Class for more details. " +
|
|
57
|
+ "Note: entityType sort property is not defined in the AuditLog class, however, it can be used to sort audit logs by types of entities that were logged.";
|
|
58
|
+
|
54
|
59
|
|
55
|
60
|
@ApiOperation(value = "Get audit logs by customer id (getAuditLogsByCustomerId)",
|
56
|
|
- notes = "Returns a page of audit logs by selected customer. " + PAGE_DATA_PARAMETERS,
|
|
61
|
+ notes = "Returns a page of audit logs related to the targeted customer entities(devices, assets, etc.), " +
|
|
62
|
+ "and users actions(login, logout, etc.) that belong to this customer. " +
|
|
63
|
+ PAGE_DATA_PARAMETERS + ADMINISTRATOR_AUTHORITY_ONLY,
|
57
|
64
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
58
|
65
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
59
|
66
|
@RequestMapping(value = "/audit/logs/customer/{customerId}", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
...
|
...
|
@@ -65,17 +72,17 @@ public class AuditLogController extends BaseController { |
65
|
72
|
@RequestParam int pageSize,
|
66
|
73
|
@ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
67
|
74
|
@RequestParam int page,
|
68
|
|
- @ApiParam(value = "The case insensitive 'startsWith' filter based on the customer name.")
|
|
75
|
+ @ApiParam(value = AUDIT_LOG_TEXT_SEARCH_DESCRIPTION)
|
69
|
76
|
@RequestParam(required = false) String textSearch,
|
70
|
|
- @ApiParam(value = SORT_AUDIT_LOG_PROPERTY_DESCRIPTION, allowableValues = SORT_AUDIT_LOG_PROPERTY_ALLOWABLE_VALUES)
|
|
77
|
+ @ApiParam(value = AUDIT_LOG_SORT_PROPERTY_DESCRIPTION, allowableValues = AUDIT_LOG_SORT_PROPERTY_ALLOWABLE_VALUES)
|
71
|
78
|
@RequestParam(required = false) String sortProperty,
|
72
|
79
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
73
|
80
|
@RequestParam(required = false) String sortOrder,
|
74
|
|
- @ApiParam(value = "A long value representing the start timestamp(milliseconds) of search time range.")
|
|
81
|
+ @ApiParam(value = AUDIT_LOG_QUERY_START_TIME_DESCRIPTION)
|
75
|
82
|
@RequestParam(required = false) Long startTime,
|
76
|
|
- @ApiParam(value = "A long value representing the end timestamp(milliseconds) of search time range.")
|
|
83
|
+ @ApiParam(value = AUDIT_LOG_QUERY_END_TIME_DESCRIPTION)
|
77
|
84
|
@RequestParam(required = false) Long endTime,
|
78
|
|
- @ApiParam(value = AUDIT_LOG_ACTION_TYPES_DESCRIPTION)
|
|
85
|
+ @ApiParam(value = AUDIT_LOG_QUERY_ACTION_TYPES_DESCRIPTION)
|
79
|
86
|
@RequestParam(name = "actionTypes", required = false) String actionTypesStr) throws ThingsboardException {
|
80
|
87
|
try {
|
81
|
88
|
checkParameter("CustomerId", strCustomerId);
|
...
|
...
|
@@ -89,7 +96,9 @@ public class AuditLogController extends BaseController { |
89
|
96
|
}
|
90
|
97
|
|
91
|
98
|
@ApiOperation(value = "Get audit logs by user id (getAuditLogsByUserId)",
|
92
|
|
- notes = "Returns a page of audit logs by selected user. " + PAGE_DATA_PARAMETERS,
|
|
99
|
+ notes = "Returns a page of audit logs related to the actions of targeted user. " +
|
|
100
|
+ "For example, RPC call to a particular device, or alarm acknowledgment for a specific device, etc. " +
|
|
101
|
+ PAGE_DATA_PARAMETERS + ADMINISTRATOR_AUTHORITY_ONLY,
|
93
|
102
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
94
|
103
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
95
|
104
|
@RequestMapping(value = "/audit/logs/user/{userId}", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
...
|
...
|
@@ -101,17 +110,17 @@ public class AuditLogController extends BaseController { |
101
|
110
|
@RequestParam int pageSize,
|
102
|
111
|
@ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
103
|
112
|
@RequestParam int page,
|
104
|
|
- @ApiParam(value = "The case insensitive 'startsWith' filter based on the user name.")
|
|
113
|
+ @ApiParam(value = AUDIT_LOG_TEXT_SEARCH_DESCRIPTION)
|
105
|
114
|
@RequestParam(required = false) String textSearch,
|
106
|
|
- @ApiParam(value = SORT_AUDIT_LOG_PROPERTY_DESCRIPTION, allowableValues = SORT_AUDIT_LOG_PROPERTY_ALLOWABLE_VALUES)
|
|
115
|
+ @ApiParam(value = AUDIT_LOG_SORT_PROPERTY_DESCRIPTION, allowableValues = AUDIT_LOG_SORT_PROPERTY_ALLOWABLE_VALUES)
|
107
|
116
|
@RequestParam(required = false) String sortProperty,
|
108
|
117
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
109
|
118
|
@RequestParam(required = false) String sortOrder,
|
110
|
|
- @ApiParam(value = "A long value representing the start timestamp(milliseconds) of search time range.")
|
|
119
|
+ @ApiParam(value = AUDIT_LOG_QUERY_START_TIME_DESCRIPTION)
|
111
|
120
|
@RequestParam(required = false) Long startTime,
|
112
|
|
- @ApiParam(value = "A long value representing the end timestamp(milliseconds) of search time range.")
|
|
121
|
+ @ApiParam(value = AUDIT_LOG_QUERY_END_TIME_DESCRIPTION)
|
113
|
122
|
@RequestParam(required = false) Long endTime,
|
114
|
|
- @ApiParam(value = AUDIT_LOG_ACTION_TYPES_DESCRIPTION)
|
|
123
|
+ @ApiParam(value = AUDIT_LOG_QUERY_ACTION_TYPES_DESCRIPTION)
|
115
|
124
|
@RequestParam(name = "actionTypes", required = false) String actionTypesStr) throws ThingsboardException {
|
116
|
125
|
try {
|
117
|
126
|
checkParameter("UserId", strUserId);
|
...
|
...
|
@@ -125,31 +134,34 @@ public class AuditLogController extends BaseController { |
125
|
134
|
}
|
126
|
135
|
|
127
|
136
|
@ApiOperation(value = "Get audit logs by entity id (getAuditLogsByEntityId)",
|
128
|
|
- notes = "Returns a page of audit logs by selected entity. " + PAGE_DATA_PARAMETERS,
|
|
137
|
+ notes = "Returns a page of audit logs related to the actions on the targeted entity. " +
|
|
138
|
+ "Basically, this API call is used to get the full lifecycle of some specific entity. " +
|
|
139
|
+ "For example to see when a device was created, updated, assigned to some customer, or even deleted from the system. " +
|
|
140
|
+ PAGE_DATA_PARAMETERS + ADMINISTRATOR_AUTHORITY_ONLY,
|
129
|
141
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
130
|
142
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
131
|
143
|
@RequestMapping(value = "/audit/logs/entity/{entityType}/{entityId}", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
132
|
144
|
@ResponseBody
|
133
|
145
|
public PageData<AuditLog> getAuditLogsByEntityId(
|
134
|
|
- @ApiParam(value = ENTITY_TYPE_DESCRIPTION)
|
|
146
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION)
|
135
|
147
|
@PathVariable("entityType") String strEntityType,
|
136
|
|
- @ApiParam(value = ENTITY_ID_DESCRIPTION)
|
|
148
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION)
|
137
|
149
|
@PathVariable("entityId") String strEntityId,
|
138
|
150
|
@ApiParam(value = PAGE_SIZE_DESCRIPTION)
|
139
|
151
|
@RequestParam int pageSize,
|
140
|
152
|
@ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
141
|
153
|
@RequestParam int page,
|
142
|
|
- @ApiParam(value = "The case insensitive 'startsWith' filter based on the entity name.")
|
|
154
|
+ @ApiParam(value = AUDIT_LOG_TEXT_SEARCH_DESCRIPTION)
|
143
|
155
|
@RequestParam(required = false) String textSearch,
|
144
|
|
- @ApiParam(value = SORT_AUDIT_LOG_PROPERTY_DESCRIPTION, allowableValues = SORT_AUDIT_LOG_PROPERTY_ALLOWABLE_VALUES)
|
|
156
|
+ @ApiParam(value = AUDIT_LOG_SORT_PROPERTY_DESCRIPTION, allowableValues = AUDIT_LOG_SORT_PROPERTY_ALLOWABLE_VALUES)
|
145
|
157
|
@RequestParam(required = false) String sortProperty,
|
146
|
158
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
147
|
159
|
@RequestParam(required = false) String sortOrder,
|
148
|
|
- @ApiParam(value = "A long value representing the start timestamp(milliseconds) of search time range.")
|
|
160
|
+ @ApiParam(value = AUDIT_LOG_QUERY_START_TIME_DESCRIPTION)
|
149
|
161
|
@RequestParam(required = false) Long startTime,
|
150
|
|
- @ApiParam(value = "A long value representing the end timestamp(milliseconds) of search time range.")
|
|
162
|
+ @ApiParam(value = AUDIT_LOG_QUERY_END_TIME_DESCRIPTION)
|
151
|
163
|
@RequestParam(required = false) Long endTime,
|
152
|
|
- @ApiParam(value = AUDIT_LOG_ACTION_TYPES_DESCRIPTION)
|
|
164
|
+ @ApiParam(value = AUDIT_LOG_QUERY_ACTION_TYPES_DESCRIPTION)
|
153
|
165
|
@RequestParam(name = "actionTypes", required = false) String actionTypesStr) throws ThingsboardException {
|
154
|
166
|
try {
|
155
|
167
|
checkParameter("EntityId", strEntityId);
|
...
|
...
|
@@ -164,7 +176,9 @@ public class AuditLogController extends BaseController { |
164
|
176
|
}
|
165
|
177
|
|
166
|
178
|
@ApiOperation(value = "Get all audit logs (getAuditLogs)",
|
167
|
|
- notes = "Returns a page of all audit logs. " + PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
179
|
+ notes = "Returns a page of audit logs related to all entities in the scope of the current user's Tenant. " +
|
|
180
|
+ PAGE_DATA_PARAMETERS + ADMINISTRATOR_AUTHORITY_ONLY,
|
|
181
|
+ produces = MediaType.APPLICATION_JSON_VALUE)
|
168
|
182
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
169
|
183
|
@RequestMapping(value = "/audit/logs", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
170
|
184
|
@ResponseBody
|
...
|
...
|
@@ -173,17 +187,17 @@ public class AuditLogController extends BaseController { |
173
|
187
|
@RequestParam int pageSize,
|
174
|
188
|
@ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
175
|
189
|
@RequestParam int page,
|
176
|
|
- @ApiParam(value = "The case insensitive 'startsWith' filter based on any name like 'Device', 'Asset', 'Customer' etc.")
|
|
190
|
+ @ApiParam(value = AUDIT_LOG_TEXT_SEARCH_DESCRIPTION)
|
177
|
191
|
@RequestParam(required = false) String textSearch,
|
178
|
|
- @ApiParam(value = SORT_AUDIT_LOG_PROPERTY_DESCRIPTION, allowableValues = SORT_AUDIT_LOG_PROPERTY_ALLOWABLE_VALUES)
|
|
192
|
+ @ApiParam(value = AUDIT_LOG_SORT_PROPERTY_DESCRIPTION, allowableValues = AUDIT_LOG_SORT_PROPERTY_ALLOWABLE_VALUES)
|
179
|
193
|
@RequestParam(required = false) String sortProperty,
|
180
|
194
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
181
|
195
|
@RequestParam(required = false) String sortOrder,
|
182
|
|
- @ApiParam(value = "A long value representing the start timestamp(milliseconds) of search time range.")
|
|
196
|
+ @ApiParam(value = AUDIT_LOG_QUERY_START_TIME_DESCRIPTION)
|
183
|
197
|
@RequestParam(required = false) Long startTime,
|
184
|
|
- @ApiParam(value = "A long value representing the end timestamp(milliseconds) of search time range.")
|
|
198
|
+ @ApiParam(value = AUDIT_LOG_QUERY_END_TIME_DESCRIPTION)
|
185
|
199
|
@RequestParam(required = false) Long endTime,
|
186
|
|
- @ApiParam(value = AUDIT_LOG_ACTION_TYPES_DESCRIPTION)
|
|
200
|
+ @ApiParam(value = AUDIT_LOG_QUERY_ACTION_TYPES_DESCRIPTION)
|
187
|
201
|
@RequestParam(name = "actionTypes", required = false) String actionTypesStr) throws ThingsboardException {
|
188
|
202
|
try {
|
189
|
203
|
TenantId tenantId = getCurrentUser().getTenantId();
|
...
|
...
|
|