コード例 #1
0
        private void seedQueue()
        {
            FileClaims Honda = new FileClaims(1, ClaimType.Car, "Car hit on i69", 4000.00, new DateTime(2020, 07, 02), new DateTime(2020, 06, 01), true);
            FileClaims House = new FileClaims(1, ClaimType.Home, "House fire in kitchen", 6000.00, new DateTime(2020, 07, 02), new DateTime(2020, 06, 01), true);
            FileClaims Theft = new FileClaims(1, ClaimType.Car, "Stolen pancakes", 10000.00, new DateTime(2020, 08, 12), new DateTime(2020, 06, 01), false);



            _itemRepo.AddClaimToList(Honda);
            _itemRepo.AddClaimToList(House);
            _itemRepo.AddClaimToList(Theft);
        }
コード例 #2
0
        public ReadOnlySecurity()
        {
            FolderClaimsResolverFunc = fi =>
            {
                var claims = FolderClaims.CreateRestricted();
                claims.AllowListContents = true;
                return(claims);
            };


            FileClaimsResolverFunc = fi =>
            {
                var claims = FileClaims.CreateRestricted();
                claims.AllowReadData = true;
                return(claims);
            };
        }
コード例 #3
0
        private void TakeCareOfNextClaim()
        {
            FileClaims nextClaim = _itemRepo.GetClaimList().Peek();

            Console.WriteLine($"ClaimId:{nextClaim.ClaimID,-10}\nType:{nextClaim.TypeofClaim,-10}\nDescription:{nextClaim.Description,-10}\nAmount:${nextClaim.ClaimAmount,-10}\nDateofAccident:{nextClaim.DateofIncident,-25}\nDateofClaim:{nextClaim.DateofClaim,-32}\nIsValid:{nextClaim.IsValid,-25} ");
            Console.WriteLine("Do you want to deal with this claim now? (yes/no)");

            string dealYes = Console.ReadLine().ToLower();

            if (dealYes == "yes")
            {
                _itemRepo.GetClaimList().Dequeue();
                //newClaim.IsValid = true;
            }
            //else
            //{
            //    Console.WriteLine("Please press any key to continue...");
            //    Console.ReadKey();
            //}
        }
コード例 #4
0
        /// <summary>
        /// Creates a transfer object for a given requested resource.
        /// </summary>
        /// <param name="submittedResourceFilePath">The resource identifier as submitted.</param>
        /// <param name="fileItem">Represents the requested file resource.</param>
        /// <param name="token">The token that is being issued for the transfer.</param>
        /// <param name="claims">The access rights for the resource.</param>
        /// <param name="lockGuard">File locks, if necessary. Can be a null reference
        /// if no locking takes place.</param>
        /// <param name="expirationJob">A scheduled job that invokes the
        /// <see cref="TransferHandlerBase{TFile,TToken,TTransfer}.OnTransferExpiration"/>"/>
        /// method once the transfer expires. May be null if the token does not expire.</param>
        /// <returns>A transfer object which encapsulates the information required to perform
        /// the transfer.</returns>
        protected override LocalDownloadTransfer CreateTransfer(string submittedResourceFilePath, FileItem fileItem,
                                                                DownloadToken token, FileClaims claims,
                                                                ResourceLockGuard lockGuard,
                                                                Job <DownloadToken> expirationJob)
        {
            var transfer = new LocalDownloadTransfer(token, fileItem)
            {
                Status = TransferStatus.Starting
            };

            if (expirationJob != null)
            {
                transfer.ExpirationNotificationJob = expirationJob;
            }
            if (lockGuard != null)
            {
                transfer.ResourceLock = lockGuard;
            }
            transfer.Owner = Config.Provider.Security.GetIdentity();

            return(transfer);
        }
