private void CreateUsersAndGroups(LDAPSupportSettings settings) { Status = Resource.LdapSettingsStatusGettingGroupsFromLdap; var groups = _importer.GetDiscoveredGroupsByAttributes(settings); Percentage = 8; Status = Resource.LdapSettingsStatusGettingUsersFromLdap; var users = _importer.GetDiscoveredUsersByAttributes(settings); Percentage = 15; Status = Resource.LdapSettingsStatusSavingGroups; AddGroupsToCore(groups); Percentage = 35; Status = Resource.LdapSettingsStatusSavingUsers; double percents = 35; var step = percents / users.Count; if (users != null && users.Count != 0) { for (int i = 0; i < users.Count; i++) { if (users[i].FirstName == string.Empty) { users[i].FirstName = Resource.FirstName; } if (users[i].LastName == string.Empty) { users[i].LastName = Resource.LastName; } } users = users.SortByUserName(); for (int i = 0; i < users.Count; i++) { if (TenantStatisticsProvider.GetUsersCount() < TenantExtra.GetTenantQuota().ActiveUsers) { users[i] = UserManagerWrapper.AddUser(users[i], UserManagerWrapper.GeneratePassword(), true, false); } else { users[i] = UserManagerWrapper.AddUser(users[i], UserManagerWrapper.GeneratePassword(), true, false, true); } Percentage += step; } } Percentage = 70; var allLdapUsers = CoreContext.UserManager.GetUsers().Where(u => u.Sid != null).ToArray(); percents = 20; step = percents / allLdapUsers.Length; for (int i = 0; i < allLdapUsers.Length; i++) { _importer.AddUserIntoGroups(allLdapUsers[i], settings); Percentage += step; } Percentage = 90; AddUsersInCacheGroups(); RemoveEmptyGroups(); }
private void SyncLDAPUsers() { SetProggressInfo(Constants.LDAP_SETTING_TASK_PERCENTAGE, 15); SetProggressInfo(Constants.LDAP_SETTING_TASK_STATUS, Resource.LdapSettingsStatusGettingUsersFromLdap); var ldapUsers = _importer.GetDiscoveredUsersByAttributes() .ConvertAll(u => { if (u.FirstName == string.Empty) { u.FirstName = Resource.FirstName; } if (u.LastName == string.Empty) { u.LastName = Resource.LastName; } return(u); }) .SortByUserName() .ToList(); if (!ldapUsers.Any()) { SetProggressInfo(Constants.LDAP_SETTING_TASK_ERROR, Resource.LdapSettingsErrorUsersNotFound); return; } SetProggressInfo(Constants.LDAP_SETTING_TASK_PERCENTAGE, 20); SetProggressInfo(Constants.LDAP_SETTING_TASK_STATUS, Resource.LdapSettingsStatusRemovingOldUsers); RemoveOldDbUsers(ldapUsers); SetProggressInfo(Constants.LDAP_SETTING_TASK_PERCENTAGE, 30); SetProggressInfo(Constants.LDAP_SETTING_TASK_STATUS, Resource.LdapSettingsStatusSavingUsers); SyncDbUsers(ldapUsers); SetProggressInfo(Constants.LDAP_SETTING_TASK_PERCENTAGE, 70); SetProggressInfo(Constants.LDAP_SETTING_TASK_STATUS, Resource.LdapSettingsStatusRemovingOldGroups); RemoveOldDbGroups(new List <GroupInfo>()); // Remove all db groups with sid }