Ejemplo n.º 1
0
        public string Read(string role)
        {
            //Check if User claims such role
            if (!_userAuthorizationService.AuthorizeUser(role))
            {
                throw new FileSecurityException($"User can't read this file - FileName: {Filename}");
            }

            //Access text content in order to validate the header row
            IFileResult fileResult = base.ReadFromBase();

            string textContent = fileResult.AsString();
            string fileRole    = string.Empty;

            //Decrypt file data first
            if (_ecryptedFile)
            {
                textContent = _decryptDataService.DecryptData(textContent);
            }

            if (string.IsNullOrEmpty(textContent))
            {
                return(string.Empty);
            }

            //If user passed the first validation and is Admin then return content
            if (role.Equals("Admin", StringComparison.CurrentCultureIgnoreCase))
            {
                return(textContent.ToString());
            }

            if (textContent.Contains("Role="))
            {
                string[] aux = textContent.Split('|');
                if (aux.Length >= 1)
                {
                    fileRole = aux[0];
                    fileRole = fileRole.Replace("Role=", string.Empty);
                }
            }

            //Check role attribute is not empty or null
            if (string.IsNullOrEmpty(fileRole))
            {
                return(string.Empty);
            }

            //Authorize File read per Role
            if (!_fileRoleValidationService.Validate(fileRole, role))
            {
                throw new FileSecurityException($"User can't read this file - FileName: {Filename}");
            }

            return(textContent);
        }
 public static StringBuilder AsStringBuilder(this IFileResult fileResult)
 {
     return(fileResult.Content);
 }
Ejemplo n.º 3
0
 public static string AsString(this IFileResult fileResult)
 {
     return(fileResult.Content.ToString());
 }