コード例 #5
0
        /// <summary>
        /// Creates a transfer object for a given file resource.
        /// </summary>
        /// <param name="submittedResourceFilePath">The resource identifier as submitted.</param>
        /// <param name="fileItem">Represents the file resource to be uploaded.</param>
        /// <param name="parentFolder">The file's parent folder.</param>
        /// <param name="token">The token that is being issued for the transfer.</param>
        /// <param name="claims">The access rights for the resource.</param>
        /// <param name="lockGuard">File locks, if necessary. Can be a null reference
        /// if no locking takes place.</param>
        /// <param name="expirationJob">A scheduled job that invokes the
        /// <see cref="TransferHandlerBase{TFile,TToken,TTransfer}.OnTransferExpiration"/>
        /// method once the transfer expires. May be null if the token does not expire.</param>
        /// <returns>A transfer object which encapsulates the information required to perform
        /// the transfer.</returns>
        protected override ZipUploadTransfer CreateTransfer(string submittedResourceFilePath, ZipFileItem fileItem, ZipFolderItem parentFolder, UploadToken token, FileClaims claims, ResourceLockGuard lockGuard, Job <UploadToken> expirationJob)
        {
            var transfer = new ZipUploadTransfer(token, fileItem)
            {
                ParentFolder = parentFolder,
                Status       = TransferStatus.Starting,
                Owner        = Config.Provider.Security.GetIdentity()
            };

            if (expirationJob != null)
            {
                transfer.ExpirationNotificationJob = expirationJob;
            }
            if (lockGuard != null)
            {
                transfer.ResourceLock = lockGuard;
            }

            return(transfer);
        }
コード例 #6
0
 protected override ResourceLockGuard LockResourceForDownload(ZipFileItem fileItem, FileClaims claims)
 {
     return(Configuration.LockResolverFunc(fileItem, ResourceLockType.Read));
 }
コード例 #7
0
        private void EnterANewClaim()
        {
            //ClaimID
            Console.Clear();
            FileClaims newClaim = new FileClaims();

            Console.WriteLine(" Enter The ClaimID:");
            string starAsIntiger = Console.ReadLine();

            //int Idnumber;
            //Int32.TryParse(starAsIntiger, out Idnumber);
            newClaim.ClaimID = int.Parse(starAsIntiger);

            //Claim Type
            Console.WriteLine("Enter the Claim Type \n" +
                              "1. Car\n" +
                              "2. Home\n" +
                              "3. Theft \n");

            string claimTypeAsString = Console.ReadLine();           // take string description and Parse to int (to use the numbers)
            int    claimTypeAsInt    = int.Parse(claimTypeAsString); // Pase description from string to Int

            newClaim.TypeofClaim = (ClaimType)claimTypeAsInt;        //Casting take one object and cast it to different type.

            // Description
            Console.WriteLine("Enter the description for the Claim:");
            newClaim.Description = Console.ReadLine();

            // Claim Amount
            Console.WriteLine("Enter the Claim Amount:");
            string starsAsString = Console.ReadLine();

            newClaim.ClaimAmount = double.Parse(starsAsString);

            //Date of Accident

            Console.WriteLine("Date of Incident: ie:(mm/dd/yyyy)");
            newClaim.DateofIncident = DateTime.Parse(Console.ReadLine());



            //Console.WriteLine("TIME: {0}", value);

            Console.WriteLine("Date of Claim: ie:(mm/dd/yyyy)");
            newClaim.DateofClaim = DateTime.Parse(Console.ReadLine());

            // Date of Claim

            Console.WriteLine("Is this Claim Valid to proceed ? (True/False)");
            string validClaim = Console.ReadLine().ToLower();

            if (validClaim == "True")
            {
                newClaim.IsValid = true;
            }
            else
            {
                newClaim.IsValid = false;
            }


            _itemRepo.AddClaimToList(newClaim);
        }
