Exemple #1
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            bool authorized = true; //the desired answer

            string authHeader = context.HttpContext.Request.Headers[_authorizationFieldName];

            if (authHeader == null)
            {
                authorized = false;                     // could add log here?
            }
            var parts = authHeader.Split(' ', 2);

            if (parts.Length != 2)
            {
                authorized = false;                    //idem
            }
            string encryptedUser     = parts[0];
            string encryptedPassword = parts[1];

            if (string.IsNullOrEmpty(encryptedPassword) || string.IsNullOrEmpty(encryptedUser))
            {
                authorized = false;                                                                                 // idem
            }
            string user     = _encryptionServices.DecryptToString(encryptedUser);
            string password = _encryptionServices.DecryptToString(encryptedPassword);

            if (string.IsNullOrEmpty(user) ||
                user != _user ||
                string.IsNullOrEmpty(password) ||
                password != _password)
            {
                authorized = false;                       //idem
            }
            context.ActionArguments[AuthorizationParameterName] = authorized;
        }
Exemple #2
0
 private static void ExtractFromJsonNodeRecursive(
     IEncryptionServices encryptionServices,
     List <FileNode> fileNodesList,
     JsonNode jsonNodeParent,
     string accumulatedPath,
     string fileSeparator)
 {
     if (jsonNodeParent.isFile) //is a file node
     {
         fileNodesList.Add(new FileNode
         {
             RelativePath = accumulatedPath,
             FileName     = encryptionServices.DecryptToString(jsonNodeParent.name),
             FileBytes    = encryptionServices.DecryptToBytes(jsonNodeParent.file)
         });
     }
     else // this is a directory.
     {
         foreach (var jsonNodeChild in jsonNodeParent.children)
         {
             ExtractFromJsonNodeRecursive(
                 encryptionServices,
                 fileNodesList,
                 jsonNodeChild,
                 $"{accumulatedPath}{encryptionServices.DecryptToString(jsonNodeParent.name)}{fileSeparator}",
                 fileSeparator);
         }
     }
 }