Пример #1
0
    public void Initialize(object config)
    {
        String configStr = YamlHelpers.Serialize(config);

        this.config = YamlHelpers.Deserialize <DaclRoles>(configStr);
        ProcessRoleConfig(this.config);
    }
Пример #2
0
        public void DecryptPlan(string planName)
        {
            string[] parts = new string[] {
                "Actions[0]:Parameters:Values:Arguments:ArgString",
                "Actions[0]:Parameters:Values:Arguments:Expressions[0]:Encoding",
                "Actions[0]:Parameters:Values:Arguments:Expressions[1]:ReplaceWith:foo:bar[1]:v1",
                "Actions[0]:Parameters:Values:Arguments:Expressions[2]:ReplaceWith:foo[1]:bar[1]:v3"
            };

            Plan   plan = Plan.FromYaml($"{__plansRoot}\\{planName}.yaml");
            object e    = YamlHelpers.SelectElements(plan, parts);

            Plan   crypto = plan.DecryptElements();
            object a      = YamlHelpers.SelectElements(crypto, parts);

            File.WriteAllText($"{__plansOut}\\{planName}_decr.yaml", crypto.ToYaml());

            List <object> exp = (List <object>)e;
            List <object> act = (List <object>)a;

            for (int i = 0; i < exp.Count; i++)
            {
                Assert.AreEqual(exp[i], act[i]);
            }
        }
Пример #3
0
        public static EnterpriseFileStore FromYamlFile(string path)
        {
            EnterpriseFileStore store = YamlHelpers.DeserializeFile <EnterpriseFileStore>(path, converter: new YamlAceConverter());

            store.CurrentPath = path;
            return(store);
        }
        public ParameterInfo GetCryptoValues(CryptoProvider planCrypto = null, bool isEncryptMode = true)
        {
            if (HasCrypto)
            {
                Crypto.InheritSettingsIfRequired(planCrypto);
            }

            switch (Type)
            {
            case SerializationType.Xml:
            {
                XmlDocument values = new XmlDocument();
                values.LoadXml(Values.ToString());
                ParameterInfo pi = XmlHelpers.GetCryptoValues(this, ref values, isEncryptMode);
                pi.Values = XmlHelpers.Serialize <string>(values);
                return(pi);
            }

            case SerializationType.Yaml:
            case SerializationType.Json:
            {
                return(YamlHelpers.GetCryptoValues(this, isEncryptMode));
            }

            case SerializationType.Unspecified:
            default:
            {
                return(this);
            }
            }
        }
    // Base Envelope for Generically Defined ActiveDirectory Searches
    private StartPlanEnvelope GetPlanEnvelope(AdSearchRequest request)
    {
        StartPlanEnvelope pe = new StartPlanEnvelope()
        {
            DynamicParameters = new Dictionary <string, string>()
        };

        pe.DynamicParameters.Add(@"filter", request.Filter);

        if (request.SearchBase != null)
        {
            pe.DynamicParameters.Add(@"searchbase", request.SearchBase);
        }

        if (request.ResultsFile != null)
        {
            pe.DynamicParameters.Add(@"resultsfile", request.ResultsFile);
        }

        string attributes = YamlHelpers.Serialize(request.ReturnAttributes, true, false);

        if (attributes != null)
        {
            pe.DynamicParameters.Add(@"attributes", attributes);
        }

        return(pe);
    }
Пример #6
0
        public void MergeParameters_ParentExitData(string planFile, string dynamicValue, string outFile)
        {
            // Arrange
            Plan plan = Plan.FromYaml($"{__plansRoot}\\{planFile}");

            Dictionary <string, string> dynamicData = new Dictionary <string, string>
            {
                { "ed", dynamicValue }
            };

            // Act
            plan.Start(dynamicData, true, true);

            // Assert
            string actual = YamlHelpers.Serialize(plan.ResultPlan.Actions[0].Actions[0]);

            actual = System.Text.RegularExpressions.Regex.Replace(actual, @"InstanceId: [\d]+", "InstanceId: 1");
            string expected = File.ReadAllText($"{__parms}\\{outFile}");

            Assert.AreEqual(expected, actual);

            if (outFile.Contains("xml"))
            {
                Assert.AreEqual(dynamicValue, ((System.Xml.XmlNode[])plan.ResultPlan.Actions[0].Actions[0].Result.ExitData)[0].OuterXml);
            }
        }
