Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/mRemoteNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortecxx <tecxx@rrs.at>2021-12-25 20:52:54 +0300
committertecxx <tecxx@rrs.at>2021-12-25 20:52:54 +0300
commitcdc1d5064feabaf60789d9cd69857666a319ba33 (patch)
tree1218483b469ef0b1bfa16380b679530134b29494
parent3b707d29b945cf0987004eb6f699ecc12c271e4c (diff)
improve handling of invalid api credentials
-rw-r--r--ExternalConnectors/TSS/SSConnectionForm.Designer.cs99
-rw-r--r--ExternalConnectors/TSS/SSConnectionForm.cs6
-rw-r--r--ExternalConnectors/TSS/SecretServerInterface.cs58
3 files changed, 105 insertions, 58 deletions
diff --git a/ExternalConnectors/TSS/SSConnectionForm.Designer.cs b/ExternalConnectors/TSS/SSConnectionForm.Designer.cs
index dfeb387a..cd10f8b1 100644
--- a/ExternalConnectors/TSS/SSConnectionForm.Designer.cs
+++ b/ExternalConnectors/TSS/SSConnectionForm.Designer.cs
@@ -48,29 +48,29 @@
// tbSSURL
//
this.tbSSURL.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tbSSURL.Location = new System.Drawing.Point(445, 7);
- this.tbSSURL.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.tbSSURL.Location = new System.Drawing.Point(260, 4);
+ this.tbSSURL.Margin = new System.Windows.Forms.Padding(4);
this.tbSSURL.Name = "tbSSURL";
- this.tbSSURL.Size = new System.Drawing.Size(921, 35);
+ this.tbSSURL.Size = new System.Drawing.Size(536, 23);
this.tbSSURL.TabIndex = 0;
//
// tbUsername
//
this.tbUsername.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tbUsername.Location = new System.Drawing.Point(445, 69);
- this.tbUsername.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.tbUsername.Location = new System.Drawing.Point(260, 35);
+ this.tbUsername.Margin = new System.Windows.Forms.Padding(4);
this.tbUsername.Name = "tbUsername";
- this.tbUsername.Size = new System.Drawing.Size(921, 35);
+ this.tbUsername.Size = new System.Drawing.Size(536, 23);
this.tbUsername.TabIndex = 2;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label3.Location = new System.Drawing.Point(6, 124);
- this.label3.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+ this.label3.Location = new System.Drawing.Point(4, 62);
+ this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(427, 46);
+ this.label3.Size = new System.Drawing.Size(248, 23);
this.label3.TabIndex = 5;
this.label3.Text = "Password";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -78,10 +78,10 @@
// tbPassword
//
this.tbPassword.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tbPassword.Location = new System.Drawing.Point(445, 131);
- this.tbPassword.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.tbPassword.Location = new System.Drawing.Point(260, 66);
+ this.tbPassword.Margin = new System.Windows.Forms.Padding(4);
this.tbPassword.Name = "tbPassword";
- this.tbPassword.Size = new System.Drawing.Size(921, 35);
+ this.tbPassword.Size = new System.Drawing.Size(536, 23);
this.tbPassword.TabIndex = 4;
this.tbPassword.UseSystemPasswordChar = true;
//
@@ -89,22 +89,23 @@
//
this.btnOK.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.btnOK.Location = new System.Drawing.Point(510, 23);
- this.btnOK.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.btnOK.Location = new System.Drawing.Point(296, 12);
+ this.btnOK.Margin = new System.Windows.Forms.Padding(4);
this.btnOK.Name = "btnOK";
- this.btnOK.Size = new System.Drawing.Size(150, 53);
+ this.btnOK.Size = new System.Drawing.Size(88, 26);
this.btnOK.TabIndex = 10;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
+ this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btnCancel.Location = new System.Drawing.Point(712, 23);
- this.btnCancel.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.btnCancel.Location = new System.Drawing.Point(415, 12);
+ this.btnCancel.Margin = new System.Windows.Forms.Padding(4);
this.btnCancel.Name = "btnCancel";
- this.btnCancel.Size = new System.Drawing.Size(150, 53);
+ this.btnCancel.Size = new System.Drawing.Size(88, 26);
this.btnCancel.TabIndex = 11;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
@@ -124,27 +125,27 @@
this.tableLayoutPanel1.Controls.Add(this.cbUseSSO, 0, 3);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
- this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 4;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 46F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 46F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 46F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 46F));
- this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 46F));
- this.tableLayoutPanel1.Size = new System.Drawing.Size(1372, 217);
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(800, 108);
this.tableLayoutPanel1.TabIndex = 12;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label5.Location = new System.Drawing.Point(445, 170);
- this.label5.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+ this.label5.Location = new System.Drawing.Point(260, 85);
+ this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(921, 47);
+ this.label5.Size = new System.Drawing.Size(536, 23);
this.label5.TabIndex = 15;
this.label5.Text = "For SSO to work, additional IIS configuration is required!";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -153,10 +154,10 @@
//
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label1.Location = new System.Drawing.Point(6, 0);
- this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+ this.label1.Location = new System.Drawing.Point(4, 0);
+ this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(427, 62);
+ this.label1.Size = new System.Drawing.Size(248, 31);
this.label1.TabIndex = 2;
this.label1.Text = "Secret Server URL";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -165,10 +166,10 @@
//
this.label2.AutoSize = true;
this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label2.Location = new System.Drawing.Point(6, 62);
- this.label2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+ this.label2.Location = new System.Drawing.Point(4, 31);
+ this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(427, 62);
+ this.label2.Size = new System.Drawing.Size(248, 31);
this.label2.TabIndex = 4;
this.label2.Text = "DOMAIN\\Username";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -176,10 +177,10 @@
// cbUseSSO
//
this.cbUseSSO.AutoSize = true;
- this.cbUseSSO.Location = new System.Drawing.Point(6, 177);
- this.cbUseSSO.Margin = new System.Windows.Forms.Padding(6, 7, 6, 0);
+ this.cbUseSSO.Location = new System.Drawing.Point(4, 89);
+ this.cbUseSSO.Margin = new System.Windows.Forms.Padding(4, 4, 4, 0);
this.cbUseSSO.Name = "cbUseSSO";
- this.cbUseSSO.Size = new System.Drawing.Size(117, 34);
+ this.cbUseSSO.Size = new System.Drawing.Size(69, 19);
this.cbUseSSO.TabIndex = 14;
this.cbUseSSO.Text = "Use SSO";
this.cbUseSSO.UseVisualStyleBackColor = true;
@@ -188,30 +189,30 @@
// tableLayoutPanel2
//
this.tableLayoutPanel2.ColumnCount = 5;
- this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 160F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 93F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
- this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 23F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
- this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 160F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 93F));
this.tableLayoutPanel2.Controls.Add(this.btnOK, 1, 0);
this.tableLayoutPanel2.Controls.Add(this.btnCancel, 3, 0);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 298);
- this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 148);
+ this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(4);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 1;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.tableLayoutPanel2.Size = new System.Drawing.Size(1372, 99);
+ this.tableLayoutPanel2.Size = new System.Drawing.Size(800, 50);
this.tableLayoutPanel2.TabIndex = 13;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label4.Location = new System.Drawing.Point(0, 217);
- this.label4.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+ this.label4.Location = new System.Drawing.Point(0, 108);
+ this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(599, 30);
+ this.label4.Size = new System.Drawing.Size(341, 15);
this.label4.TabIndex = 14;
this.label4.Text = "URL is the base URL, like https://cred.domain.local/SecretServer";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -219,13 +220,13 @@
// SSConnectionForm
//
this.AcceptButton = this.btnOK;
- this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1372, 397);
+ this.ClientSize = new System.Drawing.Size(800, 198);
this.Controls.Add(this.label4);
this.Controls.Add(this.tableLayoutPanel2);
this.Controls.Add(this.tableLayoutPanel1);
- this.Margin = new System.Windows.Forms.Padding(6, 7, 6, 7);
+ this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "SSConnectionForm";
this.Text = "Secret Server API Login Data";
this.Activated += new System.EventHandler(this.SSConnectionForm_Activated);
diff --git a/ExternalConnectors/TSS/SSConnectionForm.cs b/ExternalConnectors/TSS/SSConnectionForm.cs
index be3a5a3e..d2adeff0 100644
--- a/ExternalConnectors/TSS/SSConnectionForm.cs
+++ b/ExternalConnectors/TSS/SSConnectionForm.cs
@@ -26,5 +26,11 @@
tbPassword.Enabled = !ch;
tbUsername.Enabled = !ch;
}
+
+ private void btnOK_Click(object sender, EventArgs e)
+ {
+ // test connection first
+
+ }
}
}
diff --git a/ExternalConnectors/TSS/SecretServerInterface.cs b/ExternalConnectors/TSS/SecretServerInterface.cs
index ae0e73ab..c2b1380f 100644
--- a/ExternalConnectors/TSS/SecretServerInterface.cs
+++ b/ExternalConnectors/TSS/SecretServerInterface.cs
@@ -44,16 +44,31 @@ namespace ExternalConnectors.TSS
f.cbUseSSO.Checked = ssSSO;
// show dialog
- _ = f.ShowDialog();
-
- if (f.DialogResult != DialogResult.OK)
- return;
+ while(true)
+ {
+ _ = f.ShowDialog();
+
+ if (f.DialogResult != DialogResult.OK)
+ return;
+
+ // store values to memory
+ ssUsername = f.tbUsername.Text;
+ ssPassword = f.tbPassword.Text;
+ ssUrl = f.tbSSURL.Text;
+ ssSSO = f.cbUseSSO.Checked;
+
+ // check connection first
+ try
+ {
+ if (TestCredentials() == true)
+ break;
+ }
+ catch (Exception)
+ {
+ MessageBox.Show("TestCredentials failed - please check your credentials");
+ }
+ }
- // store values to memory
- ssUsername = f.tbUsername.Text;
- ssPassword = f.tbPassword.Text;
- ssUrl = f.tbSSURL.Text;
- ssSSO = f.cbUseSSO.Checked;
// write values to registry
key.SetValue("Username", ssUsername);
@@ -72,6 +87,31 @@ namespace ExternalConnectors.TSS
}
}
+ private static bool TestCredentials()
+ {
+ string authUsername = SSConnectionData.ssUsername;
+ string authPassword = SSConnectionData.ssPassword;
+ string baseURL = SSConnectionData.ssUrl;
+
+ if (SSConnectionData.ssSSO)
+ {
+ // checking creds doesn't really make sense here, as we can't modify them anyway if something is wrong
+ return true;
+ }
+ else
+ {
+ using (var httpClient = new HttpClient())
+ {
+ // Authenticate:
+ var tokenClient = new OAuth2ServiceClient(baseURL, httpClient);
+ // call below will throw an exception if the creds are invalid
+ var token = tokenClient.AuthorizeAsync(Grant_type.Password, authUsername, authPassword, null).Result;
+ // here we can be sure the creds are ok - return success state
+ return true;
+ }
+ }
+ }
+
private static void FetchSecret(int secretID, out string secretUsername, out string secretPassword, out string secretDomain)
{
string authUsername = SSConnectionData.ssUsername;