/// <summary> /// Requests log on credentials from the user and insert them into an object implementing /// the ICredentialAware interface. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// a value indicating whether the user did click the cancel button /// </returns> public bool AskForLogOnCredentials(LogonCredentialRequest request) { Console.WriteLine(request.MessageForUser); request.LogOnCredentials.LogOnDomain = GetInfoWithDefault( this.UserDomain, Resources.UiDispatcher_AskForLogOnCredentials_Please_enter_the_user_domain, false); request.LogOnCredentials.LogOnUserId = GetInfoWithDefault( this.UserName, Resources.UiDispatcher_AskForLogOnCredentials_Please_enter_the_user_name, false); request.LogOnCredentials.LogOnPassword = GetInfoWithDefault( this.UserPassword, Resources.UiDispatcher_AskForLogOnCredentials_Please_enter_the_user_password, true); return(request.LogOnCredentials.LogOnPassword.Length > 0); }
/// <summary> /// Shows the dialog to the user and sets the resulting information for the client via the interface <see cref="ICredentialAware"/>. /// </summary> /// <param name="request"> /// an object containing all information to request the credentiols from the user and pass them back to the callee /// </param> /// <returns> /// A value indicating whether the user did press the "ok"-button (true) or the "cancel"-button (false). /// </returns> public bool SetLogonCredentials(LogonCredentialRequest request) { this.UserMessage.Text = request.MessageForUser; this.textBoxUserId.Text = request.LogOnCredentials.LogOnUserId; this.textBoxPassword.Text = request.LogOnCredentials.LogOnPassword; if (this.ShowDialog() == DialogResult.OK) { request.LogOnCredentials.LogOnUserId = this.textBoxUserId.Text; request.LogOnCredentials.LogOnPassword = this.textBoxPassword.Text; request.WriteToCacheAllowed = this.chkAllowSaving.Checked; return(true); } return(false); }
/// <summary> /// Uses the event handler QueryForLogonCredentialsEvent to query the calling instance for Credentials. /// </summary> /// <param name="message"> the message to be displayed to the user </param> protected void QueryForLogOnCredentials(string message) { if (this.UiDispatcher != null) { var logonCredentialRequest = new LogonCredentialRequest(this, message, message); this.UiDispatcher.AskForLogOnCredentials(logonCredentialRequest); return; } if (this.QueryForLogonCredentialsEvent == null) { return; } var args = new QueryForLogOnCredentialsEventArgs { MessageForUser = message, LogonUserId = this.LogOnUserId, LogonPassword = this.LogOnPassword, }; this.QueryForLogonCredentialsEvent(this, args); }
/// <summary> /// Sends an exception file if the configuration does permit this to the configured WCF service. /// The public portion of the encryption key (2048 Bit RSA) is read from the service. There is /// currently no check if the encryption key is authentic - if someone did manipulate your /// configuration, she/he can implement the same type of service and send a different key, so /// that she/he can decrypt the information. /// <para> /// If you want to, you can simply generate a new key pair, compile the service (which is /// part of this solution) and provide such an exception service by yourself. /// </para> /// <remarks> /// The file is encrypted using 2048-bit RSA key. This sounds strong, but was implemented by a /// non-crypto-programmer: me. So don't be surprised if I did a very silly line of code that totally /// broke my encryption class - but inform me if I did so (and also how to fix it). /// </remarks> /// </summary> /// <param name="fileName"> /// the file to be sent /// </param> private static void SendFile(string fileName) { var content = File.ReadAllText(fileName); // ask the user if it's ok to send exception information if (UserInterface == null || !UserInterface.AskForConfirmSendingException(content)) { return; } // create a new service client var sender = new ExceptionServiceClient(); // todo: encryption - in this case we should use public key encryption // send the information and currently don't care about rejected messages try { var key = sender.GetEncryptionKey(); content = SimpleCrypto.EncryptString(content, key); sender.WriteExceptionData(content); } catch (ProtocolException ex) { var x = ex.InnerException as System.Net.WebException; var r = x == null ? null : x.Response as System.Net.HttpWebResponse; if (r != null && r.StatusCode == System.Net.HttpStatusCode.ProxyAuthenticationRequired) { var proxyCredentials = new Credentials(); var wp = System.Net.WebRequest.DefaultWebProxy; var logonCredentialRequest = new LogonCredentialRequest( proxyCredentials, string.Format( CultureInfo.CurrentCulture, "The proxy server needs your credentials to receive content from {0}.", sender.InnerChannel.RemoteAddress.Uri), sender.InnerChannel.RemoteAddress.Uri.ToString()); if (UserInterface.AskForLogOnCredentials(logonCredentialRequest)) { if (string.IsNullOrEmpty(proxyCredentials.LogOnDomain)) { wp.Credentials = new NetworkCredential( proxyCredentials.LogOnUserId, proxyCredentials.LogOnPassword); } else { wp.Credentials = new NetworkCredential( proxyCredentials.LogOnUserId, proxyCredentials.LogOnPassword, proxyCredentials.LogOnDomain); } sender.WriteExceptionData(content); logonCredentialRequest.SaveCredentials(); } return; } throw; } }
/// <summary> /// requests the logon credential request for an online resource /// </summary> /// <param name="request"> /// an object containing all information to request the credentiols from the user and pass them back to the callee /// </param> /// <returns> /// true if the user did click the ok button /// </returns> public bool AskForLogOnCredentials(LogonCredentialRequest request) { return(new LogOn().SetLogonCredentials(request)); }