Changed the demo's ServerForm to display the client's username when a client connects.

This commit is contained in:
antiduh
2014-06-30 14:40:39 +00:00
parent cec7b8b88f
commit 0070e94aed
2 changed files with 102 additions and 64 deletions

View File

@@ -33,15 +33,17 @@
this.startButton = new System.Windows.Forms.Button();
this.stopButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.usernameTextbox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.serverUsernameTextbox = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.sendTextbox = new System.Windows.Forms.TextBox();
this.receivedTextbox = new System.Windows.Forms.TextBox();
this.encryptButton = new System.Windows.Forms.Button();
this.signButton = new System.Windows.Forms.Button();
this.encryptButton = new System.Windows.Forms.Button();
this.sendTextbox = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.receivedTextbox = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.label3 = new System.Windows.Forms.Label();
this.clientUsernameTextBox = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
@@ -102,33 +104,35 @@
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.clientUsernameTextBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.usernameTextbox);
this.groupBox1.Controls.Add(this.serverUsernameTextbox);
this.groupBox1.Location = new System.Drawing.Point(400, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(313, 65);
this.groupBox1.Size = new System.Drawing.Size(305, 76);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server credentials";
//
// usernameTextbox
//
this.usernameTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.usernameTextbox.Location = new System.Drawing.Point(74, 20);
this.usernameTextbox.Name = "usernameTextbox";
this.usernameTextbox.ReadOnly = true;
this.usernameTextbox.Size = new System.Drawing.Size(233, 20);
this.usernameTextbox.TabIndex = 0;
this.groupBox1.Text = "Credentials";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(7, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.Size = new System.Drawing.Size(90, 13);
this.label2.TabIndex = 1;
this.label2.Text = "User name:";
this.label2.Text = "Server username:";
//
// serverUsernameTextbox
//
this.serverUsernameTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.serverUsernameTextbox.Location = new System.Drawing.Point(106, 20);
this.serverUsernameTextbox.Name = "serverUsernameTextbox";
this.serverUsernameTextbox.ReadOnly = true;
this.serverUsernameTextbox.Size = new System.Drawing.Size(193, 20);
this.serverUsernameTextbox.TabIndex = 0;
//
// groupBox2
//
@@ -138,22 +142,62 @@
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox2.Location = new System.Drawing.Point(3, 3);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(344, 381);
this.groupBox2.Size = new System.Drawing.Size(340, 396);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Send a message to the client";
//
// signButton
//
this.signButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.signButton.Location = new System.Drawing.Point(174, 357);
this.signButton.Name = "signButton";
this.signButton.Size = new System.Drawing.Size(117, 23);
this.signButton.TabIndex = 3;
this.signButton.Text = "Sign and send";
this.signButton.UseVisualStyleBackColor = true;
//
// encryptButton
//
this.encryptButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.encryptButton.Location = new System.Drawing.Point(33, 357);
this.encryptButton.Name = "encryptButton";
this.encryptButton.Size = new System.Drawing.Size(120, 23);
this.encryptButton.TabIndex = 2;
this.encryptButton.Text = "Encrypt and send";
this.encryptButton.UseVisualStyleBackColor = true;
//
// sendTextbox
//
this.sendTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.sendTextbox.Location = new System.Drawing.Point(6, 19);
this.sendTextbox.Multiline = true;
this.sendTextbox.Name = "sendTextbox";
this.sendTextbox.Size = new System.Drawing.Size(327, 330);
this.sendTextbox.TabIndex = 0;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.receivedTextbox);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox3.Location = new System.Drawing.Point(353, 3);
this.groupBox3.Location = new System.Drawing.Point(349, 3);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(345, 381);
this.groupBox3.Size = new System.Drawing.Size(341, 396);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Received messages from the client";
//
// receivedTextbox
//
this.receivedTextbox.Dock = System.Windows.Forms.DockStyle.Fill;
this.receivedTextbox.Location = new System.Drawing.Point(3, 16);
this.receivedTextbox.Multiline = true;
this.receivedTextbox.Name = "receivedTextbox";
this.receivedTextbox.Size = new System.Drawing.Size(335, 377);
this.receivedTextbox.TabIndex = 0;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@@ -164,60 +208,44 @@
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.groupBox3, 1, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 87);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 94);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(701, 387);
this.tableLayoutPanel1.Size = new System.Drawing.Size(693, 402);
this.tableLayoutPanel1.TabIndex = 7;
//
// sendTextbox
// label3
//
this.sendTextbox.Location = new System.Drawing.Point(6, 19);
this.sendTextbox.Multiline = true;
this.sendTextbox.Name = "sendTextbox";
this.sendTextbox.Size = new System.Drawing.Size(331, 322);
this.sendTextbox.TabIndex = 0;
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 50);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(85, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Client username:";
//
// receivedTextbox
// clientUsernameTextBox
//
this.receivedTextbox.Dock = System.Windows.Forms.DockStyle.Fill;
this.receivedTextbox.Location = new System.Drawing.Point(3, 16);
this.receivedTextbox.Multiline = true;
this.receivedTextbox.Name = "receivedTextbox";
this.receivedTextbox.Size = new System.Drawing.Size(339, 362);
this.receivedTextbox.TabIndex = 0;
this.clientUsernameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.clientUsernameTextBox.Location = new System.Drawing.Point(106, 47);
this.clientUsernameTextBox.Name = "clientUsernameTextBox";
this.clientUsernameTextBox.ReadOnly = true;
this.clientUsernameTextBox.Size = new System.Drawing.Size(193, 20);
this.clientUsernameTextBox.TabIndex = 3;
//
// encryptButton
//
this.encryptButton.Location = new System.Drawing.Point(33, 349);
this.encryptButton.Name = "encryptButton";
this.encryptButton.Size = new System.Drawing.Size(120, 23);
this.encryptButton.TabIndex = 2;
this.encryptButton.Text = "Encrypt and send";
this.encryptButton.UseVisualStyleBackColor = true;
//
// signButton
//
this.signButton.Location = new System.Drawing.Point(174, 349);
this.signButton.Name = "signButton";
this.signButton.Size = new System.Drawing.Size(117, 23);
this.signButton.TabIndex = 3;
this.signButton.Text = "Sign and send";
this.signButton.UseVisualStyleBackColor = true;
//
// Form1
// ServerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(725, 477);
this.ClientSize = new System.Drawing.Size(717, 499);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.stopButton);
this.Controls.Add(this.startButton);
this.Controls.Add(this.portNumeric);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Name = "ServerForm";
this.Text = "Server - SSPI Test";
((System.ComponentModel.ISupportInitialize)(this.portNumeric)).EndInit();
this.groupBox1.ResumeLayout(false);
@@ -240,7 +268,7 @@
private System.Windows.Forms.Button stopButton;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox usernameTextbox;
private System.Windows.Forms.TextBox serverUsernameTextbox;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button signButton;
@@ -248,6 +276,8 @@
private System.Windows.Forms.TextBox sendTextbox;
private System.Windows.Forms.TextBox receivedTextbox;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TextBox clientUsernameTextBox;
private System.Windows.Forms.Label label3;
}
}

View File

@@ -64,7 +64,7 @@ namespace TestServer
UpdateButtons();
this.usernameTextbox.Text = this.serverCred.Name;
this.serverUsernameTextbox.Text = this.serverCred.Name;
}
private void Form1_FormClosing( object sender, FormClosingEventArgs e )
@@ -167,7 +167,11 @@ namespace TestServer
ContextAttrib.Confidentiality
);
this.BeginInvoke( (Action) UpdateButtons );
this.BeginInvoke( (Action)delegate()
{
UpdateButtons();
this.clientUsernameTextBox.Text = "";
});
}
@@ -192,7 +196,11 @@ namespace TestServer
this.initializing = false;
this.connected = true;
this.Invoke( (Action)delegate() { UpdateButtons(); } );
this.Invoke( (Action)delegate()
{
UpdateButtons();
this.clientUsernameTextBox.Text = serverContext.ContextUserName;
} );
}
}
else