public void RunJob() { Percentage = 1; Status = Resource.LdapSettingsStatusCheckingLdapSettings; var tenantID = (int)Id; CoreContext.TenantManager.SetCurrentTenant(tenantID); if (_serializeSettings == null) { _log.ErrorFormat("Can't save default LDAP settings."); Error = Resource.LdapSettingsErrorCantGetLdapSettings; IsCompleted = true; return; } try { var settings = (LDAPSupportSettings)JavaScriptDeserializer.DeserializeFromJson(_serializeSettings, typeof(LDAPSupportSettings)); if (settings == null) { _log.ErrorFormat("Wrong LDAP settings were received from client."); Error = Resource.LdapSettingsErrorCantGetLdapSettings; IsCompleted = true; return; } if (!settings.Server.StartsWith("LDAP://")) { settings.Server = "LDAP://" + settings.Server; } if (!string.IsNullOrEmpty(settings.Password)) { settings.PasswordBytes = InstanceCrypto.Encrypt(new UnicodeEncoding().GetBytes(settings.Password)); } settings.Password = string.Empty; var error = GetError(ADDomain.CheckSettings(settings, _importer)); if (error == string.Empty) { Status = Resource.LdapSettingsStatusSavingSettings; Percentage = 3; if (!SettingsManager.Instance.SaveSettings <LDAPSupportSettings>(settings, tenantID)) { _log.ErrorFormat("Can't save LDAP settings."); Error = Resource.LdapSettingsErrorCantSaveLdapSettings; IsCompleted = true; return; } // for logout old ldap users AddLToSids(); if (settings.EnableLdapAuthentication) { CreateUsersAndGroups(settings); } Percentage = 100; } else { Error = error; } } catch (TenantQuotaException e) { _log.ErrorFormat("TenantQuotaException.", e); Error = Resource.LdapSettingsTenantQuotaSettled; } catch (FormatException) { Error = Resource.LdapSettingsErrorCantCreateUsers; } catch (Exception e) { _log.ErrorFormat("Internal server error.", e); Error = Resource.LdapSettingsInternalServerError; } IsCompleted = true; }