// ============================================================================== Static methods private static async Task <SyncConfiguration> LoadConfiguration() { try { dynamic settingsContent = Content.LoadAsync(SettingsPath).Result; if (settingsContent == null) { return(null); } string binaryUrl = _siteUrl.TrimEnd('/') + settingsContent.Binary.__mediaresource.media_src + "&includepasswords=true"; var settingsText = await RESTCaller.GetResponseStringAsync(new Uri(binaryUrl)); var config = JsonHelper.Deserialize <SyncConfiguration>(settingsText); // decrypt passwords and inject them back to the configuration foreach (var server in config.Servers.Where(server => server.LogonCredentials != null && !string.IsNullOrEmpty(server.LogonCredentials.Password))) { var request = new ODataRequest { ActionName = "Decrypt", Path = "Root", IsCollectionRequest = false, SiteUrl = _siteUrl }; try { server.LogonCredentials.Password = await RESTCaller.GetResponseStringAsync( request.GetUri(), ClientContext.Current.Servers[0], HttpMethod.Post, JsonHelper.Serialize(new { text = server.LogonCredentials.Password })); } catch (ClientException cex) { AdLog.LogError("Error during password decryption. " + Common.FormatClientException(cex)); } catch (Exception ex) { AdLog.LogException(ex); } } // preload all AD-related content types from the server ADRelatedContentTypes = await LoadADRelatedContentTypes(); return(config); } catch (Exception ex) { AdLog.LogException(ex); } return(null); }
public bool VerifyConnection() { // this is clearly invalid if (string.IsNullOrEmpty(this.LdapServer)) { return(false); } // we do not have to verify certification if (!this.UseSsl || this.TrustWrongCertification || this.LogonCredentials == null || this.LogonCredentials.Anonymous) { return(true); } try { // use default port if a port is not provided var port = this.Port == 0 ? 389 : this.Port; using (var conn = new LdapConnection(new LdapDirectoryIdentifier(this.LdapServer, port))) { conn.SessionOptions.SecureSocketLayer = true; conn.SessionOptions.VerifyServerCertificate = (connection, certificate) => { return(true); }; conn.Credential = new NetworkCredential(this.LogonCredentials.Username, this.LogonCredentials.Password); conn.AuthType = AuthType.Basic; conn.Bind(); return(true); } } catch (Exception ex) { AdLog.LogError("Could not connect to server " + this.LdapServer + " " + ex); } return(false); }