Exemplo n.º 1
0
        public IEnumerable <EncryptionKeyPair> GetKeyPair <T>(T fileId, FileStorageService <T> FileStorageService)
        {
            var fileDao = DaoFactory.GetFileDao <T>();

            fileDao.InvalidateCache(fileId);

            var file = fileDao.GetFile(fileId);

            if (file == null)
            {
                throw new System.IO.FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
            }
            if (!FileSecurity.CanEdit(file))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
            }
            if (file.RootFolderType != FolderType.Privacy)
            {
                throw new NotSupportedException();
            }

            var fileShares = FileStorageService.GetSharedInfo(new List <T> {
                fileId
            }, new List <T> {
            }).ToList();

            fileShares = fileShares.Where(share => !share.SubjectGroup &&
                                          !share.SubjectId.Equals(FileConstant.ShareLinkId) &&
                                          share.Share == FileShare.ReadWrite).ToList();

            var fileKeysPair = fileShares.Select(share =>
            {
                var fileKeyPairString = EncryptionLoginProvider.GetKeys(share.SubjectId);
                if (string.IsNullOrEmpty(fileKeyPairString))
                {
                    return(null);
                }


                var options = new JsonSerializerOptions
                {
                    AllowTrailingCommas         = true,
                    PropertyNameCaseInsensitive = true
                };
                var fileKeyPair = JsonSerializer.Deserialize <EncryptionKeyPair>(fileKeyPairString, options);
                if (fileKeyPair.UserId != share.SubjectId)
                {
                    return(null);
                }

                fileKeyPair.PrivateKeyEnc = null;

                return(fileKeyPair);
            })
                               .Where(keyPair => keyPair != null);

            return(fileKeysPair);
        }
Exemplo n.º 2
0
 public bool CanSetAccess(FileEntry entry)
 {
     return
         (entry != null &&
          (entry.RootFolderType == FolderType.COMMON && Global.IsAdministrator ||
           entry.RootFolderType == FolderType.USER &&
           (Equals(entry.RootFolderId, GlobalFolderHelper.FolderMy) || FileSecurity.CanEdit(entry)) &&
           !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)));
 }
Exemplo n.º 3
0
 private bool CanEdit <T>(File <T> file)
 {
     return(file != null &&
            FileSecurity.CanEdit(file) &&
            !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager) &&
            !EntryManager.FileLockedForMe(file.ID) &&
            !FileTracker.IsEditing(file.ID) &&
            file.RootFolderType != FolderType.TRASH &&
            !file.Encrypted);
 }