/* ==================================================================================== Event handlers */ protected void _btnCheck_Click(object sender, EventArgs e) { var syncAD2Portal = new SyncAD2Portal(); var syncInfo = syncAD2Portal.GetSyncInfo(_tbLdapPath.Text); string syncInfoStr; if (!syncInfo.SyncTreeFound) { syncInfoStr = "Configured SyncTree could not be found for this path. Check the <a href='/Explore.html#/Root/System/SystemPlugins/Tools/DirectoryServices/AD2PortalConfig.xml' target='_blank'>configuration</a>!"; } else { syncInfoStr = string.Format("Configured synctree: ({0}, {1}) -> ({2}) (<a href='/Explore.html#/Root/System/SystemPlugins/Tools/DirectoryServices/AD2PortalConfig.xml' target='_blank'>configuration</a>)<br/>Target portal path: <a href='/Explore.html#{3}' target='_blank'>{3}</a><br/>{4}<br/>{5}", syncInfo.SyncTreeADIPAddress, syncInfo.SyncTreeADPath, syncInfo.SyncTreePortalPath, syncInfo.TargetPortalPath, syncInfo.PortalNodeExists ? "Target path exists" : "Target path does not exist", syncInfo.PortalParentExists ? "Target parent path exists" : "Target parent path does not exist" ); } this.Controls.Add(new Literal { Text = "<hr/><strong>Results:</strong><br/>" }); this.Controls.Add(new Literal { Text = syncInfoStr }); }
/* ==================================================================================== Event handlers */ protected void _btnCheck_Click(object sender, EventArgs e) { var syncAD2Portal = new SyncAD2Portal(); var syncInfo = syncAD2Portal.GetSyncInfo(_tbLdapPath.Text); string syncInfoStr; if (!syncInfo.SyncTreeFound) { syncInfoStr = SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "SyncTreeNotFound"); } else { syncInfoStr = string.Format(SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "SyncTreeFound"), syncInfo.SyncTreeADIPAddress, syncInfo.SyncTreeADPath, syncInfo.SyncTreePortalPath, syncInfo.TargetPortalPath, SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", syncInfo.PortalNodeExists ? "TargetPathExists" : "TargetPathDoesNotExist"), SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", syncInfo.PortalParentExists ? "ParentPathExists" : "ParentPathDoesNotExist") ); } this.Controls.Add(new Literal { Text = string.Format("<hr/><strong>{0}:</strong><br/>", SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "Results")) }); this.Controls.Add(new Literal { Text = syncInfoStr }); }
private static void Main(string[] args) { if (!ParseParameters(args)) { Logger.WriteWarning(0, "ADSync process arguments are not correct.", new[] { "" }); return; } // Client API initialization ClientContext.Initialize(new[] { new ServerContext { Url = SiteUrl, Username = Username, Password = Password } }); ClientContext.Current.ChunkSizeInBytes = 419430; var directoryServices = new SyncAD2Portal(SiteUrl); directoryServices.SyncFromAdAsync().Wait(); }
static void Main(string[] args) { var startSettings = new RepositoryStartSettings { Console = Console.Out, StartLuceneManager = true }; using (var repo = Repository.Start(startSettings)) { using (var traceOperation = Logger.TraceOperation("SyncAD2Portal", string.Empty, AdLog.AdSyncLogCategory)) { SyncAD2Portal directoryServices = new SyncAD2Portal(); directoryServices.SyncFromAD(); traceOperation.IsSuccessful = true; } } }
protected void _btnSyncObject_Click(object sender, EventArgs e) { this.Controls.Add(new Literal { Text = "<hr/><strong>Results:</strong><br/>" }); try { var syncAD2Portal = new SyncAD2Portal(); // impersonate to currently logged on windows user, to use its credentials to connect to AD WindowsImpersonationContext impersonationContext = null; if (this.UseImpersonate) { var windowsIdentity = ((User)User.Current).WindowsIdentity; if (windowsIdentity == null) { this.Controls.Add(new Literal { Text = "Windows identity impersonation failed for current user." }); return; } impersonationContext = windowsIdentity.Impersonate(); } int? logid = null; bool noerrors = false; try { logid = AdLog.SubscribeToLog(); syncAD2Portal.SyncObjectFromAD(_tbLdapPath.Text); noerrors = true; } catch (Exception ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format("An error occurred during execution ({0}).<br/>See adsync log below and eventlog for details.<br/><br/>", ex.Message) }); } finally { if (impersonationContext != null) { impersonationContext.Undo(); } if (logid.HasValue) { var logStr = AdLog.GetLogAndRemoveSubscription(logid.Value); this.Controls.Add(new Literal { Text = logStr.Replace(Environment.NewLine, "<br/>") }); } // add link to object to bottom if (noerrors) { var syncInfo = syncAD2Portal.GetSyncInfo(_tbLdapPath.Text); if (syncInfo.PortalNodeExists) { this.Controls.Add(new Literal { Text = string.Format("<hr/>Check the results: <a href='/Explore.html#{0}' target='_blank'>{0}</a>", syncInfo.TargetPortalPath) }); } } } } catch (SecurityException ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format("A security exception occurred ({0}).<br/>See eventlog for details.", ex.Message) }); } catch (Exception ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format("An exception occurred ({0}).<br/>See eventlog for details.", ex.Message) }); } }
protected void _btnSyncObject_Click(object sender, EventArgs e) { this.Controls.Add(new Literal { Text = string.Format("<hr/><strong>{0}:</strong><br/>", SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "Results")) }); try { var syncAD2Portal = new SyncAD2Portal(); // impersonate to currently logged on windows user, to use its credentials to connect to AD WindowsImpersonationContext impersonationContext = null; if (this.UseImpersonate) { var windowsIdentity = ((User)User.Current).WindowsIdentity; if (windowsIdentity == null) { this.Controls.Add(new Literal { Text = SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "IdentityImpersonationFailed") }); return; } impersonationContext = windowsIdentity.Impersonate(); } int? logid = null; bool noerrors = false; try { logid = AdLog.SubscribeToLog(); syncAD2Portal.SyncObjectFromAD(_tbLdapPath.Text); noerrors = true; } catch (Exception ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format(SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "SyncError"), ex.Message) }); } finally { if (impersonationContext != null) { impersonationContext.Undo(); } if (logid.HasValue) { var logStr = AdLog.GetLogAndRemoveSubscription(logid.Value); this.Controls.Add(new Literal { Text = logStr.Replace(Environment.NewLine, "<br/>") }); } // add link to object to bottom if (noerrors) { var syncInfo = syncAD2Portal.GetSyncInfo(_tbLdapPath.Text); if (syncInfo.PortalNodeExists) { this.Controls.Add(new Literal { Text = string.Format(SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "CheckResults"), syncInfo.TargetPortalPath) }); } } } } catch (SecurityException ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format(SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "SyncErrorSecurity"), ex.Message) }); } catch (Exception ex) { Logger.WriteException(ex); this.Controls.Add(new Literal { Text = string.Format(SenseNetResourceManager.Current.GetString("SyncObjectFromADPortlet", "SyncErrorException"), ex.Message) }); } }