CA-337270: Perform authentication on a background thread.

- Added controls to display the error in case authentication fails.
- Use the same control(LinkLabel) to show the rubric either when new
  authentication is needed or an existing one can be used.
- Moved privacy policy statement next to the checkbox because it looked crammed.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2020-06-02 04:49:10 +01:00
parent ec7fc14c18
commit 89487fcf60
3 changed files with 409 additions and 360 deletions

View File

@ -50,10 +50,10 @@ namespace XenAdmin.Dialogs.HealthCheck
this.existingAuthenticationRadioButton = new System.Windows.Forms.RadioButton();
this.newAuthenticationRadioButton = new System.Windows.Forms.RadioButton();
this.authRubricLinkLabel = new System.Windows.Forms.LinkLabel();
this.authRubricTextLabel = new System.Windows.Forms.Label();
this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel();
this.pictureBoxStatus = new System.Windows.Forms.PictureBox();
this.labelStatus = new System.Windows.Forms.Label();
this.rubricLabel = new System.Windows.Forms.Label();
this.PolicyStatementLinkLabel = new System.Windows.Forms.LinkLabel();
this.m_ctrlError = new XenAdmin.Controls.Common.PasswordFailure();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.enrollmentCheckBox = new System.Windows.Forms.CheckBox();
this.decentGroupBoxXSCredentials = new XenAdmin.Controls.DecentGroupBox();
@ -68,12 +68,15 @@ namespace XenAdmin.Dialogs.HealthCheck
this.currentXsCredentialsRadioButton = new System.Windows.Forms.RadioButton();
this.newXsCredentialsRadioButton = new System.Windows.Forms.RadioButton();
this.testCredentialsButton = new System.Windows.Forms.Button();
this.PolicyStatementLinkLabel = new System.Windows.Forms.LinkLabel();
this.tableLayoutPanel1.SuspendLayout();
this.decentGroupBox2.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.frequencyNumericBox)).BeginInit();
this.decentGroupBox1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.tableLayoutPanel5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStatus)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
this.decentGroupBoxXSCredentials.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
@ -98,14 +101,13 @@ namespace XenAdmin.Dialogs.HealthCheck
// tableLayoutPanel1
//
resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1");
this.tableLayoutPanel1.Controls.Add(this.decentGroupBox2, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.decentGroupBox1, 0, 8);
this.tableLayoutPanel1.Controls.Add(this.decentGroupBox2, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.decentGroupBox1, 0, 4);
this.tableLayoutPanel1.Controls.Add(this.rubricLabel, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.PolicyStatementLinkLabel, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.m_ctrlError, 0, 10);
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 1, 10);
this.tableLayoutPanel1.Controls.Add(this.enrollmentCheckBox, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.decentGroupBoxXSCredentials, 0, 7);
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 5);
this.tableLayoutPanel1.Controls.Add(this.enrollmentCheckBox, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.decentGroupBoxXSCredentials, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.PolicyStatementLinkLabel, 1, 1);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
//
// decentGroupBox2
@ -195,14 +197,14 @@ namespace XenAdmin.Dialogs.HealthCheck
// tableLayoutPanel2
//
resources.ApplyResources(this.tableLayoutPanel2, "tableLayoutPanel2");
this.tableLayoutPanel2.Controls.Add(this.label1, 0, 4);
this.tableLayoutPanel2.Controls.Add(this.label2, 0, 5);
this.tableLayoutPanel2.Controls.Add(this.textBoxMyCitrixPassword, 1, 5);
this.tableLayoutPanel2.Controls.Add(this.textBoxMyCitrixUsername, 1, 4);
this.tableLayoutPanel2.Controls.Add(this.existingAuthenticationRadioButton, 0, 2);
this.tableLayoutPanel2.Controls.Add(this.newAuthenticationRadioButton, 0, 3);
this.tableLayoutPanel2.Controls.Add(this.label1, 0, 3);
this.tableLayoutPanel2.Controls.Add(this.label2, 0, 4);
this.tableLayoutPanel2.Controls.Add(this.textBoxMyCitrixPassword, 1, 4);
this.tableLayoutPanel2.Controls.Add(this.textBoxMyCitrixUsername, 1, 3);
this.tableLayoutPanel2.Controls.Add(this.existingAuthenticationRadioButton, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.newAuthenticationRadioButton, 0, 2);
this.tableLayoutPanel2.Controls.Add(this.authRubricLinkLabel, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.authRubricTextLabel, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel5, 1, 5);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
//
// label1
@ -254,11 +256,24 @@ namespace XenAdmin.Dialogs.HealthCheck
this.authRubricLinkLabel.TabStop = true;
this.authRubricLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.authRubricLinkLabel_LinkClicked);
//
// authRubricTextLabel
// tableLayoutPanel5
//
resources.ApplyResources(this.authRubricTextLabel, "authRubricTextLabel");
this.tableLayoutPanel2.SetColumnSpan(this.authRubricTextLabel, 2);
this.authRubricTextLabel.Name = "authRubricTextLabel";
resources.ApplyResources(this.tableLayoutPanel5, "tableLayoutPanel5");
this.tableLayoutPanel5.Controls.Add(this.pictureBoxStatus, 0, 0);
this.tableLayoutPanel5.Controls.Add(this.labelStatus, 1, 0);
this.tableLayoutPanel5.Name = "tableLayoutPanel5";
//
// pictureBoxStatus
//
resources.ApplyResources(this.pictureBoxStatus, "pictureBoxStatus");
this.pictureBoxStatus.Name = "pictureBoxStatus";
this.pictureBoxStatus.TabStop = false;
//
// labelStatus
//
resources.ApplyResources(this.labelStatus, "labelStatus");
this.labelStatus.ForeColor = System.Drawing.SystemColors.ControlText;
this.labelStatus.Name = "labelStatus";
//
// rubricLabel
//
@ -266,22 +281,10 @@ namespace XenAdmin.Dialogs.HealthCheck
this.tableLayoutPanel1.SetColumnSpan(this.rubricLabel, 2);
this.rubricLabel.Name = "rubricLabel";
//
// PolicyStatementLinkLabel
//
resources.ApplyResources(this.PolicyStatementLinkLabel, "PolicyStatementLinkLabel");
this.tableLayoutPanel1.SetColumnSpan(this.PolicyStatementLinkLabel, 2);
this.PolicyStatementLinkLabel.Name = "PolicyStatementLinkLabel";
this.PolicyStatementLinkLabel.TabStop = true;
this.PolicyStatementLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.PolicyStatementLinkLabel_LinkClicked);
//
// m_ctrlError
//
resources.ApplyResources(this.m_ctrlError, "m_ctrlError");
this.m_ctrlError.Name = "m_ctrlError";
//
// flowLayoutPanel1
//
resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1");
this.tableLayoutPanel1.SetColumnSpan(this.flowLayoutPanel1, 2);
this.flowLayoutPanel1.Controls.Add(this.cancelButton);
this.flowLayoutPanel1.Controls.Add(this.okButton);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
@ -289,7 +292,6 @@ namespace XenAdmin.Dialogs.HealthCheck
// enrollmentCheckBox
//
resources.ApplyResources(this.enrollmentCheckBox, "enrollmentCheckBox");
this.tableLayoutPanel1.SetColumnSpan(this.enrollmentCheckBox, 2);
this.enrollmentCheckBox.Name = "enrollmentCheckBox";
this.enrollmentCheckBox.UseVisualStyleBackColor = true;
this.enrollmentCheckBox.CheckedChanged += new System.EventHandler(this.enrollmentCheckBox_CheckedChanged);
@ -319,8 +321,8 @@ namespace XenAdmin.Dialogs.HealthCheck
//
// errorLabel
//
this.errorLabel.AutoEllipsis = true;
resources.ApplyResources(this.errorLabel, "errorLabel");
this.errorLabel.AutoEllipsis = true;
this.errorLabel.ForeColor = System.Drawing.Color.Red;
this.errorLabel.Name = "errorLabel";
//
@ -377,7 +379,7 @@ namespace XenAdmin.Dialogs.HealthCheck
this.newXsCredentialsRadioButton.Name = "newXsCredentialsRadioButton";
this.newXsCredentialsRadioButton.TabStop = true;
this.newXsCredentialsRadioButton.UseVisualStyleBackColor = true;
this.newXsCredentialsRadioButton.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
this.newXsCredentialsRadioButton.CheckedChanged += new System.EventHandler(this.newXsCredentialsRadioButton_CheckedChanged);
//
// testCredentialsButton
//
@ -386,6 +388,13 @@ namespace XenAdmin.Dialogs.HealthCheck
this.testCredentialsButton.UseVisualStyleBackColor = true;
this.testCredentialsButton.Click += new System.EventHandler(this.testCredentialsButton_Click);
//
// PolicyStatementLinkLabel
//
resources.ApplyResources(this.PolicyStatementLinkLabel, "PolicyStatementLinkLabel");
this.PolicyStatementLinkLabel.Name = "PolicyStatementLinkLabel";
this.PolicyStatementLinkLabel.TabStop = true;
this.PolicyStatementLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.PolicyStatementLinkLabel_LinkClicked);
//
// HealthCheckSettingsDialog
//
this.AcceptButton = this.okButton;
@ -405,6 +414,9 @@ namespace XenAdmin.Dialogs.HealthCheck
this.decentGroupBox1.PerformLayout();
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
this.tableLayoutPanel5.ResumeLayout(false);
this.tableLayoutPanel5.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxStatus)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false);
this.flowLayoutPanel1.PerformLayout();
this.decentGroupBoxXSCredentials.ResumeLayout(false);
@ -450,13 +462,14 @@ namespace XenAdmin.Dialogs.HealthCheck
protected System.Windows.Forms.TextBox textboxXSUserName;
private System.Windows.Forms.RadioButton currentXsCredentialsRadioButton;
private System.Windows.Forms.RadioButton newXsCredentialsRadioButton;
private Controls.Common.PasswordFailure m_ctrlError;
private System.Windows.Forms.Button testCredentialsButton;
private System.Windows.Forms.PictureBox testCredentialsStatusImage;
private System.Windows.Forms.Label errorLabel;
protected System.Windows.Forms.Label label2;
protected System.Windows.Forms.TextBox textBoxMyCitrixPassword;
private System.Windows.Forms.LinkLabel authRubricLinkLabel;
private System.Windows.Forms.Label authRubricTextLabel;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel5;
private System.Windows.Forms.PictureBox pictureBoxStatus;
private System.Windows.Forms.Label labelStatus;
}
}

