ConnectToObject() публичный Метод

public ConnectToObject ( string objectPath ) : System.DirectoryServices.DirectoryEntry
objectPath string
Результат System.DirectoryServices.DirectoryEntry
Пример #1
0
        private void CreateADUser(SyncTree syncTree, string parentADPath, User user, string passwd)
        {
            using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
            {
                var prefix   = Common.GetADObjectPrefix(ADObjectType.User);
                var userName = user.Name.MaximizeLength(_config.ADNameMaxLength);
                using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, userName), "user"))
                {
                    newObj.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_DONT_EXPIRE_PASSWD;

                    // user actions

                    var enabled = ((!_createdUsersDisabled) && (user.Enabled));

                    Common.UpdateADUserCustomProperties(newObj, user, _propertyMappings, enabled, _config.ADsAMAccountNameMaxLength, _config.SyncEnabledState, _config.SyncUserName);

                    newObj.CommitChanges();

                    // set password
                    if (passwd != null)
                    {
                        Common.SetPassword(newObj, passwd);
                    }

                    Common.SetPortalObjectGuid(newObj, user, _config.GuidProp);
                }
            }
        }
Пример #2
0
 private void CreateADContainer(SyncTree syncTree, string parentADPath, Node node)
 {
     using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
     {
         var prefix = Common.GetADObjectPrefix(ADObjectType.Container);
         using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, node.Name), "container"))
         {
             newObj.CommitChanges();
             Common.SetPortalObjectGuid(newObj, node, _config.GuidProp);
         }
     }
 }
Пример #3
0
 private void CreateADGroup(SyncTree syncTree, string parentADPath, Node node)
 {
     using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
     {
         var prefix = Common.GetADObjectPrefix(ADObjectType.Group);
         using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, node.Name), "group"))
         {
             newObj.Properties["sAMAccountName"].Value = node.Name.MaximizeLength(_config.ADsAMAccountNameMaxLength);
             newObj.Properties["groupType"].Value      = ADGroupOptions.GlobalSecurityGroup;
             newObj.CommitChanges();
             Common.SetPortalObjectGuid(newObj, node, _config.GuidProp);
         }
     }
 }
Пример #4
0
        // adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local
        // portalParentPath: "/Root/IMS/Nativ.Local/ExampleOrg"
        private void EnsurePortalPath(SyncTree syncTree, string ADPath, string portalParentPath)
        {
            // portalParentPath does not exist
            if (!Node.Exists(portalParentPath))
            {
                // get parent AD object
                string ADparentPath = syncTree.GetADParentObjectPath(ADPath);
                // ensurepath
                EnsurePortalPath(syncTree, ADparentPath, RepositoryPath.GetParentPath(portalParentPath));
            }

            // portalParentPath exists, so AD object should be synchronized here
            // domain, container, orgunit
            using (DirectoryEntry entry = syncTree.ConnectToObject(ADPath))
            {
                var guid = Common.GetADObjectGuid(entry, _config.GuidProp);
                if (!guid.HasValue)
                {
                    return;
                }

                SyncOneADObject(null, entry, (Guid)guid, ADObjectType.AllContainers, portalParentPath, CreateNewPortalContainer, UpdatePortalContainerProperties, syncTree);
            }
        }
Пример #5
0
        // adpath: OU=OtherOrg,OU=ExampleOrg,DC=Nativ,DC=local
        // portalParentPath: "/Root/IMS/Nativ.Local/ExampleOrg"
        private void EnsurePortalPath(SyncTree syncTree, string ADPath, string portalParentPath)
        {
            // portalParentPath does not exist
            if (!Node.Exists(portalParentPath))
            {
                // get parent AD object
                string ADparentPath = syncTree.GetADParentObjectPath(ADPath);
                // ensurepath
                EnsurePortalPath(syncTree, ADparentPath, RepositoryPath.GetParentPath(portalParentPath));
            }

            // portalParentPath exists, so AD object should be synchronized here
            // domain, container, orgunit
            using (DirectoryEntry entry = syncTree.ConnectToObject(ADPath))
            {
                var guid = Common.GetADObjectGuid(entry, _config.GuidProp);
                if (!guid.HasValue)
                    return;

                SyncOneADObject(null, entry, (Guid)guid, ADObjectType.AllContainers, portalParentPath, CreateNewPortalContainer, UpdatePortalContainerProperties, syncTree);
            }
        }
Пример #6
0
 private void CreateADContainer(SyncTree syncTree, string parentADPath, Node node)
 {
     using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
     {
         var prefix = Common.GetADObjectPrefix(ADObjectType.Container);
         using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, node.Name), "container"))
         {
             newObj.CommitChanges();
             Common.SetPortalObjectGuid(newObj, node, _config.GuidProp);
         }
     }
 }
Пример #7
0
 private void CreateADGroup(SyncTree syncTree, string parentADPath, Node node)
 {
     using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
     {
         var prefix = Common.GetADObjectPrefix(ADObjectType.Group);
         using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, node.Name), "group"))
         {
             // a members.clear után nem engedné létrehozni constraint miatt
             //UpdateADGroupCustomProperies(newObj, node);
             newObj.Properties["sAMAccountName"].Value = node.Name.MaximizeLength(_config.ADsAMAccountNameMaxLength);
             newObj.Properties["groupType"].Value = ADGroupOptions.GlobalSecurityGroup;
             newObj.CommitChanges();
             Common.SetPortalObjectGuid(newObj, node, _config.GuidProp);
         }
     }
 }
Пример #8
0
        private void CreateADUser(SyncTree syncTree, string parentADPath, User user, string passwd)
        {
            using (DirectoryEntry parentObj = syncTree.ConnectToObject(parentADPath))
            {
                var prefix = Common.GetADObjectPrefix(ADObjectType.User);
                var userName = user.Name.MaximizeLength(_config.ADNameMaxLength);
                using (DirectoryEntry newObj = parentObj.Children.Add(String.Concat(prefix, userName), "user"))
                {
                    newObj.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_DONT_EXPIRE_PASSWD;

                    // user actions

                    // user enabled/disabled: akkor enabled, ha a user maga enabled és globálisan nincs letiltva az enabled állapot konfigban
                    var enabled = ((!_createdUsersDisabled) && (user.Enabled));

                    Common.UpdateADUserCustomProperties(newObj, user, _propertyMappings, enabled, _config.ADsAMAccountNameMaxLength, _config.SyncEnabledState, _config.SyncUserName);

                    newObj.CommitChanges();

                    //if (doNotExpirePassword)
                    //{
                    //    oNewADUser.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT | ADAccountOptions.UF_DONT_EXPIRE_PASSWD;
                    //}
                    //else
                    //{
                    //    oNewADUser.Properties["userAccountControl"].Value = ADAccountOptions.UF_NORMAL_ACCOUNT;
                    //}
                    
                    // set password
                    if (passwd != null)
                        Common.SetPassword(newObj, passwd);

                    Common.SetPortalObjectGuid(newObj, user, _config.GuidProp);
                }
            }
        }