public LdapOperationStatus SaveLdapSettings(string settings, bool acceptCertificate) { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID).ToList(); if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { return(GetStartProcessError()); } var ldapSettings = JsonConvert.DeserializeObject <LdapSettings>(settings); ldapSettings.AcceptCertificate = acceptCertificate; if (!ldapSettings.EnableLdapAuthentication) { SetLdapCronSettings(null); } //ToDo ldapSettings.AccessRights.Clear(); var ldapLocalization = new LdapLocalization(Resource.ResourceManager); var tenant = CoreContext.TenantManager.GetCurrentTenant(); var op = new LdapSaveSyncOperation(ldapSettings, tenant, LdapOperationType.Save, ldapLocalization, CurrentUser.ToString()); return(QueueTask(op)); }
private static LdapOperationStatus ToLdapOperationStatus() { var operations = LDAPTasks.GetTasks().ToList(); foreach (var o in operations) { if (!string.IsNullOrEmpty(o.InstanseId) && Process.GetProcesses().Any(p => p.Id == int.Parse(o.InstanseId))) { continue; } o.SetProperty(LdapOperation.PROGRESS, 100); LDAPTasks.RemoveTask(o.Id); } var operation = operations .FirstOrDefault(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID); if (operation == null) { return(null); } if (DistributedTaskStatus.Running < operation.Status) { operation.SetProperty(LdapOperation.PROGRESS, 100); LDAPTasks.RemoveTask(operation.Id); } var certificateConfirmRequest = operation.GetProperty <LdapCertificateConfirmRequest>(LdapOperation.CERT_REQUEST); var result = new LdapOperationStatus { Id = operation.Id, Completed = operation.GetProperty <bool>(LdapOperation.FINISHED), Percents = operation.GetProperty <int>(LdapOperation.PROGRESS), Status = operation.GetProperty <string>(LdapOperation.RESULT), Error = operation.GetProperty <string>(LdapOperation.ERROR), CertificateConfirmRequest = certificateConfirmRequest, Source = operation.GetProperty <string>(LdapOperation.SOURCE), OperationType = Enum.GetName(typeof(LdapOperationType), (LdapOperationType)Convert.ToInt32(operation.GetProperty <string>(LdapOperation.OPERATION_TYPE))), Warning = operation.GetProperty <string>(LdapOperation.WARNING) }; if (!(string.IsNullOrEmpty(result.Warning))) { operation.SetProperty(LdapOperation.WARNING, ""); // "mark" as read } return(result); }
private static LDAPSupportSettingsResult ToLdapSettingsResult() { var operations = LDAPTasks.GetTasks().ToList(); foreach (var o in operations) { if (!string.IsNullOrEmpty(o.InstanseId) && Process.GetProcesses().Any(p => p.Id == int.Parse(o.InstanseId))) { continue; } o.SetProperty(LDAPOperation.PROGRESS, 100); LDAPTasks.RemoveTask(o.Id); } var operation = operations .FirstOrDefault(t => t.GetProperty <int>(LDAPOperation.OWNER) == TenantProvider.CurrentTenantID); if (operation == null) { return(new LDAPSupportSettingsResult { Id = null, Completed = true, Percents = 100, Status = "", Error = Resource.LdapSettingsInternalServerError, Source = "" }); } if (DistributedTaskStatus.Running < operation.Status) { operation.SetProperty(LDAPOperation.PROGRESS, 100); LDAPTasks.RemoveTask(operation.Id); } var certificateConfirmRequest = operation.GetProperty <NovellLdapCertificateConfirmRequest>(LDAPOperation.CERT_REQUEST); var result = new LDAPSupportSettingsResult { Id = operation.Id, Completed = operation.GetProperty <bool>(LDAPOperation.FINISHED), Percents = operation.GetProperty <int>(LDAPOperation.PROGRESS), Status = operation.GetProperty <string>(LDAPOperation.RESULT), Error = operation.GetProperty <string>(LDAPOperation.ERROR), CertificateConfirmRequest = certificateConfirmRequest, Source = operation.GetProperty <string>(LDAPOperation.SOURCE) }; return(result); }
public LDAPSupportSettingsResult SaveLdapSettings(string settings, bool acceptCertificate) { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LDAPOperation.OWNER) == TenantProvider.CurrentTenantID); if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { throw new InvalidOperationException(Resource.LdapSettingsTooManyOperations); } var ldapSettings = JsonConvert.DeserializeObject <LDAPSupportSettings>(settings); var op = new LDAPSaveSyncOperation(ldapSettings, acceptCertificate: acceptCertificate); return(QueueTask(op)); }
public LDAPSupportSettingsResult SyncLdap() { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LDAPOperation.OWNER) == TenantProvider.CurrentTenantID); if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { throw new InvalidOperationException(Resource.LdapSettingsTooManyOperations); } var ldapSettings = SettingsManager.Instance.LoadSettings <LDAPSupportSettings>(TenantProvider.CurrentTenantID); var op = new LDAPSaveSyncOperation(ldapSettings, syncOnly: true); return(QueueTask(op)); }
public LdapOperationStatus TestLdapSave(string settings, bool acceptCertificate) { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID) .ToList(); var hasStarted = operations.Any(o => { var opType = o.GetProperty <LdapOperationType>(LdapOperation.OPERATION_TYPE); return(o.Status <= DistributedTaskStatus.Running && (opType == LdapOperationType.SyncTest || opType == LdapOperationType.SaveTest)); }); if (hasStarted) { return(GetLdapOperationStatus()); } if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { return(GetStartProcessError()); } var ldapSettings = JsonConvert.DeserializeObject <LdapSettings>(settings); ldapSettings.AcceptCertificate = acceptCertificate; var ldapLocalization = new LdapLocalization(Resource.ResourceManager); var tenant = CoreContext.TenantManager.GetCurrentTenant(); Cache.Insert("REWRITE_URL" + tenant.TenantId, HttpContext.Current.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5)); var op = new LdapSaveSyncOperation(ldapSettings, tenant, LdapOperationType.SaveTest, ldapLocalization, CurrentUser.ToString()); return(QueueTask(op)); }
public LdapOperationStatus SaveLdapSettings(string settings, bool acceptCertificate) { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID).ToList(); if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { return(GetStartProcessError()); } var ldapSettings = JsonConvert.DeserializeObject <LdapSettings>(settings); ldapSettings.AcceptCertificate = acceptCertificate; if (!ldapSettings.EnableLdapAuthentication) { SetLdapCronSettings(null); } //ToDo ldapSettings.AccessRights.Clear(); if (!ldapSettings.LdapMapping.ContainsKey(LdapSettings.MappingFields.MailAttribute) || string.IsNullOrEmpty(ldapSettings.LdapMapping[LdapSettings.MappingFields.MailAttribute])) { ldapSettings.SendWelcomeEmail = false; } var ldapLocalization = new LdapLocalization(Resource.ResourceManager, ASC.Web.Studio.Core.Notify.WebstudioNotifyPatternResource.ResourceManager); var tenant = CoreContext.TenantManager.GetCurrentTenant(); Cache.Insert("REWRITE_URL" + tenant.TenantId, HttpContext.Current.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5)); var op = new LdapSaveSyncOperation(ldapSettings, tenant, LdapOperationType.Save, ldapLocalization, CurrentUser.ToString()); return(QueueTask(op)); }
public LdapOperationStatus TestLdapSync() { CheckLdapPermissions(); var operations = LDAPTasks.GetTasks() .Where(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID) .ToList(); var hasStarted = operations.Any(o => { var opType = o.GetProperty <LdapOperationType>(LdapOperation.OPERATION_TYPE); return(o.Status <= DistributedTaskStatus.Running && (opType == LdapOperationType.SyncTest || opType == LdapOperationType.SaveTest)); }); if (hasStarted) { return(GetLdapOperationStatus()); } if (operations.Any(o => o.Status <= DistributedTaskStatus.Running)) { return(GetStartProcessError()); } var ldapSettings = LdapSettings.Load(); var ldapLocalization = new LdapLocalization(Resource.ResourceManager); var tenant = CoreContext.TenantManager.GetCurrentTenant(); var op = new LdapSaveSyncOperation(ldapSettings, tenant, LdapOperationType.SyncTest, ldapLocalization); return(QueueTask(op)); }
private LdapOperationStatus QueueTask(LdapOperation op) { LDAPTasks.QueueTask(op.RunJob, op.GetDistributedTask()); return(ToLdapOperationStatus()); }
private LDAPSupportSettingsResult QueueTask(LDAPOperation op) { LDAPTasks.QueueTask(op.RunJob, op.GetDistributedTask()); return(ToLdapSettingsResult()); }