Store the domain and username rather than the whole AdPasswordPrompt.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-07-27 13:16:01 +01:00 committed by Mihaela Stoica
parent 02eaac832a
commit 12fe9e9620
3 changed files with 25 additions and 37 deletions

View File

@ -41,18 +41,14 @@ namespace XenAdmin.Dialogs
public string Domain
{
get
{
return textBoxDomain.Text;
}
get { return textBoxDomain.Text.Trim(); }
set { textBoxDomain.Text = value ?? string.Empty; }
}
public string Username
{
get
{
return textBoxUsername.Text.Trim();
}
get { return textBoxUsername.Text.Trim(); }
set { textBoxUsername.Text = value ?? string.Empty; }
}
public string Password
@ -72,7 +68,7 @@ namespace XenAdmin.Dialogs
/// the AD server, giving options 'Disable', 'Ignore' and 'Cancel'.</param>
/// <param name="currentDomainName">The current domain name to populate the dialog with. Maybe null or empty if
/// joining an unknown domain. Should not be null or empty when leaving a domain.</param>
public AdPasswordPrompt(bool join, string currentDomainName)
public AdPasswordPrompt(bool join, string currentDomainName = null)
{
InitializeComponent();
@ -144,11 +140,6 @@ namespace XenAdmin.Dialogs
: textBoxUsername.Text.Trim().Length > 0;
}
public void ClearPassword()
{
textBoxPassword.Text = "";
}
internal override string HelpName
{
get

View File

@ -60,13 +60,11 @@ namespace XenAdmin.TabPages
private IXenConnection _connection;
private Thread _loggedInStatusUpdater;
/// <summary>
/// We keep a reference to this prompt to make repeated attempts to enable AD more user friendly (remembering the previously tried creds)
/// </summary>
private AdPasswordPrompt joinPrompt;
private bool _updateInProgress;
private string _storedDomain;
private string _storedUsername;
private readonly CollectionChangeEventHandler Pool_CollectionChangedWithInvoke;
public IXenObject XenObject
{
@ -109,7 +107,6 @@ namespace XenAdmin.TabPages
tTipRemoveButton.SetToolTip(Messages.AD_CANNOT_MODIFY_ROOT);
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
Text = Messages.ACTIVE_DIRECTORY_TAB_TITLE;
joinPrompt = new AdPasswordPrompt(true, null);
}
/// <summary>
@ -685,21 +682,22 @@ namespace XenAdmin.TabPages
if (buttonJoinLeave.Text == Messages.AD_JOIN_DOMAIN)
{
// We're enabling AD
// Obtain domain, username and password
// Obtain domain, username and password; store the domain and username
// so the user won't have to retype it for future join attempts
joinPrompt.ShowDialog(this);
// Blocking for a long time, check we haven't had the dialog disposed under us
if (Disposing || IsDisposed)
return;
if (joinPrompt.DialogResult == DialogResult.Cancel)
using (var joinPrompt = new AdPasswordPrompt(true)
{Domain = _storedDomain, Username = _storedUsername})
{
joinPrompt.ClearPassword();
return;
}
var result = joinPrompt.ShowDialog(this);
_storedDomain = joinPrompt.Domain;
_storedUsername = joinPrompt.Username;
new EnableAdAction(_connection, joinPrompt.Domain, joinPrompt.Username, joinPrompt.Password, false).RunAsync();
joinPrompt.ClearPassword();
if (result == DialogResult.Cancel)
return;
new EnableAdAction(_connection, joinPrompt.Domain,
joinPrompt.Username, joinPrompt.Password, false).RunAsync();
}
}
else
{
@ -751,7 +749,6 @@ namespace XenAdmin.TabPages
return;
}
Host master = Helpers.GetMaster(_connection);
if (master == null)
{
@ -762,7 +759,7 @@ namespace XenAdmin.TabPages
using (var passPrompt = new AdPasswordPrompt(false, master.external_auth_service_name))
{
var result = passPrompt.ShowDialog(Program.MainWindow);
var result = passPrompt.ShowDialog(this);
if (result == DialogResult.Cancel)
return;
@ -785,7 +782,7 @@ namespace XenAdmin.TabPages
return;
using (var dlog = new ResolvingSubjectsDialog(_connection))
dlog.ShowDialog();
dlog.ShowDialog(this);
}
private void ButtonRemove_Click(object sender, EventArgs e)
@ -865,7 +862,7 @@ namespace XenAdmin.TabPages
var action = new AddRemoveSubjectsAction(_connection, new List<string>(), subjectsToRemove);
using (var dlog = new ActionProgressDialog(action, ProgressBarStyle.Continuous))
dlog.ShowDialog();
dlog.ShowDialog(this);
}
private void GridViewSubjectList_SelectionChanged(object sender, EventArgs e)

View File

@ -42,7 +42,7 @@ namespace XenAdminTests.DialogTests.state1_xml.AdPasswordPromptTests
{
protected override AdPasswordPrompt NewDialog()
{
return new AdPasswordPrompt(true, null);
return new AdPasswordPrompt(true);
}
}