コード例 #8
0
 /// <summary>
 /// Creates a transfer object for a given file resource.
 /// </summary>
 /// <param name="submittedResourceFilePath">The resource identifier as submitted.</param>
 /// <param name="fileItem">Represents the file resource to be uploaded.</param>
 /// <param name="parentFolder">The file's parent folder.</param>
 /// <param name="token">The token that is being issued for the transfer.</param>
 /// <param name="claims">The access rights for the resource.</param>
 /// <param name="lockGuard">File locks, if necessary. Can be a null reference
 /// if no locking takes place.</param>
 /// <param name="expirationJob">A scheduled job that invokes the
 /// <see cref="TransferHandlerBase{TFile,TToken,TTransfer}.OnTransferExpiration"/>
 /// method once the transfer expires. May be null if the token does not expire.</param>
 /// <returns>A transfer object which encapsulates the information required to perform
 /// the transfer.</returns>
 protected abstract TTransfer CreateTransfer(string submittedResourceFilePath, TFile fileItem, TFolder parentFolder, UploadToken token, FileClaims claims, ResourceLockGuard lockGuard, Job <UploadToken> expirationJob);
コード例 #9
0
        private TTransfer InitTransferImpl(string submittedResourceFilePath, bool overwrite, long resourceLength, string contentType)
        {
            const FileSystemTask context = FileSystemTask.UploadTokenRequest;

            //validate maximum file size
            var maxFileSize = GetMaxFileUploadSize();

            if (maxFileSize.HasValue && maxFileSize < resourceLength)
            {
                string msg = "Upload for file [{0}] denied: Resource length of [{1}] is above the maximum upload limit of [{2}] bytes.";
                msg = String.Format(msg, submittedResourceFilePath, resourceLength, maxFileSize.Value);
                throw new ResourceAccessException(msg);
            }

            //of course, the length cannot be negative
            if (resourceLength < 0)
            {
                string msg = "Upload for file [{0}] denied: Resource length cannot be negative [{1}].";
                msg = String.Format(msg, submittedResourceFilePath, resourceLength);
                throw new ResourceAccessException(msg);
            }


            TFile fileItem = CreateFileItemImpl(submittedResourceFilePath, false, context);

            if (fileItem.Exists && !overwrite)
            {
                AuditHelper.AuditDeniedOperation(Auditor, context, AuditEvent.FileAlreadyExists, fileItem);

                string msg = String.Format("Cannot upload file [{0}] without overwriting existing data - a file already exists at this location.", submittedResourceFilePath);
                throw new ResourceOverwriteException(msg)
                      {
                          IsAudited = true
                      };
            }

            //get authorization
            TFolder parentFolder = GetParentFolder(fileItem, context);

            //validate file system specific restrictions
            VerifyCanUploadFileToFileSystemLocation(submittedResourceFilePath, parentFolder, fileItem);

            //get parent folder and check whether files can be added
            FolderClaims folderClaims = GetParentFolderClaims(fileItem, parentFolder);

            if (!folderClaims.AllowAddFiles)
            {
                //deny adding a file to that folder
                AuditHelper.AuditDeniedOperation(Auditor, context, AuditEvent.CreateFileDenied, fileItem);

                string msg = "Cannot create file at [{0}] - adding files to the folder is not permitted.";
                msg = String.Format(msg, submittedResourceFilePath);
                throw new ResourceAccessException(msg)
                      {
                          IsAudited = true
                      };
            }


            //only overwrite a file if explicitly requested
            FileClaims claims = GetFileClaims(fileItem);

            if (fileItem.Exists)
            {
                if (!claims.AllowOverwrite)
                {
                    AuditHelper.AuditDeniedOperation(Auditor, context, AuditEvent.FileDataOverwriteDenied, fileItem);

                    string msg = "Overwriting file [{0}] was denied due to missing permission.";
                    msg = String.Format(msg, submittedResourceFilePath);
                    throw new ResourceOverwriteException(msg)
                          {
                              IsAudited = true
                          };
                }
            }


            //try to get lock
            ResourceLockGuard writeLock = LockResourceForUpload(fileItem);

            if (writeLock != null && !writeLock.IsLockEnabled)
            {
                AuditHelper.AuditDeniedOperation(Auditor, context, AuditEvent.FileReadLockDenied, fileItem);

                string msg = "The file [{0}] is currently locked and cannot be accessed.";
                msg = String.Format(msg, submittedResourceFilePath);
                throw new ResourceLockedException(msg)
                      {
                          IsAudited = true
                      };
            }

            //create upload token
            UploadToken token = CreateUploadToken(submittedResourceFilePath, fileItem, resourceLength, contentType);

            //create expiration job if we have an expiration time
            Job <UploadToken> job = null;

            if (token.ExpirationTime.HasValue)
            {
                job = ScheduleExpiration(token);
            }

            //create and cache transfer instance
            TTransfer transfer = CreateTransfer(submittedResourceFilePath, fileItem, parentFolder, token, claims, writeLock, job);

            TransferStore.AddTransfer(transfer);

            AuditHelper.AuditResourceOperation(Auditor, context, AuditEvent.UploadTokenIssued, fileItem);
            return(transfer);
        }
