/// <summary> /// Initializes a new instance of the <see cref="LogonCredentialRequest"/> class. /// </summary> /// <param name="credentials">The credentials.</param> /// <param name="message">The message to display.</param> /// <param name="resourceName"> The name of the resource the credentials belong to. </param> public LogonCredentialRequest(ICredentialAware credentials, string message, string resourceName) { this.LogOnCredentials = credentials; this.MessageForUser = message; this.ResourceKey = Tools.GetSha1Hash(resourceName); var regValue = Tools.GetRegValue(SoftwareSemSyncCachedcredentials, this.ResourceKey, string.Empty); if (!string.IsNullOrEmpty(regValue)) { this.LogOnCredentials = Tools.LoadFromString <Credentials>(regValue); } }
/// <summary> /// Generates a connector and inserts some information /// </summary> /// <param name="typeName"> The type name to generate. </param> /// <param name="credentials"> The credentials to add to the connector . </param> /// <returns> The connector that is set up </returns> public StdClient SetupConnector(string typeName, ICredentialAware credentials) { var client = this.factory.GetNewObject <StdClient>(typeName); if (client != null && credentials != null) { client.LogOnUserId = credentials.LogOnUserId; client.LogOnPassword = credentials.LogOnPassword; client.LogOnDomain = credentials.LogOnDomain; } return(client); }
/// <summary> /// Create a request and get the response stream for the GET method /// </summary> /// <param name="url"> url to the page to get </param> /// <param name="referer"> specifies the referer (url this request came from) to add to the request </param> /// <param name="encoding"> the encoding used for the text </param> /// <returns> a stream corresponding to the content at the uri </returns> private Stream GetResponseStream(Uri url, string referer, out string encoding) { HttpWebResponse objResponse; var request = this.CreateRequest(url, "GET", referer); var logonCredentialRequest = new LogonCredentialRequest( this.proxyCredentials, string.Format( CultureInfo.CurrentCulture, Resources.TheProxyServerNeedsYourCredentials, url.Host, request.Proxy.GetProxy(url).Host), request.Proxy.GetProxy(url).Host); while (true) { try { objResponse = GetHttpResponse(request); encoding = objResponse.CharacterSet; logonCredentialRequest.SaveCredentials(); break; } catch (WebException ex) { if ((this.UiDispatcher != null) && ex.Response != null && ((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired) { request = this.CreateRequest(url, "GET", referer); if (this.UiDispatcher.AskForLogOnCredentials(logonCredentialRequest)) { this.proxyCredentials = logonCredentialRequest.LogOnCredentials; if (string.IsNullOrEmpty(logonCredentialRequest.LogOnCredentials.LogOnDomain)) { request.Proxy.Credentials = new NetworkCredential( logonCredentialRequest.LogOnCredentials.LogOnUserId, logonCredentialRequest.LogOnCredentials.LogOnPassword); } else { request.Proxy.Credentials = new NetworkCredential( logonCredentialRequest.LogOnCredentials.LogOnUserId, logonCredentialRequest.LogOnCredentials.LogOnPassword, logonCredentialRequest.LogOnCredentials.LogOnDomain); } } else { encoding = string.Empty; return(null); } } else { if (ex.Response != null) { if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized) { if (this.ContentCredentials.LogOnDomain == "[GOOGLE]") { request = this.CreateRequest(url, "GET", referer); request.Headers.Add("Authorization", "GoogleLogin auth=" + this.ContentCredentials.LogOnPassword); } } } if ((this.UiDispatcher != null) && (ex.Status == WebExceptionStatus.ConnectFailure || ex.Status == WebExceptionStatus.NameResolutionFailure)) { if ( this.UiDispatcher.AskForConfirm( string.Format( Resources.UserMessageConnectionProblemQuestionRetry, url.Host, ex.Status), Resources.UserMessageConnectionProblemTitle)) { continue; } } encoding = string.Empty; return(null); } } } return(objResponse.GetResponseStream()); }
/// <summary> /// Shows the dialog to the user and sets the resulting information for the client via the interface <see cref="ICredentialAware"/>. /// </summary> /// <param name="client"> /// The client that implements <see cref="ICredentialAware"/> and should get the credentials. /// </param> /// <param name="arguments"> /// The arguments with preselected credentials and a message for the user. /// </param> public void SetLogonCredentials(ICredentialAware client, QueryForLogOnCredentialsEventArgs arguments) { this.SetLogonCredentials( new LogonCredentialRequest(client, arguments.MessageForUser, arguments.MessageForUser)); }