@ -37,14 +37,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.http.HttpStatus ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.DeleteMapping ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.ResponseStatus ;
import org.springframework.web.bind.annotation.RestController ;
import org.springframework.web.context.request.async.DeferredResult ;
@ -125,8 +124,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Get the Administration Settings object using key (getAdminSettings)" ,
notes = "Get the Administration Settings object using specified string key. Referencing non-existing key will cause an error." + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/settings/{key}" , method = RequestMethod . GET )
@ResponseBody
@GetMapping ( value = "/settings/{key}" )
public AdminSettings getAdminSettings (
@Parameter ( description = "A string value of the key (e.g. 'general' or 'mail')." )
@PathVariable ( "key" ) String key ) throws ThingsboardException {
@ -144,8 +142,7 @@ public class AdminController extends BaseController {
"The Administration Settings Id will be present in the response. Specify the Administration Settings Id when you would like to update the Administration Settings. " +
"Referencing non-existing Administration Settings Id will cause an error." + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/settings" , method = RequestMethod . POST )
@ResponseBody
@PostMapping ( value = "/settings" )
public AdminSettings saveAdminSettings (
@Parameter ( description = "A JSON value representing the Administration Settings." )
@RequestBody AdminSettings adminSettings ) throws ThingsboardException {
@ -165,8 +162,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Get the Security Settings object (getSecuritySettings)" ,
notes = "Get the Security Settings object that contains password policy, etc." + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/securitySettings" , method = RequestMethod . GET )
@ResponseBody
@GetMapping ( value = "/securitySettings" )
public SecuritySettings getSecuritySettings ( ) throws ThingsboardException {
accessControlService . checkPermission ( getCurrentUser ( ) , Resource . ADMIN_SETTINGS , Operation . READ ) ;
return checkNotNull ( securitySettingsService . getSecuritySettings ( ) ) ;
@ -175,8 +171,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Update Security Settings (saveSecuritySettings)" ,
notes = "Updates the Security Settings object that contains password policy, etc." + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/securitySettings" , method = RequestMethod . POST )
@ResponseBody
@PostMapping ( value = "/securitySettings" )
public SecuritySettings saveSecuritySettings (
@Parameter ( description = "A JSON value representing the Security Settings." )
@RequestBody SecuritySettings securitySettings ) throws ThingsboardException {
@ -188,8 +183,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Get the JWT Settings object (getJwtSettings)" ,
notes = "Get the JWT Settings object that contains JWT token policy, etc. " + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/jwtSettings" , method = RequestMethod . GET )
@ResponseBody
@GetMapping ( value = "/jwtSettings" )
public JwtSettings getJwtSettings ( ) throws ThingsboardException {
accessControlService . checkPermission ( getCurrentUser ( ) , Resource . ADMIN_SETTINGS , Operation . READ ) ;
return checkNotNull ( jwtSettingsService . getJwtSettings ( ) ) ;
@ -198,8 +192,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Update JWT Settings (saveJwtSettings)" ,
notes = "Updates the JWT Settings object that contains JWT token policy, etc. The tokenSigningKey field is a Base64 encoded string." + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/jwtSettings" , method = RequestMethod . POST )
@ResponseBody
@PostMapping ( value = "/jwtSettings" )
public JwtPair saveJwtSettings (
@Parameter ( description = "A JSON value representing the JWT Settings." )
@RequestBody JwtSettings jwtSettings ) throws ThingsboardException {
@ -213,7 +206,7 @@ public class AdminController extends BaseController {
notes = "Attempts to send test email to the System Administrator User using Mail Settings provided as a parameter. " +
"You may change the 'To' email in the user profile of the System Administrator. " + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@Reque stMapping ( value = "/settings/testMail" , method = RequestMethod . POST )
@Po stMapping ( value = "/settings/testMail" )
public void sendTestMail (
@Parameter ( description = "A JSON value representing the Mail Settings." )
@RequestBody AdminSettings adminSettings ) throws ThingsboardException {
@ -251,7 +244,7 @@ public class AdminController extends BaseController {
notes = "Attempts to send test sms to the System Administrator User using SMS Settings and phone number provided as a parameters of the request. "
+ SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@Reque stMapping ( value = "/settings/testSms" , method = RequestMethod . POST )
@Po stMapping ( value = "/settings/testSms" )
public void sendTestSms (
@Parameter ( description = "A JSON value representing the Test SMS request." )
@RequestBody TestSmsRequest testSmsRequest ) throws ThingsboardException {
@ -325,7 +318,7 @@ public class AdminController extends BaseController {
notes = "Deletes the repository settings."
+ TENANT_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@Request Mapping ( value = "/repositorySettings" , method = RequestMethod . DELETE )
@Delete Mapping ( value = "/repositorySettings" )
@ResponseStatus ( value = HttpStatus . OK )
public DeferredResult < Void > deleteRepositorySettings ( ) throws Exception {
accessControlService . checkPermission ( getCurrentUser ( ) , Resource . VERSION_CONTROL , Operation . DELETE ) ;
@ -335,7 +328,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Check repository access (checkRepositoryAccess)" ,
notes = "Attempts to check repository access. " + TENANT_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@Reque stMapping ( value = "/repositorySettings/checkAccess" , method = RequestMethod . POST )
@Po stMapping ( value = "/repositorySettings/checkAccess" )
public DeferredResult < Void > checkRepositoryAccess (
@Parameter ( description = "A JSON value representing the Repository Settings." )
@RequestBody RepositorySettings settings ) throws Exception {
@ -376,7 +369,7 @@ public class AdminController extends BaseController {
notes = "Deletes the auto commit settings."
+ TENANT_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('TENANT_ADMIN')" )
@Request Mapping ( value = "/autoCommitSettings" , method = RequestMethod . DELETE )
@Delete Mapping ( value = "/autoCommitSettings" )
@ResponseStatus ( value = HttpStatus . OK )
public void deleteAutoCommitSettings ( ) throws ThingsboardException {
accessControlService . checkPermission ( getCurrentUser ( ) , Resource . VERSION_CONTROL , Operation . DELETE ) ;
@ -387,9 +380,8 @@ public class AdminController extends BaseController {
notes = "Check notifications about new platform releases. "
+ SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/updates" , method = RequestMethod . GET )
@ResponseBody
public UpdateMessage checkUpdates ( ) throws ThingsboardException {
@GetMapping ( value = "/updates" )
public UpdateMessage checkUpdates ( ) {
return updateService . checkUpdates ( ) ;
}
@ -397,9 +389,8 @@ public class AdminController extends BaseController {
notes = "Get main information about system. "
+ SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/systemInfo" , method = RequestMethod . GET )
@ResponseBody
public SystemInfo getSystemInfo ( ) throws ThingsboardException {
@GetMapping ( value = "/systemInfo" )
public SystemInfo getSystemInfo ( ) {
return systemInfoService . getSystemInfo ( ) ;
}
@ -407,8 +398,7 @@ public class AdminController extends BaseController {
notes = "Get information about enabled/disabled features. "
+ SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/featuresInfo" , method = RequestMethod . GET )
@ResponseBody
@GetMapping ( value = "/featuresInfo" )
public FeaturesInfo getFeaturesInfo ( ) {
return systemInfoService . getFeaturesInfo ( ) ;
}
@ -417,8 +407,7 @@ public class AdminController extends BaseController {
"double quotes. After successful authentication with OAuth2 provider and user consent for requested scope, it makes a redirect to this path so that the platform can do " +
"further log in processing and generating access tokens. " + SYSTEM_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN')" )
@RequestMapping ( value = "/mail/oauth2/loginProcessingUrl" , method = RequestMethod . GET )
@ResponseBody
@GetMapping ( value = "/mail/oauth2/loginProcessingUrl" )
public String getMailProcessingUrl ( ) throws ThingsboardException {
accessControlService . checkPermission ( getCurrentUser ( ) , Resource . ADMIN_SETTINGS , Operation . READ ) ;
return "\"/api/admin/mail/oauth2/code\"" ;
@ -427,7 +416,7 @@ public class AdminController extends BaseController {
@ApiOperation ( value = "Redirect user to mail provider login page. " , notes = "After user logged in and provided access" +
"provider sends authorization code to specified redirect uri.)" )
@PreAuthorize ( "hasAuthority('SYS_ADMIN')" )
@Reques tMapping ( value = "/mail/oauth2/authorize" , method = RequestMethod . GET , produces = "application/text" )
@Ge tMapping ( value = "/mail/oauth2/authorize" , produces = "application/text" )
public String getAuthorizationUrl ( HttpServletRequest request , HttpServletResponse response ) throws ThingsboardException {
String state = StringUtils . generateSafeToken ( ) ;
if ( request . getParameter ( PREV_URI_PATH_PARAMETER ) ! = null ) {
@ -452,7 +441,7 @@ public class AdminController extends BaseController {
. build ( ) + "\"" ;
}
@Reques tMapping ( value = "/mail/oauth2/code" , params = { "code" , "state" } , method = RequestMethod . GET )
@Ge tMapping ( value = "/mail/oauth2/code" , params = { "code" , "state" } )
public void codeProcessingUrl (
@RequestParam ( value = "code" ) String code , @RequestParam ( value = "state" ) String state ,
HttpServletRequest request , HttpServletResponse response ) throws ThingsboardException , IOException {