protected override void Do() { try { if (OperationType == LdapOperationType.Save) { SetProgress(10, Resource.LdapSettingsStatusSavingSettings); LDAPSettings.IsDefault = LDAPSettings.Equals(LDAPSettings.GetDefault()); if (!LDAPSettings.Save()) { Logger.Error("Can't save LDAP settings."); Error = Resource.LdapSettingsErrorCantSaveLdapSettings; return; } } if (LDAPSettings.EnableLdapAuthentication) { Logger.Debug("SyncLDAP()"); SyncLDAP(); if (!string.IsNullOrEmpty(Error)) { return; } } else { Logger.Debug("TurnOffLDAP()"); TurnOffLDAP(); ((LdapCurrentUserPhotos)LdapCurrentUserPhotos.Load().GetDefault()).Save(); ((LdapCurrentAcccessSettings)LdapCurrentAcccessSettings.Load().GetDefault()).Save(); //не снимать права при выключении //var rights = new List<LdapSettings.AccessRight>(); //TakeUsersRights(rights); //if (rights.Count > 0) //{ // Warning = Resource.LdapSettingsErrorLostRights; //} } } catch (NovellLdapTlsCertificateRequestedException ex) { Logger.ErrorFormat( "CheckSettings(acceptCertificate={0}, cert thumbprint: {1}): NovellLdapTlsCertificateRequestedException: {2}", LDAPSettings.AcceptCertificate, LDAPSettings.AcceptCertificateHash, ex.ToString()); Error = Resource.LdapSettingsStatusCertificateVerification; //TaskInfo.SetProperty(CERT_REQUEST, ex.CertificateConfirmRequest); } catch (TenantQuotaException e) { Logger.ErrorFormat("TenantQuotaException. {0}", e.ToString()); Error = Resource.LdapSettingsTenantQuotaSettled; } catch (FormatException e) { Logger.ErrorFormat("FormatException error. {0}", e.ToString()); Error = Resource.LdapSettingsErrorCantCreateUsers; } catch (Exception e) { Logger.ErrorFormat("Internal server error. {0}", e.ToString()); Error = Resource.LdapSettingsInternalServerError; } finally { SetProgress(99, Resource.LdapSettingsStatusDisconnecting, ""); Dispose(); } SetProgress(100, OperationType == LdapOperationType.SaveTest || OperationType == LdapOperationType.SyncTest ? JsonConvert.SerializeObject(_ldapChanges) : "", ""); }
public void RunJob(DistributedTask _, CancellationToken cancellationToken) { try { CancellationToken = cancellationToken; CoreContext.TenantManager.SetCurrentTenant(CurrentTenant); SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(_culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(_culture); Logger = LogManager.GetLogger(typeof(LDAPOperation)); if (LDAPSettings == null) { Error = Resource.LdapSettingsErrorCantGetLdapSettings; Logger.Error("Can't save default LDAP settings."); return; } if (OperationType == LDAPOperationType.Save) { SetProgress(1, Resource.LdapSettingsStatusCheckingLdapSettings); PrepareSettings(LDAPSettings); if (!string.IsNullOrEmpty(Error)) { return; } Importer = new LDAPUserImporter(LDAPSettings); SetProgress(5, Resource.LdapSettingsStatusLoadingBaseInfo); var acceptCertificate = TaskInfo.GetProperty <bool>(CERT_ALLOW); var result = _ldapSettingsChecker.CheckSettings(Importer, acceptCertificate); if (result == LdapSettingsChecker.CERTIFICATE_REQUEST) { TaskInfo.SetProperty(FINISHED, true); TaskInfo.SetProperty(CERT_REQUEST, ((NovellLdapSettingsChecker)_ldapSettingsChecker).CertificateConfirmRequest); SetProgress(0, Resource.LdapSettingsStatusCertificateVerification); return; } var error = GetError(result); if (!string.IsNullOrEmpty(error)) { Error = error; return; } SetProgress(10, Resource.LdapSettingsStatusSavingSettings); LDAPSettings.IsDefault = LDAPSettings.Equals(LDAPSettings.GetDefault()); if (!SettingsManager.Instance.SaveSettings(LDAPSettings, CurrentTenant.TenantId)) { Logger.Error("Can't save LDAP settings."); Error = Resource.LdapSettingsErrorCantSaveLdapSettings; return; } } else if (OperationType == LDAPOperationType.Sync) { Importer = new LDAPUserImporter(LDAPSettings); } Do(); } catch (AuthorizingException authError) { Error = Resource.ErrorAccessDenied; Logger.Error(Error, new SecurityException(Error, authError)); } catch (AggregateException ae) { ae.Flatten().Handle(e => e is TaskCanceledException || e is OperationCanceledException); } catch (TenantQuotaException e) { Error = Resource.LdapSettingsTenantQuotaSettled; Logger.ErrorFormat("TenantQuotaException. {0}", e); } catch (FormatException e) { Error = Resource.LdapSettingsErrorCantCreateUsers; Logger.ErrorFormat("FormatException error. {0}", e); } catch (Exception e) { Error = Resource.LdapSettingsInternalServerError; Logger.ErrorFormat("Internal server error. {0}", e); } finally { try { TaskInfo.SetProperty(FINISHED, true); PublishTaskInfo(); } catch { /* ignore */ } } }