Example #1
0
        public static bool PassWordsCompare(string pass1, string pass2)
        {
            string temPpassword;

            try
            {
                temPpassword = DpapiWrapper.DecryptIfEncrypted(pass1);
            }
            catch (Exception)
            {
                //
                temPpassword = pass1;
            }

            string temPpassword1;

            try
            {
                temPpassword1 = DpapiWrapper.DecryptIfEncrypted(pass2);
            }
            catch (Exception)
            {
                //
                temPpassword1 = pass2;
            }

            return(string.Equals(temPpassword, temPpassword1));
        }
        public void FileReadWithBase64_GivenPasswordEncryted_ShouldReturnSamePassword()
        {
            //---------------Set up test pack-------------------
            var uniqueId     = Guid.NewGuid().ToString();
            var password     = "******";
            var encrytedPass = DpapiWrapper.DecryptIfEncrypted(password);
            var fileRead     = new FileReadWithBase64 {
                UniqueID = uniqueId, Password = encrytedPass
            };
            var fileRead1 = new FileReadWithBase64 {
                UniqueID = uniqueId, Password = "******"
            };

            //---------------Assert Precondition----------------
            Assert.IsNotNull(fileRead);
            //---------------Execute Test ----------------------
            var @equals = fileRead.Equals(fileRead1);

            //---------------Test Result -----------------------
            Assert.IsTrue(equals);
        }
Example #3
0
 public bool ImpersonateForceDecrypt(string userName, string domain, string decryptIfEncrypted)
 {
     return(Impersonate(userName, domain, DpapiWrapper.DecryptIfEncrypted(decryptIfEncrypted)));
 }
Example #4
0
        /// <summary>
        /// Executes the specified errors.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <param name="update"></param>
        /// <returns></returns>
        public override Guid Execute(out ErrorResultTO errors, int update)
        {
            errors = new ErrorResultTO();
            ITestCatalog testCatalog = TstCatalog ?? TestCatalog.Instance;
            // WorkflowApplicationFactory wfFactor = new WorkflowApplicationFactory();
            Guid result = GlobalConstants.NullDataListID;


            Dev2Logger.Debug("Entered Wf Container");

            // Set Service Name
            DataObject.ServiceName = ServiceAction.ServiceName;

            // Set server ID, only if not set yet - original server;
            if (DataObject.ServerID == Guid.Empty)
            {
                DataObject.ServerID = HostSecurityProvider.Instance.ServerID;
            }

            // Set resource ID, only if not set yet - original resource;
            if (DataObject.ResourceID == Guid.Empty && ServiceAction?.Service != null)
            {
                DataObject.ResourceID = ServiceAction.Service.ID;
            }


            // Travis : Now set Data List
            DataObject.DataList = ServiceAction.DataListSpecification;
            // Set original instance ID, only if not set yet - original resource;
            if (DataObject.OriginalInstanceID == Guid.Empty)
            {
                DataObject.OriginalInstanceID = DataObject.DataListID;
            }
            Dev2Logger.Info($"Started Execution for Service Name:{DataObject.ServiceName} Resource Id:{DataObject.ResourceID} Mode:{(DataObject.IsDebug ? "Debug" : "Execute")}");
            //Set execution origin
            if (!string.IsNullOrWhiteSpace(DataObject.ParentServiceName))
            {
                DataObject.ExecutionOrigin            = ExecutionOrigin.Workflow;
                DataObject.ExecutionOriginDescription = DataObject.ParentServiceName;
            }
            else if (DataObject.IsDebug)
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.Debug;
            }
            else
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.External;
            }


            ErrorResultTO to = errors;
            var           serviceTestModelTo = testCatalog.FetchTest(DataObject.ResourceID, DataObject.TestName);

            if (serviceTestModelTo == null)
            {
                testCatalog.Load();
                serviceTestModelTo = testCatalog.FetchTest(DataObject.ResourceID, DataObject.TestName);
            }
            if (serviceTestModelTo == null)
            {
                Dev2JsonSerializer serializer = new Dev2JsonSerializer();
                var testRunResult             = new ServiceTestModelTO
                {
                    Result = new TestRunResult
                    {
                        TestName      = DataObject.TestName,
                        RunTestResult = RunResult.TestInvalid,
                        Message       = $"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID}, has been deleted."
                    }
                };
                Dev2Logger.Error($"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID}, has been deleted.");
                _request.ExecuteResult = serializer.SerializeToBuilder(testRunResult);
                return(Guid.NewGuid());
            }

            if (serviceTestModelTo.AuthenticationType == AuthenticationType.User)
            {
                Impersonator impersonator = new Impersonator();
                var          userName     = serviceTestModelTo.UserName;
                var          domain       = "";
                if (userName.Contains("\\"))
                {
                    var slashIndex = userName.IndexOf("\\", StringComparison.InvariantCultureIgnoreCase);
                    domain   = userName.Substring(0, slashIndex);
                    userName = userName.Substring(slashIndex + 1);
                }
                else if (userName.Contains("@"))
                {
                    var atIndex = userName.IndexOf("@", StringComparison.InvariantCultureIgnoreCase);
                    userName = userName.Substring(0, atIndex);
                    domain   = userName.Substring(atIndex + 1);
                }
                var hasImpersonated = impersonator.Impersonate(userName, domain, DpapiWrapper.DecryptIfEncrypted(serviceTestModelTo.Password));
                if (!hasImpersonated)
                {
                    DataObject.Environment.AllErrors.Add("Unauthorized to execute this resource.");
                    DataObject.StopExecution = true;
                }
            }
            else if (serviceTestModelTo.AuthenticationType == AuthenticationType.Public)
            {
                Thread.CurrentPrincipal = GlobalConstants.GenericPrincipal;
            }
            var userPrinciple = Thread.CurrentPrincipal;

            Common.Utilities.PerformActionInsideImpersonatedContext(userPrinciple, () =>
            {
                result = ExecuteWf(to, serviceTestModelTo);
            });
            if (DataObject.Environment.Errors != null)
            {
                foreach (var err in DataObject.Environment.Errors)
                {
                    errors.AddError(err, true);
                }
            }
            if (DataObject.Environment.AllErrors != null)
            {
                foreach (var err in DataObject.Environment.AllErrors)
                {
                    errors.AddError(err, true);
                }
            }

            Dev2Logger.Info($"Completed Execution for Service Name:{DataObject.ServiceName} Resource Id: {DataObject.ResourceID} Mode:{(DataObject.IsDebug ? "Debug" : "Execute")}");

            return(result);
        }
