private void RenewDrivePassword(NetworkDrive drive) { renewDriveMutex.WaitOne(); try { bool keepAsking = true; do { App.Current.Dispatcher.Invoke(new Action(() => { CredentialsWindow dialog = new CredentialsWindow(); dialog.Description = string.Format(Properties.Strings.CredentialsWindowReEnterAfterFailDescription, Helper.GetDomain(drive.RemoteAddress), AskForCredentialsAfterFails); dialog.Username = drive.Username; if (dialog.ShowDialog() == true) { drive.SetCredentials(dialog.Username, dialog.Password); } else { keepAsking = false; } })); if (keepAsking) { if (CheckNetworkDrive(drive)) { try { drive.Connect(ConnectDriveFlags.IgnoreAlreadyConnected | ConnectDriveFlags.Force); } catch (Exception ex) { this.log.Warn("Could not connect drive \"" + drive.LocalDriveLetter + "\" after password renewal: " + ex.Message, ex); App.Current.Dispatcher.Invoke(new Action(() => { MessageBox.Show(null, string.Format(Properties.Strings.MessageConnectFailedAfterCheck), Properties.Strings.TitleCheckConnection, MessageBoxButton.OK, MessageBoxImage.Exclamation); })); } keepAsking = false; } } } while (keepAsking); App.Current.DriveCollection.SaveDrives(); } catch (Exception ex) { this.log.Info("Could not renew password for drive \"" + drive.LocalDriveLetter + "\": " + ex.Message, ex); } renewDriveMutex.ReleaseMutex(); }
private CredentialsWindow GetCredentialsWindow(IWin32Window owner) { var credentialsWindow = new CredentialsWindow(); var helper = new WindowInteropHelper(credentialsWindow); if (owner != null) { helper.Owner = owner.Handle; } return(credentialsWindow); }
private bool ResolveCredentials(AuthorizationRequiredException e) { CredentialsWindow dlg = new CredentialsWindow { ConnectionProfile = e.ConnectionProfile, Owner = Application.Current.MainWindow }; var resolved = dlg.ShowDialog().GetValueOrDefault(false); if (resolved) { ConnectionService.Instance.SetCredentials(e.ConnectionProfile, dlg.Username, dlg.Password, e.Scheme, e.Domain); } return(resolved); }
void RequestCredentialsAndRetry(Uri serviceUri, HttpResponseMessage response, ClientSettings settings) { ICollection <AuthenticationViewModelBase> authTypes = CredentialSelectionController.Default.AuthenticationTypes; authTypes.Clear(); CredentialsWindow credentialsWindow = new CredentialsWindow(); credentialsWindow.DataContext = this; Action <ServiceContext> onGotCredentialsAction = delegate(ServiceContext serviceContext) { // save the context and close all the dialogs this.ServiceContext = serviceContext; credentialsWindow.DialogResult = true; this.connectDialog.DialogResult = true; }; foreach (AuthenticationHeaderValue value in response.Headers.WwwAuthenticate) { switch (value.Scheme.ToUpperInvariant()) { case "BEARER": Trace.TraceInformation("Found Bearer challenge"); if (!authTypes.OfType <OAuthS2SAuthenticationViewModel>().Any()) { authTypes.Add(new OAuthS2SAuthenticationViewModel(serviceUri, onGotCredentialsAction)); } break; case "NTLM": case "NEGOTIATE": Trace.TraceInformation("Found Windows Auth challenge"); if (!authTypes.OfType <WindowsAuthenticationViewModel>().Any()) { authTypes.Add(new WindowsAuthenticationViewModel(serviceUri, onGotCredentialsAction)); } break; } } if (credentialsWindow.ShowDialog() != true) { Trace.TraceInformation("User canceled from the authorization step."); } }