示例#1
0
        public void MergeACL(ACLRoot resourceAcl)
        {
            if (resourceAcl.Groups != null)
            {
                foreach (var group in resourceAcl.Groups)
                {
                    if (_mainAcl.Groups.Any(grp => grp.Name == group.Name))
                    {
                        var ourGrp = _mainAcl.Groups.First(grp => grp.Name == group.Name);

                        foreach (var right in group.ACLRights)
                        {
                            if (!ourGrp.ACLRights.Any(r => r.Name == right.Name))
                            {
                                ourGrp.ACLRights.Add(right);
                            }
                        }

                        /* // Disabled for security measures
                         * foreach ( var obj in group.Objects)
                         * {
                         *  if (!ourGrp.Objects.Any(o => o.Name == obj.Name))
                         *      ourGrp.Objects.Add(obj);
                         * }*/
                    }
                    else
                    {
                        _mainAcl.Groups.Add(group);
                    }
                }
            }

            if (resourceAcl.RightLists != null)
            {
                foreach (var rights in resourceAcl.RightLists)
                {
                    if (_mainAcl.RightLists.Any(r => r.Name == rights.Name))
                    {
                        var ourList = _mainAcl.RightLists.First(r => r.Name == rights.Name);
                        foreach (var right in rights.Rights)
                        {
                            if (!ourList.Rights.Any(r => r.Name == right.Name))
                            {
                                ourList.Rights.Add(right);
                            }
                        }
                    }
                    else
                    {
                        _mainAcl.RightLists.Add(rights);
                    }
                }
            }
        }
示例#2
0
        public void LoadACL()
        {
            _mainAcl = ParseXml(_filepath);

            foreach (var aclGroup in _mainAcl.Groups)
            {
                foreach (var obj in aclGroup.Objects)
                {
                    if (!string.IsNullOrWhiteSpace(obj.Password) && obj.Password.Length != 64)
                    {
                        obj.Password = Program.GetHashSHA256(obj.Password);
                    }
                }
            }

            SaveXml(_filepath, _mainAcl);
        }
示例#3
0
        public static void SaveXml(string path, ACLRoot root)
        {
            var ser = new XmlSerializer(typeof(ACLRoot));

            using (var stream = new FileStream(path, FileMode.Truncate)) ser.Serialize(stream, root);
        }