Пример #7
0
    public object FormatData(object data, ReturnFormat format)
    {
        switch (format)
        {
        case ReturnFormat.Yaml:
        {
            return(YamlHelpers.Deserialize(data.ToString()));
        }

        case ReturnFormat.Json:
        {
            return(YamlHelpers.Deserialize(data.ToString()));
        }

        case ReturnFormat.Xml:
        {
            return(XmlHelpers.Deserialize <XmlDocument>(data.ToString()));
        }

        default:
        {
            return(data);
        }
        }
    }
    T DeserializeYamlFile <T>(string path)
    {
        zf.AwsS3ZephyrFile file = new zf.AwsS3ZephyrFile(_awsClient, path);
        string             yaml = file.ReadAllText();

        return(YamlHelpers.Deserialize <T>(yaml));
    }
Пример #9
0
    public void ToYamlFile(string path = null, bool serializeAsJson = false)
    {
        if (string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(CurrentPath))
        {
            path = CurrentPath;
        }

        if (string.IsNullOrWhiteSpace(path))
        {
            throw new ArgumentException("path or CurrentPath must not be null.");
        }

        SuplexStore clone = new SuplexStore
        {
            Users           = Store.Users,
            Groups          = Store.Groups,
            GroupMembership = Store.GroupMembership
        };

        Store.SecureObjects.ShallowCloneTo(clone.SecureObjects);

        YamlHelpers.SerializeFile(path, clone,
                                  serializeAsJson: serializeAsJson, formatJson: serializeAsJson, emitDefaultValues: true, converter: new YamlAceConverter());

        CurrentPath = path;
    }
    void SerializeYamlFile(string path, object data, bool serializeAsJson = false, bool formatJson = true, bool emitDefaultValues = false)
    {
        string yaml = YamlHelpers.Serialize(data, serializeAsJson: serializeAsJson, formatJson: formatJson, emitDefaultValues: true);

        zf.AwsS3ZephyrFile file = new zf.AwsS3ZephyrFile(_awsClient, path);
        file.WriteAllText(yaml);
    }
    public void UpdatePlanActionStatus(ActionUpdateItem item)
    {
        try
        {
            Plan plan = GetPlanStatus(item.PlanUniqueName, item.PlanInstanceId);
            bool ok   = DalUtilities.FindActionAndReplace(plan.Actions, item.ActionItem);
            if (ok)
            {
                YamlHelpers.SerializeFile(Utilities.PathCombine(_histPath, $"{plan.UniqueName}_{plan.InstanceId}.yaml"), plan, emitDefaultValues: true);
            }
            else
            {
                throw new Exception($"Could not find Plan.InstanceId = [{item.PlanInstanceId}], Action:{item.ActionItem.Name}.ParentInstanceId = [{item.ActionItem.ParentInstanceId}] in Plan outfile.");
            }
        }
        catch (Exception ex)
        {
            ActionItemSingletonProcessor.Instance.Exceptions.Enqueue(ex);

            if (item.RetryAttempts++ < 5)
            {
                ActionItemSingletonProcessor.Instance.Queue.Enqueue(item);
            }
            else
            {
                ActionItemSingletonProcessor.Instance.Fatal.Enqueue(ex);
            }
        }
    }
    private void AddPropertiesToPlan(StartPlanEnvelope pe, Dictionary <String, List <String> > properties)
    {
        if (properties != null)
        {
            // Include Entire "Properties" Structure In Dynamic Parameter "properties"
            string propStr = YamlHelpers.Serialize(properties, true, false);
            pe.DynamicParameters.Add(@"properties", propStr);

            // Include Each Property In A Dynamic Parameter Matching The Name of the Property
            foreach (KeyValuePair <string, List <string> > property in properties)
            {
                if (property.Value?.Count > 0 && !(String.IsNullOrWhiteSpace(property.Key)))
                {
                    String pName = property.Key.ToLower();
                    if (pe.DynamicParameters.ContainsKey(pName))
                    {
                        continue;
                    }
                    string values = YamlHelpers.Serialize(property.Value, true, false);
                    String pValue = values;
                    pe.DynamicParameters.Add(pName, pValue);
                }
            }
        }
    }
    public void Configure(IAuthorizationProviderConfig conifg)
    {
        if (conifg != null)
        {
            int hash = conifg.Config.GetHashCode();
            if (!_cache.ContainsKey(hash) || _cache[hash] == null)
            {
                string s = YamlHelpers.Serialize(conifg.Config);
                _cache[hash] = YamlHelpers.Deserialize <WindowsPrincipalProvider>(s);
            }

            Configure(_cache[hash]);

            //if external source declared, merge contents
            if (!string.IsNullOrWhiteSpace(ListSourcePath) && File.Exists(ListSourcePath))
            {
                DateTime lastWriteTime = File.GetLastWriteTimeUtc(ListSourcePath);
                if (!lastWriteTime.Equals(ListSourceLastWriteTime))
                {
                    string s = YamlHelpers.Serialize(conifg.Config);
                    WindowsPrincipalProvider p = YamlHelpers.Deserialize <WindowsPrincipalProvider>(s);
                    Configure(p, lastWriteTime);


                    WindowsPrincipalProvider listSource = YamlHelpers.DeserializeFile <WindowsPrincipalProvider>(ListSourcePath);

                    if (listSource.HasUsers)
                    {
                        EnsureUsersGroups(isUsers: true);

                        if (listSource.Users.HasAllowed)
                        {
                            Users.Allowed.AddRange(listSource.Users.Allowed);
                        }

                        if (listSource.Users.HasDenied)
                        {
                            Users.Denied.AddRange(listSource.Users.Denied);
                        }
                    }
                    if (listSource.HasGroups)
                    {
                        EnsureUsersGroups(isUsers: false);

                        if (listSource.Groups.HasAllowed)
                        {
                            Groups.Allowed.AddRange(listSource.Groups.Allowed);
                        }

                        if (listSource.Groups.HasDenied)
                        {
                            Groups.Denied.AddRange(listSource.Groups.Denied);
                        }
                    }

                    _cache[hash] = this;
                }
            }
        }
    }
        public static String Serialize <T>(object obj)
        {
            String str = String.Empty;

            if (obj.GetType() == typeof(XmlNode[]))
            {
                StringBuilder sb   = new StringBuilder();
                String        type = typeof(T).Name;
                sb.Append("<" + type + ">");
                XmlNode[] nodes = (XmlNode[])obj;
                foreach (XmlNode node in nodes)
                {
                    sb.Append(node.OuterXml);
                }
                sb.Append("</" + type + ">");
                str = sb.ToString();
            }
            else if (obj.GetType() == typeof(Dictionary <object, object>))
            {
                str = YamlHelpers.Serialize(obj);
            }
            else
            {
                str = obj.ToString();
            }

            return(str);
        }
