2022-03-03 17:33:11 +00:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
|
*
|
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
|
*
|
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
|
*
|
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
|
*
|
|
|
|
|
* Pursuant to Section 7 <EFBFBD> 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
|
* Pursuant to Section 7 <EFBFBD> 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace ASC.Api.Documents;
|
|
|
|
|
|
|
|
|
|
[Scope]
|
|
|
|
|
[DefaultRoute]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class PrivacyRoomController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly AuthContext _authContext;
|
2022-03-04 10:25:12 +00:00
|
|
|
|
private readonly EncryptionKeyPairDtoHelper _encryptionKeyPairHelper;
|
2022-03-03 17:33:11 +00:00
|
|
|
|
private readonly FileStorageService<string> _fileStorageService;
|
|
|
|
|
private readonly FileStorageService<int> _fileStorageServiceInt;
|
|
|
|
|
private readonly ILog _logger;
|
|
|
|
|
private readonly MessageService _messageService;
|
|
|
|
|
private readonly PermissionContext _permissionContext;
|
|
|
|
|
private readonly SettingsManager _settingsManager;
|
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
|
|
|
|
|
|
public PrivacyRoomController(
|
|
|
|
|
AuthContext authContext,
|
|
|
|
|
PermissionContext permissionContext,
|
|
|
|
|
SettingsManager settingsManager,
|
|
|
|
|
TenantManager tenantManager,
|
2022-03-04 10:25:12 +00:00
|
|
|
|
EncryptionKeyPairDtoHelper encryptionKeyPairHelper,
|
2022-03-03 17:33:11 +00:00
|
|
|
|
FileStorageService<int> fileStorageServiceInt,
|
|
|
|
|
FileStorageService<string> fileStorageService,
|
|
|
|
|
MessageService messageService,
|
|
|
|
|
IOptionsMonitor<ILog> option)
|
|
|
|
|
{
|
|
|
|
|
_authContext = authContext;
|
|
|
|
|
_permissionContext = permissionContext;
|
|
|
|
|
_settingsManager = settingsManager;
|
|
|
|
|
_tenantManager = tenantManager;
|
|
|
|
|
_encryptionKeyPairHelper = encryptionKeyPairHelper;
|
|
|
|
|
_fileStorageServiceInt = fileStorageServiceInt;
|
|
|
|
|
_fileStorageService = fileStorageService;
|
|
|
|
|
_messageService = messageService;
|
|
|
|
|
_logger = option.Get("ASC.Api.Documents");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("keys")]
|
2022-03-04 10:25:12 +00:00
|
|
|
|
public EncryptionKeyPairDto GetKeys()
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(_authContext.CurrentAccount.ID), Constants.Action_EditUser);
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(_settingsManager))
|
|
|
|
|
{
|
|
|
|
|
throw new System.Security.SecurityException();
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
return _encryptionKeyPairHelper.GetKeyPair();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("access/{fileId}")]
|
2022-03-04 10:25:12 +00:00
|
|
|
|
public Task<IEnumerable<EncryptionKeyPairDto>> GetPublicKeysWithAccess(string fileId)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(_settingsManager))
|
|
|
|
|
{
|
|
|
|
|
throw new System.Security.SecurityException();
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
return _encryptionKeyPairHelper.GetKeyPairAsync(fileId, _fileStorageService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("access/{fileId:int}")]
|
2022-03-04 10:25:12 +00:00
|
|
|
|
public Task<IEnumerable<EncryptionKeyPairDto>> GetPublicKeysWithAccess(int fileId)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-08 17:37:23 +00:00
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(_settingsManager))
|
|
|
|
|
{
|
|
|
|
|
throw new System.Security.SecurityException();
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
return _encryptionKeyPairHelper.GetKeyPairAsync(fileId, _fileStorageServiceInt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("")]
|
|
|
|
|
public bool PrivacyRoom()
|
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
|
|
|
|
|
return PrivacyRoomSettings.GetEnabled(_settingsManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Update("keys")]
|
2022-03-05 14:41:47 +00:00
|
|
|
|
public object SetKeysFromBody([FromBody] PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
return SetKeys(inDto);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("keys")]
|
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
2022-03-05 14:41:47 +00:00
|
|
|
|
public object SetKeysFromForm([FromForm] PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
return SetKeys(inDto);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enable"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Update("")]
|
2022-03-05 14:41:47 +00:00
|
|
|
|
public bool SetPrivacyRoomFromBody([FromBody] PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
return SetPrivacyRoom(inDto);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("")]
|
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
2022-03-05 14:41:47 +00:00
|
|
|
|
public bool SetPrivacyRoomFromForm([FromForm] PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
return SetPrivacyRoom(inDto);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
private object SetKeys(PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(_authContext.CurrentAccount.ID), Constants.Action_EditUser);
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(_settingsManager))
|
|
|
|
|
{
|
|
|
|
|
throw new System.Security.SecurityException();
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
var keyPair = _encryptionKeyPairHelper.GetKeyPair();
|
|
|
|
|
if (keyPair != null)
|
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(keyPair.PublicKey) && !inDto.Update)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
return new { isset = true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.InfoFormat("User {0} updates address", _authContext.CurrentAccount.ID);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
_encryptionKeyPairHelper.SetKeyPair(inDto.PublicKey, inDto.PrivateKeyEnc);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
return new
|
|
|
|
|
{
|
|
|
|
|
isset = true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
private bool SetPrivacyRoom(PrivacyRoomRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
if (inDto.Enable)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (!PrivacyRoomSettings.IsAvailable(_tenantManager))
|
|
|
|
|
{
|
|
|
|
|
throw new BillingException(Resource.ErrorNotAllowedOption, "PrivacyRoom");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
PrivacyRoomSettings.SetEnabled(_tenantManager, _settingsManager, inDto.Enable);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
_messageService.Send(inDto.Enable ? MessageAction.PrivacyRoomEnable : MessageAction.PrivacyRoomDisable);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
2022-03-05 14:41:47 +00:00
|
|
|
|
return inDto.Enable;
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|