Example #5
0
        protected override ExecuteMessage ExecuteImpl(Dev2JsonSerializer serializer, Guid resourceId, Dictionary <string, StringBuilder> values)
        {
            var versionNumber = IsValid(values, out var environmentString, out var startActivityId, out var currentUserPrincipal);
            var executingUser = BuildClaimsPrincipal(DpapiWrapper.DecryptIfEncrypted(currentUserPrincipal.ToString()));
            var environment   = DpapiWrapper.DecryptIfEncrypted(environmentString.ToString());

            var decodedEnv   = HttpUtility.UrlDecode(environment);
            var executionEnv = new ExecutionEnvironment();

            executionEnv.FromJson(decodedEnv);

            Int32.TryParse(versionNumber.ToString(), out int parsedVersionNumber);

            var dataObject = new DsfDataObject("", Guid.NewGuid())
            {
                ResourceID    = resourceId,
                Environment   = executionEnv,
                VersionNumber = parsedVersionNumber,
                ExecutingUser = executingUser,
                IsDebug       = true
            };

            if (!CanExecute(dataObject))
            {
                var errorMessage = string.Format(ErrorResource.AuthenticationError, executingUser.Identity.Name);
                Dev2Logger.Error(errorMessage, GlobalConstants.WarewolfError);
                return(new ExecuteMessage {
                    HasError = true, Message = new StringBuilder(errorMessage)
                });
            }

            ResourceCatalogInstance.Reload();

            var dynamicService = ResourceCatalogInstance.GetService(GlobalConstants.ServerWorkspaceID, resourceId, "");

            if (dynamicService is null)
            {
                return(new ExecuteMessage {
                    HasError = true, Message = new StringBuilder($"Error resuming. ServiceAction is null for Resource ID:{resourceId}")
                });
            }

            var sa = dynamicService.Actions.FirstOrDefault();

            if (sa is null)
            {
                return(new ExecuteMessage {
                    HasError = true, Message = new StringBuilder($"Error resuming. ServiceAction is null for Resource ID:{resourceId}")
                });
            }

            var container = CustomContainer.Get <IResumableExecutionContainerFactory>()?.New(startActivityId, sa, dataObject) ?? CustomContainer.CreateInstance <IResumableExecutionContainer>(startActivityId, sa, dataObject);

            container.Execute(out ErrorResultTO errors, 0);

            if (errors.HasErrors())
            {
                return(new ExecuteMessage {
                    HasError = true, Message = new StringBuilder(errors.MakeDisplayReady())
                });
            }

            return(new ExecuteMessage {
                HasError = false, Message = new StringBuilder("Execution Completed.")
            });
        }