GetUserNameProp() публичный статический Метод

public static GetUserNameProp ( List propMappings ) : string
propMappings List
Результат string
Пример #1
0
        public static bool SyncVirtualUserFromAD(string adPath, string username, User virtualUser, List <PropertyMapping> propertyMappings, string customADAdminAccountName, string customADAdminAccountPwd, bool novellSupport, string guidProp, bool syncUserName)
        {
            bool success = false;

            try
            {
                using (var serverEntry = ConnectToAD(adPath, customADAdminAccountName, customADAdminAccountPwd, novellSupport, guidProp))
                {
                    var filter = string.Format("({0}={1})", SyncConfiguration.GetUserNameProp(propertyMappings), username);
                    using (var entry = SearchADObject(serverEntry, filter, novellSupport, guidProp))
                    {
                        if (entry != null)
                        {
                            UpdatePortalUserCustomProperties(entry, virtualUser, propertyMappings, syncUserName);

                            var guid = Common.GetADObjectGuid(entry, guidProp);
                            if (guid.HasValue)
                            {
                                virtualUser["SyncGuid"] = ((Guid)guid).ToString();
                                success = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }
            return(success);
        }
Пример #2
0
        public static void UpdateADUserCustomProperties(DirectoryEntry entry, Node user, List <PropertyMapping> propertyMappings, bool enabled, int ADsAMAccountNameMaxLength, bool syncEnabledState, bool syncUserName)
        {
            if (syncEnabledState)
            {
                if (enabled)
                {
                    Common.EnableUserAccount(entry);
                }
                else
                {
                    Common.DisableUserAccount(entry);
                }
            }

            // Name -> sAMAccountName
            if (syncUserName)
            {
                entry.Properties[SyncConfiguration.GetUserNameProp(propertyMappings)].Value = user.Name.MaximizeLength(ADsAMAccountNameMaxLength);
            }

            foreach (PropertyMapping propMapping in propertyMappings)
            {
                if (propMapping.ADProperties.Count == 1)
                {
                    if (propMapping.PortalProperties.Count == 1)
                    {
                        // 1 ADproperty + 1 portalproperty
                        var adProp      = propMapping.ADProperties[0];
                        var portalProp  = propMapping.PortalProperties[0];
                        var portalValue = GetNodeValue(user, portalProp);
                        SetEntryValue(entry, adProp, portalValue);
                    }
                    else
                    {
                        // 1 ADproperty + more portalproperty
                        var adProp      = propMapping.ADProperties[0];
                        var portalValue = propMapping.ConcatPortalPropValues(user);
                        SetEntryValue(entry, adProp, portalValue);
                    }
                }
                else
                {
                    // 1 portalproperty + more ADproperty
                    var portalProp = propMapping.PortalProperties[0];
                    var propValue  = GetNodeValue(user, portalProp);
                    if (propValue == null)
                    {
                        propValue = string.Empty;
                    }
                    var portalValues = propValue.Split(new string[] { propMapping.Separator }, StringSplitOptions.None);
                    int index        = 0;
                    foreach (SyncProperty adProp in propMapping.ADProperties)
                    {
                        var portalValue = (index < portalValues.Length) ? portalValues[index] : null;
                        SetEntryValue(entry, adProp, portalValue);
                        index++;
                    }
                }
            }
        }
Пример #3
0
        public static void UpdatePortalUserCustomProperties(DirectoryEntry entry, Node node, List <PropertyMapping> propertyMappings, bool syncUserName)
        {
            // sAMAccountName -> Name
            if (syncUserName)
            {
                node.Name = entry.Properties[SyncConfiguration.GetUserNameProp(propertyMappings)].Value.ToString();

                // in case of AD users the content name and login name are the same
                var user = node as User;
                if (user != null)
                {
                    user.LoginName = user.Name;
                }
            }

            // user actions
            foreach (PropertyMapping propMapping in propertyMappings)
            {
                if (propMapping.ADProperties.Count == 1)
                {
                    if (propMapping.PortalProperties.Count == 1)
                    {
                        // 1 ADproperty + 1 portalproperty
                        var portalProp = propMapping.PortalProperties[0];
                        var adProp     = propMapping.ADProperties[0];
                        var adValue    = GetEntryValue(entry, adProp);
                        SetNodeValue(node, portalProp, adValue);
                    }
                    else
                    {
                        // 1 ADproperty + more portalproperty
                        // slice the AD property (with empties) and set portal properties controlled by propertyMapping
                        var adProp   = propMapping.ADProperties[0];
                        var adValues = GetEntryValue(entry, adProp).Split(new string[] { propMapping.Separator }, StringSplitOptions.None);
                        int index    = 0;
                        foreach (SyncProperty portalProp in propMapping.PortalProperties)
                        {
                            var adValue = (index < adValues.Length) ? adValues[index] : null;
                            SetNodeValue(node, portalProp, adValue);
                            index++;
                        }
                    }
                }
                else
                {
                    // 1 portalproperty + more ADproperty
                    // concatenate the AD properties and set the portal property
                    var portalProp = propMapping.PortalProperties[0];
                    var adValue    = propMapping.ConcatADPropValues(entry);
                    SetNodeValue(node, portalProp, adValue);
                }
            }
        }
Пример #4
0
        public static void UpdatePortalUserCustomProperties(DirectoryEntry entry, Node node, List <PropertyMapping> propertyMappings, bool syncUserName)
        {
            var user = (IUser)node;

            // sAMAccountName -> Name
            if (syncUserName)
            {
                node.Name = entry.Properties[SyncConfiguration.GetUserNameProp(propertyMappings)].Value.ToString();
            }

            // user actions
            foreach (PropertyMapping propMapping in propertyMappings)
            {
                if (propMapping.ADProperties.Count == 1)
                {
                    if (propMapping.PortalProperties.Count == 1)
                    {
                        // 1db ADproperty + 1db portalproperty
                        var portalProp = propMapping.PortalProperties[0];
                        var adProp     = propMapping.ADProperties[0];
                        var adValue    = GetEntryValue(entry, adProp);
                        SetNodeValue(node, portalProp, adValue);
                    }
                    else
                    {
                        // 1db ADproperty + xdb portalproperty
                        // az AD propertyt felvágjuk az elválasztók mentén (üreseket is meghagyjuk), majd
                        // ezek kerülnek be sorrendben a portal propertykbe
                        var adProp   = propMapping.ADProperties[0];
                        var adValues = GetEntryValue(entry, adProp).Split(new string[] { propMapping.Separator }, StringSplitOptions.None);
                        int index    = 0;
                        foreach (SyncProperty portalProp in propMapping.PortalProperties)
                        {
                            var adValue = (index < adValues.Length) ? adValues[index] : null;
                            SetNodeValue(node, portalProp, adValue);
                            index++;
                        }
                    }
                }
                else
                {
                    // 1db portalproperty + xdb ADproperty
                    // az AD propertyk értékét összefűzzük egy stringbe, majd beadjuk a portalpropertynek
                    var portalProp = propMapping.PortalProperties[0];
                    var adValue    = propMapping.ConcatADPropValues(entry);
                    SetNodeValue(node, portalProp, adValue);
                }
            }
        }
Пример #5
0
        public static void DisableADObjectCustomProperties(DirectoryEntry entry, List <PropertyMapping> propertyMappings, int ADNameMaxLength, int ADsAMAccountNameMaxLength)
        {
            // entry.name
            var deletedEntryName = GetADObjectName(entry.Name).PrefixDeleted();
            var newName          = string.Concat(GetADObjectPrefix(ADObjectType.User), deletedEntryName.MaximizeLength(ADNameMaxLength));

            entry.Rename(newName);

            // sAMAccountName
            entry.Properties[SyncConfiguration.GetUserNameProp(propertyMappings)].Value = deletedEntryName.MaximizeLength(ADsAMAccountNameMaxLength);

            foreach (PropertyMapping propMapping in propertyMappings)
            {
                foreach (SyncProperty adProp in propMapping.ADProperties)
                {
                    if (adProp.Unique)
                    {
                        var propValue = GetEntryValue(entry, adProp).PrefixDeleted();
                        SetEntryValue(entry, adProp, propValue);
                    }
                }
            }
        }