...
|
...
|
@@ -16,6 +16,8 @@ |
16
|
16
|
package org.thingsboard.server.controller;
|
17
|
17
|
|
18
|
18
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
19
|
+import io.swagger.annotations.ApiOperation;
|
|
20
|
+import io.swagger.annotations.ApiParam;
|
19
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
22
|
import org.springframework.security.access.prepost.PreAuthorize;
|
21
|
23
|
import org.springframework.web.bind.annotation.PathVariable;
|
...
|
...
|
@@ -44,6 +46,7 @@ import org.thingsboard.server.service.update.UpdateService; |
44
|
46
|
@RequestMapping("/api/admin")
|
45
|
47
|
public class AdminController extends BaseController {
|
46
|
48
|
|
|
49
|
+ public static final String SYS_ADMIN_AUTHORITY_ONLY = " Available for users with System Administrator ('SYS_ADMIN') authority only.";
|
47
|
50
|
@Autowired
|
48
|
51
|
private MailService mailService;
|
49
|
52
|
|
...
|
...
|
@@ -59,10 +62,14 @@ public class AdminController extends BaseController { |
59
|
62
|
@Autowired
|
60
|
63
|
private UpdateService updateService;
|
61
|
64
|
|
|
65
|
+ @ApiOperation(value = "Get the Administration Settings object using key (getAdminSettings)",
|
|
66
|
+ notes = "Get the Administration Settings object using specified string key. Referencing non-existing key will cause an error." + SYS_ADMIN_AUTHORITY_ONLY)
|
62
|
67
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
63
|
68
|
@RequestMapping(value = "/settings/{key}", method = RequestMethod.GET)
|
64
|
69
|
@ResponseBody
|
65
|
|
- public AdminSettings getAdminSettings(@PathVariable("key") String key) throws ThingsboardException {
|
|
70
|
+ public AdminSettings getAdminSettings(
|
|
71
|
+ @ApiParam(value = "A string value of the key (e.g. 'general' or 'mail').")
|
|
72
|
+ @PathVariable("key") String key) throws ThingsboardException {
|
66
|
73
|
try {
|
67
|
74
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ);
|
68
|
75
|
AdminSettings adminSettings = checkNotNull(adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, key));
|
...
|
...
|
@@ -75,10 +82,17 @@ public class AdminController extends BaseController { |
75
|
82
|
}
|
76
|
83
|
}
|
77
|
84
|
|
|
85
|
+
|
|
86
|
+ @ApiOperation(value = "Get the Administration Settings object using key (getAdminSettings)",
|
|
87
|
+ notes = "Creates or Updates the Administration Settings. Platform generates random Administration Settings Id during settings creation. " +
|
|
88
|
+ "The Administration Settings Id will be present in the response. Specify the Administration Settings Id when you would like to update the Administration Settings. " +
|
|
89
|
+ "Referencing non-existing Administration Settings Id will cause an error." + SYS_ADMIN_AUTHORITY_ONLY)
|
78
|
90
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
79
|
91
|
@RequestMapping(value = "/settings", method = RequestMethod.POST)
|
80
|
92
|
@ResponseBody
|
81
|
|
- public AdminSettings saveAdminSettings(@RequestBody AdminSettings adminSettings) throws ThingsboardException {
|
|
93
|
+ public AdminSettings saveAdminSettings(
|
|
94
|
+ @ApiParam(value = "A JSON value representing the Administration Settings.")
|
|
95
|
+ @RequestBody AdminSettings adminSettings) throws ThingsboardException {
|
82
|
96
|
try {
|
83
|
97
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.WRITE);
|
84
|
98
|
adminSettings = checkNotNull(adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, adminSettings));
|
...
|
...
|
@@ -94,6 +108,8 @@ public class AdminController extends BaseController { |
94
|
108
|
}
|
95
|
109
|
}
|
96
|
110
|
|
|
111
|
+ @ApiOperation(value = "Get the Security Settings object",
|
|
112
|
+ notes = "Get the Security Settings object that contains password policy, etc." + SYS_ADMIN_AUTHORITY_ONLY)
|
97
|
113
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
98
|
114
|
@RequestMapping(value = "/securitySettings", method = RequestMethod.GET)
|
99
|
115
|
@ResponseBody
|
...
|
...
|
@@ -106,10 +122,14 @@ public class AdminController extends BaseController { |
106
|
122
|
}
|
107
|
123
|
}
|
108
|
124
|
|
|
125
|
+ @ApiOperation(value = "Update Security Settings (saveSecuritySettings)",
|
|
126
|
+ notes = "Updates the Security Settings object that contains password policy, etc." + SYS_ADMIN_AUTHORITY_ONLY)
|
109
|
127
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
110
|
128
|
@RequestMapping(value = "/securitySettings", method = RequestMethod.POST)
|
111
|
129
|
@ResponseBody
|
112
|
|
- public SecuritySettings saveSecuritySettings(@RequestBody SecuritySettings securitySettings) throws ThingsboardException {
|
|
130
|
+ public SecuritySettings saveSecuritySettings(
|
|
131
|
+ @ApiParam(value = "A JSON value representing the Security Settings.")
|
|
132
|
+ @RequestBody SecuritySettings securitySettings) throws ThingsboardException {
|
113
|
133
|
try {
|
114
|
134
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.WRITE);
|
115
|
135
|
securitySettings = checkNotNull(systemSecurityService.saveSecuritySettings(TenantId.SYS_TENANT_ID, securitySettings));
|
...
|
...
|
@@ -119,14 +139,19 @@ public class AdminController extends BaseController { |
119
|
139
|
}
|
120
|
140
|
}
|
121
|
141
|
|
|
142
|
+ @ApiOperation(value = "Send test email (sendTestMail)",
|
|
143
|
+ notes = "Attempts to send test email to the System Administrator User using Mail Settings provided as a parameter. " +
|
|
144
|
+ "You may change the 'To' email in the user profile of the System Administrator. " + SYS_ADMIN_AUTHORITY_ONLY)
|
122
|
145
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
123
|
146
|
@RequestMapping(value = "/settings/testMail", method = RequestMethod.POST)
|
124
|
|
- public void sendTestMail(@RequestBody AdminSettings adminSettings) throws ThingsboardException {
|
|
147
|
+ public void sendTestMail(
|
|
148
|
+ @ApiParam(value = "A JSON value representing the Mail Settings.")
|
|
149
|
+ @RequestBody AdminSettings adminSettings) throws ThingsboardException {
|
125
|
150
|
try {
|
126
|
151
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ);
|
127
|
152
|
adminSettings = checkNotNull(adminSettings);
|
128
|
153
|
if (adminSettings.getKey().equals("mail")) {
|
129
|
|
- if(!adminSettings.getJsonValue().has("password")) {
|
|
154
|
+ if (!adminSettings.getJsonValue().has("password")) {
|
130
|
155
|
AdminSettings mailSettings = checkNotNull(adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail"));
|
131
|
156
|
((ObjectNode) adminSettings.getJsonValue()).put("password", mailSettings.getJsonValue().get("password").asText());
|
132
|
157
|
}
|
...
|
...
|
@@ -138,9 +163,14 @@ public class AdminController extends BaseController { |
138
|
163
|
}
|
139
|
164
|
}
|
140
|
165
|
|
|
166
|
+ @ApiOperation(value = "Send test sms (sendTestMail)",
|
|
167
|
+ notes = "Attempts to send test sms to the System Administrator User using SMS Settings and phone number provided as a parameters of the request. "
|
|
168
|
+ + SYS_ADMIN_AUTHORITY_ONLY)
|
141
|
169
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
142
|
170
|
@RequestMapping(value = "/settings/testSms", method = RequestMethod.POST)
|
143
|
|
- public void sendTestSms(@RequestBody TestSmsRequest testSmsRequest) throws ThingsboardException {
|
|
171
|
+ public void sendTestSms(
|
|
172
|
+ @ApiParam(value = "A JSON value representing the Test SMS request.")
|
|
173
|
+ @RequestBody TestSmsRequest testSmsRequest) throws ThingsboardException {
|
144
|
174
|
try {
|
145
|
175
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ);
|
146
|
176
|
smsService.sendTestSms(testSmsRequest);
|
...
|
...
|
@@ -149,6 +179,9 @@ public class AdminController extends BaseController { |
149
|
179
|
}
|
150
|
180
|
}
|
151
|
181
|
|
|
182
|
+ @ApiOperation(value = "Check for new Platform Releases (checkUpdates)",
|
|
183
|
+ notes = "Check notifications about new platform releases. "
|
|
184
|
+ + SYS_ADMIN_AUTHORITY_ONLY)
|
152
|
185
|
@PreAuthorize("hasAuthority('SYS_ADMIN')")
|
153
|
186
|
@RequestMapping(value = "/updates", method = RequestMethod.GET)
|
154
|
187
|
@ResponseBody
|
...
|
...
|
|