Пример #15
0
    public void Configure(object config)
    {
        string yaml = YamlHelpers.Serialize(config);
        FileSystemDalConfig fileSystemDalConfig = YamlHelpers.Deserialize <FileSystemDalConfig>(yaml);

        Configure(fileSystemDalConfig);
    }
        public static T Deserialize <T>(String str)
        {
            T obj;

            if (str.Trim().StartsWith("<"))
            {
                try
                {
                    obj = XmlHelpers.Deserialize <T>(new StringReader(str));
                }
                catch (Exception e)
                {
                    // Check Edge Case Of Yaml Document Starting With A "<" Character
                    try
                    {
                        obj = YamlHelpers.Deserialize <T>(new StringReader(str));
                    }
                    catch (Exception)
                    {
                        throw e;
                    }
                }
            }
            else
            {
                obj = YamlHelpers.Deserialize <T>(new StringReader(str));
            }

            return(obj);
        }
Пример #17
0
        public Plan GetPlan(string planUniqueName)
        {
            //todo: this is temporary only, switch to mongo impl
            string planFile = $"{CurrentPath}\\Plans\\{planUniqueName}.yaml";

            return(YamlHelpers.DeserializeFile <Plan>(planFile));
        }
    private ActiveDirectoryHandlerResults CallPlan(string planName, StartPlanEnvelope planEnvelope)
    {
        IExecuteController ec = GetExecuteControllerInstance();
        StartPlanEnvelope  pe = planEnvelope;

        if (pe == null)
        {
            pe = new StartPlanEnvelope()
            {
                DynamicParameters = new Dictionary <string, string>()
            }
        }
        ;

        IEnumerable <KeyValuePair <string, string> > queryString = this.Request.GetQueryNameValuePairs();

        foreach (KeyValuePair <string, string> kvp in queryString)
        {
            pe.DynamicParameters.Add(kvp.Key, kvp.Value);
        }

        object reply = ec.StartPlanSync(pe, planName, setContentType: false);
        ActiveDirectoryHandlerResults result = null;
        Type replyType = reply.GetType();

        if (replyType == typeof(string))
        {
            try
            {
                result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>((string)reply);
            }
            catch (Exception e)
            {
                try
                {
                    // Reply was not Json or Yaml.  See if Xml
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml((string)reply);
                    result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
                }
                catch (Exception)
                {
                    throw e;
                }
            }
        }
        else if (replyType == typeof(Dictionary <object, object>))
        {
            String str = YamlHelpers.Serialize(reply);
            result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(str);
        }
        else if (replyType == typeof(XmlDocument))
        {
            XmlDocument doc = (XmlDocument)reply;
            result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
        }

        return(result);
    }
 public SecurityContext GetCryptoValues(CryptoProvider planCrypto = null, bool isEncryptMode = true)
 {
     if (HasCrypto)
     {
         Crypto.InheritSettingsIfRequired(planCrypto);
     }
     return(YamlHelpers.GetCryptoValues(this, isEncryptMode));
 }
    public Plan GetPlan(string planUniqueName)
    {
        //_splxDal?.TrySecurityOrException( securityContext, planUniqueName, AceType.FileSystem, FileSystemRight.Execute, "Plan" );

        string planFile = Utilities.PathCombine(_planPath, $"{planUniqueName}.yaml");

        return(YamlHelpers.DeserializeFile <Plan>(planFile));
    }