View File

@ -36,7 +36,6 @@ using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAdmin.Model;
using XenAdmin.Properties;
using XenAPI;
@ -55,7 +54,7 @@ namespace XenAdmin.Dialogs.HealthCheck
private string xsUserName;
private string xsPassword;
internal override string HelpName { get { return "HealthCheckSettingsDialog"; } }
internal override string HelpName => "HealthCheckSettingsDialog";
public HealthCheckSettingsDialog(Pool pool, bool enrollNow)
:base(pool.Connection)
@ -113,21 +112,21 @@ namespace XenAdmin.Dialogs.HealthCheck
private void InitializeControls()
{
Text = String.Format(Messages.HEALTHCHECK_ENROLLMENT_TITLE, pool.Name());
tableLayoutPanel5.Visible = false;
string noAuthTokenMessage = string.Format(Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_NO_TOKEN, Messages.MY_CITRIX_CREDENTIALS_URL);
string existingAuthTokenMessage = Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_EXISTING_TOKEN;
string authenticationRubricLabelText = authenticationRequired ? noAuthTokenMessage : existingAuthTokenMessage;
if (authenticationRubricLabelText == noAuthTokenMessage)
if (authenticationRequired)
{
authRubricTextLabel.Visible = false;
string noAuthTokenMessage = string.Format(Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_NO_TOKEN,
Messages.MY_CITRIX_CREDENTIALS_URL);
authRubricLinkLabel.Text = noAuthTokenMessage;
authRubricLinkLabel.LinkArea = new System.Windows.Forms.LinkArea(authenticationRubricLabelText.IndexOf(Messages.MY_CITRIX_CREDENTIALS_URL), Messages.MY_CITRIX_CREDENTIALS_URL.Length);
authRubricLinkLabel.LinkArea = new LinkArea(noAuthTokenMessage.IndexOf(Messages.MY_CITRIX_CREDENTIALS_URL),
Messages.MY_CITRIX_CREDENTIALS_URL.Length);
}
else
{
authRubricLinkLabel.Visible = false;
authRubricTextLabel.Text = existingAuthTokenMessage;
authRubricLinkLabel.Text = Messages.HEALTHCHECK_AUTHENTICATION_RUBRIC_EXISTING_TOKEN;
authRubricLinkLabel.LinkArea = new LinkArea(0, 0);
}
enrollmentCheckBox.Checked = healthCheckSettings.Status != HealthCheckStatus.Disabled;
@ -168,19 +167,19 @@ namespace XenAdmin.Dialogs.HealthCheck
private void UpdateButtons()
{
okButton.Enabled = m_ctrlError.PerformCheck(CheckCredentialsEntered) && !errorLabel.Visible;
okButton.Enabled = CheckCredentialsEntered() && !errorLabel.Visible;
}
private void okButton_Click(object sender, EventArgs e)
{
okButton.Enabled = false;
if (enrollmentCheckBox.Checked && newAuthenticationRadioButton.Checked
&& !m_ctrlError.PerformCheck(CheckUploadAuthentication))
{
okButton.Enabled = true;
return;
if (enrollmentCheckBox.Checked && newAuthenticationRadioButton.Checked)
CheckUploadAuthentication();
else
SaveAndClose();
}
private void SaveAndClose()
{
if (ChangesMade())
{
var newHealthCheckSettings = new HealthCheckSettings(pool.health_check_config);
@ -194,7 +193,7 @@ namespace XenAdmin.Dialogs.HealthCheck
new SaveHealthCheckSettingsAction(pool, newHealthCheckSettings, authenticationToken, diagnosticToken, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, false).RunAsync();
new TransferHealthCheckSettingsAction(pool, newHealthCheckSettings, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, true).RunAsync();
}
okButton.Enabled = true;
DialogResult = DialogResult.OK;
Close();
}
@ -212,12 +211,7 @@ namespace XenAdmin.Dialogs.HealthCheck
UpdateButtons();
}
private void newAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
{
SetMyCitrixCredentials(existingAuthenticationRadioButton.Checked);
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
private void newXsCredentialsRadioButton_CheckedChanged(object sender, EventArgs e)
{
SetXSCredentials(currentXsCredentialsRadioButton.Checked);
testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked &&
@ -277,43 +271,55 @@ namespace XenAdmin.Dialogs.HealthCheck
return true;
}
private bool CheckCredentialsEntered(out string error)
private void CheckUploadAuthentication()
{
error = string.Empty;
return CheckCredentialsEntered();
}
private bool CheckUploadAuthentication(out string error)
{
error = string.Empty;
if (!CheckCredentialsEntered())
return false;
var action = new HealthCheckAuthenticationAction(textBoxMyCitrixUsername.Text.Trim(), textBoxMyCitrixPassword.Text.Trim(),
Registry.HealthCheckIdentityTokenDomainName, Registry.HealthCheckUploadGrantTokenDomainName, Registry.HealthCheckUploadTokenDomainName,
Registry.HealthCheckDiagnosticDomainName, Registry.HealthCheckProductKey, 0, false);
Registry.HealthCheckDiagnosticDomainName, Registry.HealthCheckProductKey, 0, true);
action.Completed += action_Completed;
try
{
action.RunExternal(null);
okButton.Enabled = false;
pictureBoxStatus.Image = Images.StaticImages.ajax_loader;
labelStatus.Text = action.Description;
labelStatus.ForeColor = SystemColors.ControlText;
tableLayoutPanel5.Visible = true;
action.RunAsync();
}
catch
private void action_Completed(ActionBase a)
{
Program.Invoke(this, () =>
{
if (!a.Succeeded || !(a is HealthCheckAuthenticationAction action))
{
error = action.Exception != null ? action.Exception.Message : Messages.ERROR_UNKNOWN;
authenticationToken = null;
authenticated = false;
return authenticated;
}
else
{
authenticationToken = action.UploadToken; // current upload token
diagnosticToken = action.DiagnosticToken; // current diagnostic token
authenticated = !string.IsNullOrEmpty(authenticationToken) && !string.IsNullOrEmpty(diagnosticToken);
}
authenticationToken = action.UploadToken; // curent upload token
diagnosticToken = action.DiagnosticToken; // curent diagnostic token
authenticated = !String.IsNullOrEmpty(authenticationToken) && !String.IsNullOrEmpty(diagnosticToken);
return authenticated;
if (!authenticated)
{
pictureBoxStatus.Image = Images.StaticImages._000_error_h32bit_16;
labelStatus.Text = a.Exception != null ? a.Exception.Message : Messages.ERROR_UNKNOWN;
labelStatus.ForeColor = Color.Red;
okButton.Enabled = true;
return;
}
tableLayoutPanel5.Visible = false;
okButton.Enabled = true;
SaveAndClose();
});
}
private void credentials_TextChanged(object sender, EventArgs e)
{
tableLayoutPanel5.Visible = false;
UpdateButtons();
}
@ -379,20 +385,20 @@ namespace XenAdmin.Dialogs.HealthCheck
{
if (passedRbacChecks)
{
ShowTestCredentialsStatus(Resources._000_Tick_h32bit_16, null);
ShowTestCredentialsStatus(Images.StaticImages._000_Tick_h32bit_16, null);
okButton.Enabled = true;
}
else
{
okButton.Enabled = false;
ShowTestCredentialsStatus(Resources._000_error_h32bit_16, action.Exception != null ? action.Exception.Message : Messages.HEALTH_CHECK_USER_NOT_AUTHORIZED);
ShowTestCredentialsStatus(Images.StaticImages._000_error_h32bit_16, action.Exception != null ? action.Exception.Message : Messages.HEALTH_CHECK_USER_NOT_AUTHORIZED);
}
textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked;
});
};
log.Debug("Testing logging in with the new credentials");
ShowTestCredentialsStatus(Resources.ajax_loader, null);
ShowTestCredentialsStatus(Images.StaticImages.ajax_loader, null);
textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = false;
action.RunAsync();
}
@ -426,8 +432,15 @@ namespace XenAdmin.Dialogs.HealthCheck
return false;
}
private void newAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
{
tableLayoutPanel5.Visible = false;
SetMyCitrixCredentials(existingAuthenticationRadioButton.Checked);
}
private void existingAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
{
tableLayoutPanel5.Visible = false;
UpdateButtons();
}
@ -435,6 +448,5 @@ namespace XenAdmin.Dialogs.HealthCheck
{
Program.OpenURL(Messages.MY_CITRIX_CREDENTIALS_URL);
}
}
}

File diff suppressed because it is too large Load Diff