Beispiel #1
0
        public LdapChangeResult ChangeObjectAttribute(string distinguishedName, string attributeName, object value, IEnumerable <AttributeInfo> allowedAttributes)
        {
            var attributeNames = new string[] { attributeName };
            var obj            = GetObjectByDn(distinguishedName, attributeNames);

            if (obj == null)
            {
                throw new ActiveDirectoryObjectNotFoundException();
            }



            var changer = new LdapObjectChangeBuilder(this, distinguishedName, allowedAttributes)
                          .AddModification(attributeName, value);


            var result = changer.SendChangedModifications();

            var oldJson = JObject.Parse(JsonConvert.SerializeObject(obj.Properties));
            var nobj    = GetObjectByDn(result.DistinguishedName, attributeNames);
            var newJson = JObject.Parse(JsonConvert.SerializeObject(nobj.Properties));


            foreach (var jProperty in newJson.Properties())
            {
                var n = jProperty.Name;
                if (oldJson.ContainsKey(n))
                {
                    if (newJson[n]?.ToString() != oldJson[n]?.ToString())
                    {
                        result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Changed, nobj.GetPropertyOrNull(n), obj.GetPropertyOrNull(n)));
                    }
                }
                else
                {
                    result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Added, nobj[n], null));
                }
            }

            foreach (var jProperty in oldJson.Properties())
            {
                var n = jProperty.Name;
                if (!newJson.ContainsKey(n))
                {
                    result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Removed, null, obj[n]));
                }
            }

            return(result);
        }
Beispiel #2
0
        public LdapChangeResult ChangeObjectAttributes(string distinguishedName, JObject attributes, IEnumerable <AttributeInfo> allowedAttributes)
        {
            var attributeNames = attributes.Properties().Select(p => p.Name).ToArray();
            var obj            = GetObjectByDn(distinguishedName, attributeNames);

            if (obj == null)
            {
                throw new Exception("Ldap Object not found");
            }

            var changer = new LdapObjectChangeBuilder(this, distinguishedName, allowedAttributes).AddModifications(attributes);

            var result = changer.SendChangedModifications();

            var oldJson = JObject.Parse(JsonConvert.SerializeObject(obj));
            var nobj    = GetObjectByDn(result.DistinguishedName, attributeNames);
            var newJson = JObject.Parse(JsonConvert.SerializeObject(nobj));


            foreach (var jProperty in newJson.Properties())
            {
                var n = jProperty.Name;
                if (oldJson.ContainsKey(n))
                {
                    if (newJson[n]?.ToString() != oldJson[n]?.ToString())
                    {
                        result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Changed, nobj.GetValueOrDefault(n), obj.GetValueOrDefault(n)));
                    }
                }
                else
                {
                    result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Added, nobj[n], null));
                }
            }

            foreach (var jProperty in oldJson.Properties())
            {
                var n = jProperty.Name;
                if (!newJson.ContainsKey(n))
                {
                    result.Modifications.Add(new ChangedAttributeInformation(n, ChangedAttributeType.Removed, null, obj[n]));
                }
            }

            return(result);
        }