Пример #21
0
 public static FileSystemDal LoadFromYaml(string yaml)
 {
     return(new FileSystemDal
     {
         Store = YamlHelpers.Deserialize <SuplexStore>(yaml, converter: new YamlAceConverter()),
         CurrentPath = null
     });
 }
Пример #22
0
        public static ActiveDirectoryHandlerResults CallPlan(string planName, Dictionary <string, string> dynamicParameters = null)
        {
            object output = CallRawPlan(planName, dynamicParameters);
            ActiveDirectoryHandlerResults result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(output.ToString());

            Console.WriteLine(YamlHelpers.Serialize(result));
            return(result);
        }
Пример #23
0
 public static FileSystemDal LoadFromYamlFile(string path)
 {
     return(new FileSystemDal
     {
         Store = YamlHelpers.DeserializeFile <SuplexStore>(path, converter: new YamlAceConverter()),
         CurrentPath = path
     });
 }
Пример #24
0
    public static ActiveDirectoryApiConfig Deserialze()
    {
        if (!File.Exists(FileName))
        {
            throw new FileNotFoundException($"Could not find {FileName}");
        }

        return(YamlHelpers.DeserializeFile <ActiveDirectoryApiConfig>(FileName));
    }
        public static HandlerConfig Deserialze()
        {
            if (!File.Exists(FileName))
            {
                throw new FileNotFoundException($"Could not find {FileName}.");
            }

            return(YamlHelpers.DeserializeFile <HandlerConfig>(FileName));
        }
Пример #26
0
        public static StartPlanEnvelope FromYaml(string yaml, bool isEncoded = false)
        {
            if (isEncoded)
            {
                yaml = CryptoHelpers.Decode(yaml);
            }

            return(YamlHelpers.Deserialize <StartPlanEnvelope>(yaml, ignoreUnmatchedProperties: false));
        }