コード例 #10
0
 /// <summary>
 /// Locks the resource if necessary, and returns a <see cref="ResourceLockGuard"/>
 /// that contains all the required locks. The invoking method will check whether
 /// the lock was granted through the <see cref="ResourceLockGuard.IsLockEnabled"/>
 /// property and throw an exception if the lock was not available.<br/>
 /// If no locking is necessary, this method should just return a null reference.
 /// </summary>
 /// <param name="fileItem">Represents the requested file resource.</param>
 /// <param name="claims">The access rights for the resource as returned by
 /// <see cref="TransferHandlerBase{TFile,TToken,TTransfer}.GetFileClaims"/>.</param>
 /// <returns>Locks for the file, or <c>null</c> if no locking is necessary.<br/>
 /// Failed locking is indicated by a returned <see cref="ResourceLockGuard"/> whose
 /// <see cref="ResourceLockGuard.IsLockEnabled"/> property is set to false.</returns></returns>
 protected abstract ResourceLockGuard LockResourceForDownload(TFile fileItem, FileClaims claims);
コード例 #11
0
        private TTransfer InitTransferImpl(string submittedResourceFilePath, int?clientMaxBlockSize, bool includeFileHash)
        {
            const FileSystemTask context = FileSystemTask.DownloadTokenRequest;
            TFile fileItem = CreateFileItemImpl(submittedResourceFilePath, false, context);

            if (!fileItem.Exists)
            {
                Auditor.AuditRequestedFileNotFound(fileItem, context);

                string msg = String.Format("Resource [{0}] not found.", submittedResourceFilePath);
                throw new VirtualResourceNotFoundException(msg)
                      {
                          IsAudited = true
                      };
            }

            //get authorization
            FileClaims claims = GetFileClaims(fileItem);

            if (!claims.AllowReadData)
            {
                Auditor.AuditDeniedOperation(context, AuditEvent.FileDataDownloadDenied, fileItem);

                string msg = "Read request for file [{0}] was denied - you are not authorized to read the resource.";
                msg = String.Format(msg, submittedResourceFilePath);
                throw new ResourceAccessException(msg)
                      {
                          IsAudited = true
                      };
            }

            //try to get lock
            ResourceLockGuard readLock = LockResourceForDownload(fileItem, claims);

            if (readLock != null && !readLock.IsLockEnabled)
            {
                Auditor.AuditDeniedOperation(context, AuditEvent.FileReadLockDenied, fileItem);

                string msg = "The requested file [{0}] is currently locked and thus cannot be accessed.";
                msg = String.Format(msg, submittedResourceFilePath);
                throw new ResourceLockedException(msg)
                      {
                          IsAudited = true
                      };
            }

            //create download token
            DownloadToken token = CreateDownloadToken(submittedResourceFilePath, fileItem, clientMaxBlockSize, includeFileHash);

            //create expiration job if we have an expiration time
            Job <DownloadToken> job = null;

            if (token.ExpirationTime.HasValue)
            {
                job = ScheduleExpiration(token);
            }

            //create transfer instance
            TTransfer transfer = CreateTransfer(submittedResourceFilePath, fileItem, token, claims, readLock, job);

            //cache transfer
            TransferStore.AddTransfer(transfer);

            //audit issued token
            Auditor.AuditResourceOperation(context, AuditEvent.DownloadTokenIssued, fileItem);

            return(transfer);
        }