/// <summary> /// Audits a request for the file system's root folder. /// </summary> public static void AuditRootFolderRequest(IAuditor auditor, IVirtualFolderItem rootFolder) { if (!AuditHelper.IsInfoEnabledFor(auditor, FileSystemTask.RootFolderInfoRequest)) { return; } const string msg = "File system root requested."; auditor.Audit(AuditLevel.Info, FileSystemTask.RootFolderInfoRequest, AuditEvent.FolderInfoRequested, msg); }
/// <summary> /// Audits an attempt to delete the root folder. /// </summary> public static void AuditDeleteRootAttempt(IAuditor auditor, IVirtualFolderItem folder) { if (!AuditHelper.IsWarnEnabledFor(auditor, FileSystemTask.FolderDeleteRequest)) { return; } string msg = String.Format("Blocked attempt to delete root folder.\n\n{0}", AuditHelper.CreateResourceInfoString(folder)); auditor.Audit(AuditLevel.Warning, FileSystemTask.FolderDeleteRequest, AuditEvent.DeleteFileSystemRoot, msg); }
/// <summary> /// Audits a request for a folder that was not found on the file system. /// </summary> public static void AuditRequestedFolderNotFound(IAuditor auditor, IVirtualFolderItem folder, FileSystemTask context) { if (!AuditHelper.IsWarnEnabledFor(auditor, context)) { return; } string msg = "Could not handle request for folder [{0}] - the folder was not found on the file system.\n\n{1}"; msg = String.Format(msg, folder.ResourceInfo.Name, AuditHelper.CreateResourceInfoString(folder)); auditor.Audit(AuditLevel.Warning, context, AuditEvent.FolderNotFound, msg); }
/// <summary> /// Audits a request for the file system's root folder. /// </summary> public static void AuditInvalidRootParentRequest(IAuditor auditor, IVirtualFolderItem childFolder) { if (!AuditHelper.IsWarnEnabledFor(auditor, FileSystemTask.FolderParentRequest)) { return; } string msg = "Parent folder request for file system root was blocked. Submitted folder:\n{0}"; msg = String.Format(msg, AuditHelper.CreateResourceInfoString(childFolder)); auditor.Audit(AuditLevel.Warning, FileSystemTask.FolderParentRequest, AuditEvent.FolderInfoRequested, msg); }
/// <summary> /// Audits a request for the file system's root folder. /// </summary> public static void AuditFolderParentRequest(IAuditor auditor, IVirtualFolderItem childFolder, IVirtualFolderItem parentFolder) { if (!AuditHelper.IsInfoEnabledFor(auditor, FileSystemTask.FolderParentRequest)) { return; } string msg = "Parent folder of folder [{0}] was requested.\nSubmitted folder:\n{1}\n\nParent folder:\n{2}"; msg = String.Format(msg, childFolder.ResourceInfo.Name, AuditHelper.CreateResourceInfoString(childFolder), AuditHelper.CreateResourceInfoString(parentFolder)); auditor.Audit(AuditLevel.Info, FileSystemTask.FolderParentRequest, AuditEvent.FolderInfoRequested, msg); }
/// <summary> /// Audits that a folder was created on the file system. /// </summary> public static void AuditFolderCreation(IAuditor auditor, IVirtualFolderItem folder) { const FileSystemTask context = FileSystemTask.FolderCreateRequest; if (!AuditHelper.IsInfoEnabledFor(auditor, context)) { return; } string msg = "Created folder [{0}] on the file system.\n\n{1}"; msg = String.Format(msg, folder.ResourceInfo.Name, AuditHelper.CreateResourceInfoString(folder)); auditor.Audit(AuditLevel.Info, context, AuditEvent.FolderCreated, msg); }
/// <summary> /// Audits a request for a given folder's meta data (e.g. through <see cref="IFileSystemProvider.GetFolderInfo"/>. /// Be aware that this might cause verbose audit trails. /// </summary> public static void AuditFolderInfoRequest(IAuditor auditor, FileSystemTask context, IVirtualFolderItem folder) { if (!AuditHelper.IsInfoEnabledFor(auditor, context)) { return; } string msg = String.Format("Folder information requested:\n{0}", AuditHelper.CreateResourceInfoString(folder)); auditor.Audit(AuditLevel.Info, context, AuditEvent.FolderInfoRequested, msg); }
/// <summary> /// Gets authorization claims for a given folder resource. /// </summary> /// <param name="folderItem">The currently processed folder.</param> /// <returns>The requesting party's permissions for the /// submitted <paramref name="folderItem"/>.</returns> public FolderClaims GetFolderClaims(IVirtualFolderItem folderItem) { return(FolderClaims.CreatePermissive()); }
/// <summary> /// Copies a physical folder on the file system from one location to the other. This /// method is invoked by <see cref="FileSystemProviderBase2{TFile,TFolder}.CopyFolder(string,string)"/>. /// </summary> /// <param name="sourceFolder">The folder to be copied.</param> /// <param name="targetFolder">The designated location of the copy.</param> protected override void CopyFolderOnFileSystem(IVirtualFolderItem sourceFolder, IVirtualFolderItem targetFolder) { CopyFolderOnFileSystem2(sourceFolder as FolderItem, targetFolder as FolderItem); }
/// <summary> /// This method is invoked by <see cref="FileSystemProviderBase2{TFile,TFolder}.CreateFolder(string)"/> in order /// to handle the creation of a physical folder on the file system. /// </summary> /// <param name="folder">Describes the (currently unavailable folder).</param> /// <returns>Either the updated <paramref name="folder"/> reference that /// was submitted, or a new <see cref="FolderItem"/> that represents the /// created folder.</returns> protected override IVirtualFolderItem CreateFolderOnFileSystem(IVirtualFolderItem folder) { return(CreateFolderOnFileSystem2(folder as FolderItem)); }
/// <summary> /// Gets authorization claims for a given folder resource. /// </summary> /// <param name="folderItem">The currently processed folder.</param> /// <returns>The requesting party's permissions for the /// submitted <paramref name="folderItem"/>.</returns> public FolderClaims GetFolderClaims(IVirtualFolderItem folderItem) { return FolderClaims.CreatePermissive(); }
/// <summary> /// Gets authorization claims for a given folder resource. /// </summary> /// <param name="folderItem">The currently processed folder.</param> /// <returns>The requesting party's permissions for the /// submitted <paramref name="folderItem"/>.</returns> public FolderClaims GetFolderClaims(IVirtualFolderItem folderItem) { throw new NotImplementedException(""); //TODO provide implementation }
/// <summary> /// Audits a request for a folder's files and sub folders. /// </summary> public static void AuditFolderContentsRequest(this IAuditor auditor, FileSystemTask context, IVirtualFolderItem parentFolder) { if (!auditor.IsInfoEnabledFor(context)) { return; } string msg = "Delivered contents of folder [{0}]. Folder details:\n\n{1}"; msg = String.Format(msg, parentFolder.ResourceInfo.Name, parentFolder.CreateResourceInfoString()); auditor.Audit(AuditLevel.Info, context, AuditEvent.FolderContentsRequested, msg); }
/// <summary> /// Audits a request for the file system's root folder. /// </summary> public static void AuditFileParentRequest(this IAuditor auditor, IVirtualFileItem childFile, IVirtualFolderItem parentFolder) { if (!auditor.IsInfoEnabledFor(FileSystemTask.FileParentRequest)) { return; } string msg = "Parent folder of file [{0}] was requested.\nSubmitted file:\n{1}\n\nParent folder:\n{2}"; msg = String.Format(msg, childFile.ResourceInfo.Name, childFile.CreateResourceInfoString(), parentFolder.CreateResourceInfoString()); auditor.Audit(AuditLevel.Info, FileSystemTask.FileParentRequest, AuditEvent.FolderInfoRequested, msg); }
/// <summary> /// Resolves all child files of a given parent folder. This method is invoked /// by the <see cref="GetChildFiles"/> method in order to resolve the /// qualified paths of all files within that folder, which can be used in order to /// create <see cref="VirtualFileInfo"/> instances based on the returned paths. /// </summary> /// <param name="parentFolder">The currently processed folder.</param> /// <returns>File paths that can be resolved to the files withing the submitted /// <paramref name="parentFolder"/>.</returns> protected abstract IEnumerable<string> GetChildFilePathsInternal(IVirtualFolderItem parentFolder);
/// <summary> /// Gets all resources that need to be read-locked (and thus write-protected) /// in order to savely access a given folder. With hierarchical folder systems, /// these are usually the parent folders of the folder, because deleting, /// moving, or renaming the folder would cause folder access issues if the /// folder is still accessed). /// </summary> /// <param name="folder">The currently processed folder.</param> /// <returns>All resources that need to be write-protected in order to /// process the folder.</returns> protected abstract List<string> GetResourceLockChain(IVirtualFolderItem folder);
/// <summary> /// Tries to acquire a lock for a given folder and its parent folders, /// and executes the submitted <paramref name="action"/> if the lock /// was granted. Otherwise audits a warning. /// </summary> /// <param name="folder">The folder to be locked.</param> /// <param name="context">The currently performed file system operation.</param> /// <param name="lockType">Whether a read or a write lock is required for the /// <paramref name="folder"/>.</param> /// <param name="action">An action that is being executed if the locking /// succeeded.</param> /// <returns>True if locking succeeded and the <paramref name="action"/> was invoked. False /// if the lock was not granted.</returns> protected virtual bool LockResourceAndExecute(IVirtualFolderItem folder, FileSystemTask context, ResourceLockType lockType, Action action) { using (var guard = RequestChainedLockGuard(folder, lockType)) { if (!guard.IsLockEnabled) { AuditEvent ae = lockType == ResourceLockType.Read ? AuditEvent.FolderReadLockDenied : AuditEvent.FolderWriteLockDenied; AuditHelper.AuditDeniedOperation(Auditor,context, ae, folder); return false; } action(); return true; } }
/// <summary> /// Creates a <see cref="ResourceLockGuard"/> that encapsulates /// a read or write lock for a given folder as well as read locks /// for all its parent folders. /// </summary> /// <param name="folder">The folder to be locked.</param> /// <param name="lockType">Whether a read or a write lock is being /// required for the <paramref name="folder"/>.</param> /// <returns>A guard which releases folder resource and all folders once it is being disposed. /// If locking did not succeed because an element in the chain could not be locked, /// the returned <see cref="ResourceLockGuard.IsLockEnabled"/> property /// is false.</returns> protected virtual ResourceLockGuard RequestChainedLockGuard(IVirtualFolderItem folder, ResourceLockType lockType) { List<string> parentFolders = GetResourceLockChain(folder); switch (lockType) { case ResourceLockType.Read: return LockRepository.GetResourceChainLock(folder.QualifiedIdentifier, false, parentFolders); case ResourceLockType.Write: return LockRepository.GetResourceChainLock(folder.QualifiedIdentifier, true, parentFolders); default: throw new ArgumentOutOfRangeException("lockType", "Unknown lock type: " + lockType); } }
/// <summary> /// Gets authorization claims for a given folder resource. /// </summary> /// <param name="folderItem">The currently processed folder.</param> /// <returns>The requesting party's permissions for the /// submitted <paramref name="folderItem"/>.</returns> public FolderClaims GetFolderClaims(IVirtualFolderItem folderItem) { return(FolderClaimsResolverFunc == null ? null : FolderClaimsResolverFunc(folderItem)); }
/// <summary> /// This method is invoked by <see cref="CreateFolder"/> in order /// to handle the creation of a physical folder on the file system. /// </summary> /// <param name="folder">Describes the (currently unavailable folder).</param> /// <returns>Either the updated <paramref name="folder"/> reference that /// was submitted, or a new <see cref="TFolder"/> that represents the /// created folder.</returns> protected abstract IVirtualFolderItem CreateFolderOnFileSystem(IVirtualFolderItem folder);
protected override void MoveFolderOnFileSystem(IVirtualFolderItem sourceFolder, IVirtualFolderItem targetFolder) { MoveFolderOnFileSystem2(sourceFolder as ZipFolderItem, targetFolder as ZipFolderItem); }
/// <summary> /// Audits a denied request for a folder's contents. /// </summary> public static void AuditDeniedFolderContentsRequest(IAuditor auditor, FileSystemTask context, IVirtualFolderItem parentFolder) { if (!AuditHelper.IsWarnEnabledFor(auditor, context)) { return; } string msg = "Denied access to contents of folder [{0}]. Folder details:\n\n{1}"; msg = String.Format(msg, parentFolder.ResourceInfo.Name, AuditHelper.CreateResourceInfoString(parentFolder)); auditor.Audit(AuditLevel.Warning, context, AuditEvent.ListFolderContentsDenied, msg); }
/// <summary> /// Physically deletes a given folder on the file system. This method is /// being invoked by the <see cref="DeleteFolder"/> method. /// </summary> /// <param name="folder">The folder to be deleted.</param> protected abstract void DeleteFolderOnFileSystem(IVirtualFolderItem folder);
/// <summary> /// Moves a physical folder on the file system from one location to the other. This /// method is invoked by <see cref="MoveFolder"/>. /// </summary> /// <param name="sourceFolder">The folder to be copied.</param> /// <param name="targetFolder">The designated new location of the folder.</param> protected abstract void MoveFolderOnFileSystem(IVirtualFolderItem sourceFolder, IVirtualFolderItem targetFolder);
protected override IEnumerable<string> GetChildFilePathsInternal(IVirtualFolderItem parentFolder) { return GetChildFilePathsInternal2(parentFolder as ZipFolderItem); }
public static void AuditDeniedFolderCreation(IAuditor auditor, AuditEvent eventId, IVirtualFolderItem folder) { if (!AuditHelper.IsWarnEnabledFor(auditor, FileSystemTask.FolderCreateRequest)) { return; } string msg = String.Format("Blocked attempt to create folder on file system. Folder information:\n{0}", AuditHelper.CreateResourceInfoString(folder)); auditor.Audit(AuditLevel.Warning, FileSystemTask.FolderCreateRequest, eventId, msg); }
protected override IVirtualFolderItem CreateFolderOnFileSystem(IVirtualFolderItem folder) { return CreateFolderOnFileSystem2(folder as ZipFolderItem); }
protected override void DeleteFolderOnFileSystem(IVirtualFolderItem folder) { DeleteFolderOnFileSystem2(folder as ZipFolderItem); }
/// <summary> /// Resolves all child files of a given parent folder. This method is invoked /// by the <see cref="FileSystemProviderBase2{TFile,TFolder}.GetChildFiles(string)"/> method in order to resolve the /// qualified paths of all files within that folder, which can be used in order to /// create <see cref="VirtualFileInfo"/> instances based on the returned paths. /// </summary> /// <param name="parentFolder">The currently processed folder.</param> /// <returns>File paths that can be resolved to the files withing the submitted /// <paramref name="parentFolder"/>.</returns> protected override IEnumerable <string> GetChildFilePathsInternal(IVirtualFolderItem parentFolder) { return(GetChildFilePathsInternal2(parentFolder as FolderItem)); }
/// <summary> /// Copies a physical folder on the file system from one location to the other. This /// method is invoked by <see cref="FileSystemProviderBase2{TFile,TFolder}.CopyFolder(string,string)"/>. /// </summary> /// <param name="sourceFolder">The folder to be copied.</param> /// <param name="targetFolder">The designated location of the copy.</param> protected override void CopyFolderOnFileSystem(IVirtualFolderItem sourceFolder, IVirtualFolderItem targetFolder) { CopyFolderOnFileSystem2(sourceFolder as ZipFolderItem, targetFolder as ZipFolderItem); }
/// <summary> /// Physically deletes a given folder on the file system. This method is /// being invoked by the <see cref="FileSystemProviderBase2{TFile,TFolder}.DeleteFolder"/> method. /// </summary> /// <param name="folder">The folder to be deleted.</param> protected override void DeleteFolderOnFileSystem(IVirtualFolderItem folder) { DeleteFolderOnFileSystem2(folder as FolderItem); }
/// <summary> /// Gets all resources that need to be read-locked (and thus write-protected) /// in order to savely access a given folder. With hierarchical folder systems, /// these are usually the parent folders of the folder, because deleting, /// moving, or renaming the folder would cause folder access issues if the /// folder is still accessed). /// </summary> /// <param name="folder">The currently processed folder.</param> /// <returns>All resources that need to be write-protected in order to /// process the folder.</returns> protected override List<string> GetResourceLockChain(IVirtualFolderItem folder) { return GetResourceLockChain2(folder as ZipFolderItem); }
/// <summary> /// Gets all resources that need to be read-locked (and thus write-protected) /// in order to savely access a given folder. With hierarchical folder systems, /// these are usually the parent folders of the folder, because deleting, /// moving, or renaming the folder would cause folder access issues if the /// folder is still accessed). /// </summary> /// <param name="folder">The currently processed folder.</param> /// <returns>All resources that need to be write-protected in order to /// process the folder.</returns> protected override List <string> GetResourceLockChain(IVirtualFolderItem folder) { return(GetResourceLockChain2(folder as FolderItem)); }
/// <summary> /// Moves a physical folder on the file system from one location to the other. This /// method is invoked by <see cref="FileSystemProviderBase2{TFile,TFolder}.MoveFolder(string,string)"/>. /// </summary> /// <param name="sourceFolder">The folder to be copied.</param> /// <param name="targetFolder">The designated new location of the folder.</param> /// <returns>Either the updated <paramref name="targetFolder"/> instance, or a new /// <see cref="FolderItem"/> instance that represents the created target folder.</returns> protected override void MoveFolderOnFileSystem(IVirtualFolderItem sourceFolder, IVirtualFolderItem targetFolder) { MoveFolderOnFileSystem2(sourceFolder as FolderItem,targetFolder as FolderItem); }