Пример #27
0
    public static ActiveDirectoryApiConfig DeserializeOrNew()
    {
        ActiveDirectoryApiConfig config = null;

        if (!File.Exists(FileName))
        {
            config = new ActiveDirectoryApiConfig();

            config.Plans.User.Get              = @"GetUser";
            config.Plans.User.Create           = @"CreateUser";
            config.Plans.User.Delete           = @"DeleteUser";
            config.Plans.User.Modify           = @"ModifyUser";
            config.Plans.User.AddToGroup       = @"AddUserToGroup";
            config.Plans.User.RemoveFromGroup  = @"RemoveUserFromGroup";
            config.Plans.User.AddAccessRule    = @"AddAccessRuleToUser";
            config.Plans.User.RemoveAccessRule = @"RemoveAccessRuleFromUser";
            config.Plans.User.SetAccessRule    = @"SetAccessRuleOnUser";
            config.Plans.User.PurgeAccessRules = @"PurgeAccessRulesOnUser";
            config.Plans.User.AddRole          = @"AddRoleToUser";
            config.Plans.User.RemoveRole       = @"RemoveRoleFromUser";

            config.Plans.Group.Get              = @"GetGroup";
            config.Plans.Group.Create           = @"CreateGroup";
            config.Plans.Group.Delete           = @"DeleteGroup";
            config.Plans.Group.Modify           = @"ModifyGroup";
            config.Plans.Group.AddToGroup       = @"AddGroupToGroup";
            config.Plans.Group.RemoveFromGroup  = @"RemoveGroupFromGroup";
            config.Plans.Group.AddAccessRule    = @"AddAccessRuleToGroup";
            config.Plans.Group.RemoveAccessRule = @"RemoveAccessRuleFromGroup";
            config.Plans.Group.SetAccessRule    = @"SetAccessRuleOnGroup";
            config.Plans.Group.PurgeAccessRules = @"PurgeAccessRulesOnGroup";
            config.Plans.Group.AddRole          = @"AddRoleToGroup";
            config.Plans.Group.RemoveRole       = @"RemoveRoleFromGroup";

            config.Plans.OrganizationalUnit.Get              = @"GetOrgUnit";
            config.Plans.OrganizationalUnit.Create           = @"CreateOrgUnit";
            config.Plans.OrganizationalUnit.Delete           = @"DeleteOrgUnit";
            config.Plans.OrganizationalUnit.Modify           = @"ModifyOrgUnit";
            config.Plans.OrganizationalUnit.AddAccessRule    = @"AddAccessRuleToOrgUnit";
            config.Plans.OrganizationalUnit.RemoveAccessRule = @"RemoveAccessRuleFromOrgUnit";
            config.Plans.OrganizationalUnit.SetAccessRule    = @"SetAccessRuleOnOrgUnit";
            config.Plans.OrganizationalUnit.PurgeAccessRules = @"PurgeAccessRulesOnOrgUnit";
            config.Plans.OrganizationalUnit.AddRole          = @"AddRoleToOrgUnit";
            config.Plans.OrganizationalUnit.RemoveRole       = @"RemoveRoleFromOrgUnit";

            config.Plans.Search = @"Search";

            config.Serialize();
        }
        else
        {
            config = YamlHelpers.DeserializeFile <ActiveDirectoryApiConfig>(FileName);
        }

        return(config);
    }
Пример #28
0
    public Dictionary <string, string> Configure(ISynapseDalConfig conifg)
    {
        if (conifg != null && conifg.Config != null)
        {
            string       s    = YamlHelpers.Serialize(conifg.Config);
            UriDalConfig fsds = YamlHelpers.Deserialize <UriDalConfig>(s);

            _planPath = fsds.PlanFolderPath;
            _histPath = fsds.HistoryFolderPath;
            _splxPath = fsds.Security.FilePath;

            EnsurePaths();

            ProcessPlansOnSingleton   = fsds.ProcessPlansOnSingleton;
            ProcessActionsOnSingleton = fsds.ProcessActionsOnSingleton;

            LoadSuplex();

            if (fsds.CloudPlatform == CloudPlatform.Azure)
            {
                AzureUriDalConfig azureConfig = YamlHelpers.Deserialize <AzureUriDalConfig>(s);
                cloudUriHandler = new AzureCloudUriHandler(azureConfig);
            }
            else
            {
                AWSUriDalConfig awsConfig = YamlHelpers.Deserialize <AWSUriDalConfig>(s);
                cloudUriHandler = new AWSCloudUriHandler(awsConfig);
            }
            EncryptionHelper.Configure(fsds);

            if (_splxDal == null && fsds.Security.IsRequired)
            {
                throw new Exception($"Security is required.  Could not load security file: {_splxPath}.");
            }

            if (_splxDal != null)
            {
                _splxDal.LdapRoot = conifg.LdapRoot;
                _splxDal.GlobalExternalGroupsCsv = fsds.Security.GlobalExternalGroupsCsv;
            }
        }
        else
        {
            ConfigureDefaults();
        }

        Dictionary <string, string> props = new Dictionary <string, string>();
        string name = nameof(UriDal);

        props.Add(name, CurrentPath);
        props.Add($"{name} Plan path", _planPath);
        props.Add($"{name} History path", _histPath);
        props.Add($"{name} Security path", _splxPath);
        return(props);
    }
Пример #29
0
 public static SuplexMru Deserialize()
 {
     if (File.Exists(FileName))
     {
         return(YamlHelpers.DeserializeFile <SuplexMru>(FileName));
     }
     else
     {
         return(new SuplexMru());
     }
 }
Пример #30
0
        private void ReadComponent(YamlMappingNode mapping)
        {
            // TODO: nonexistant component types are not checked here.
            var type = ((YamlScalarNode)mapping[new YamlScalarNode("type")]).Value;
            Dictionary <string, YamlNode> dict = YamlHelpers.YamlMappingToDict(mapping);

            dict.Remove("type");

            components[type] = dict;
            // TODO: figure out a better way to exclude the type node.
        }