mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-11 01:36:39 +00:00
Fix authentication constructors
Provide more ConnectionInfo default constructors.
This commit is contained in:
@@ -16,16 +16,6 @@ namespace Renci.SshNet
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets connection host.
|
||||
/// </summary>
|
||||
public string Host { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets connection port.
|
||||
/// </summary>
|
||||
public int Port { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets connection username.
|
||||
/// </summary>
|
||||
@@ -39,22 +29,12 @@ namespace Renci.SshNet
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthenticationMethod"/> class.
|
||||
/// </summary>
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
protected AuthenticationMethod(string host, int port, string username)
|
||||
protected AuthenticationMethod(string username)
|
||||
{
|
||||
if (!host.IsValidHost())
|
||||
throw new ArgumentException("host");
|
||||
|
||||
if (!port.IsValidPort())
|
||||
throw new ArgumentOutOfRangeException("port");
|
||||
|
||||
if (username.IsNullOrWhiteSpace())
|
||||
throw new ArgumentException("username");
|
||||
|
||||
this.Host = host;
|
||||
this.Port = port;
|
||||
this.Username = username;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,29 @@ namespace Renci.SshNet
|
||||
/// </summary>
|
||||
public string CurrentClientCompressionAlgorithm { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConnectionInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="authenticationMethods">The authentication methods.</param>
|
||||
public ConnectionInfo(string host, string username, params AuthenticationMethod[] authenticationMethods)
|
||||
: this(host, 22, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, authenticationMethods)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConnectionInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="authenticationMethods">The authentication methods.</param>
|
||||
public ConnectionInfo(string host, int port, string username, params AuthenticationMethod[] authenticationMethods)
|
||||
: this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, authenticationMethods)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConnectionInfo"/> class.
|
||||
/// </summary>
|
||||
@@ -328,7 +351,7 @@ namespace Renci.SshNet
|
||||
session.UserAuthenticationBannerReceived += Session_UserAuthenticationBannerReceived;
|
||||
|
||||
// Try to authenticate against none
|
||||
var noneAuthenticationMethod = new NoneAuthenticationMethod(this.Host, this.Port, this.Username);
|
||||
var noneAuthenticationMethod = new NoneAuthenticationMethod(this.Username);
|
||||
|
||||
authenticated = noneAuthenticationMethod.Authenticate(session);
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ namespace Renci.SshNet
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
public KeyboardInteractiveAuthenticationMethod(string host, int port, string username)
|
||||
: base(host, port, username)
|
||||
public KeyboardInteractiveAuthenticationMethod(string username)
|
||||
: base(username)
|
||||
{
|
||||
this._requestMessage = new RequestMessageKeyboardInteractive(ServiceName.Connection, username);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Renci.SshNet
|
||||
/// <param name="proxyUsername">The proxy username.</param>
|
||||
/// <param name="proxyPassword">The proxy password.</param>
|
||||
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(host, port, username))
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(username))
|
||||
{
|
||||
foreach (var authenticationMethod in this.AuthenticationMethods.OfType<KeyboardInteractiveAuthenticationMethod>())
|
||||
{
|
||||
|
||||
@@ -30,25 +30,14 @@ namespace Renci.SshNet
|
||||
/// </summary>
|
||||
public IEnumerable<string> AllowedAuthentications { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
public NoneAuthenticationMethod(string host, string username)
|
||||
: this(host, 22, username)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="host">The host.</param>
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
public NoneAuthenticationMethod(string host, int port, string username)
|
||||
: base(host, port, username)
|
||||
public NoneAuthenticationMethod(string username)
|
||||
: base(username)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ namespace Renci.SshNet
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
public PasswordAuthenticationMethod(string host, int port, string username, string password)
|
||||
: base(host, port, username)
|
||||
public PasswordAuthenticationMethod(string username, string password)
|
||||
: base(username)
|
||||
{
|
||||
if (password == null)
|
||||
throw new ArgumentNullException("password");
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace Renci.SshNet
|
||||
/// <param name="proxyUsername">The proxy username.</param>
|
||||
/// <param name="proxyPassword">The proxy password.</param>
|
||||
public PasswordConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PasswordAuthenticationMethod(host, port, username, password))
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PasswordAuthenticationMethod(username, password))
|
||||
{
|
||||
foreach (var authenticationMethod in this.AuthenticationMethods.OfType<PasswordAuthenticationMethod>())
|
||||
{
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace Renci.SshNet
|
||||
/// <param name="port">The port.</param>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="keyFiles">The key files.</param>
|
||||
public PrivateKeyAuthenticationMethod(string host, int port, string username, params PrivateKeyFile[] keyFiles)
|
||||
: base(host, port, username)
|
||||
public PrivateKeyAuthenticationMethod(string username, params PrivateKeyFile[] keyFiles)
|
||||
: base(username)
|
||||
{
|
||||
this.KeyFiles = new Collection<PrivateKeyFile>(keyFiles);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Renci.SshNet
|
||||
/// <param name="proxyPassword">The proxy password.</param>
|
||||
/// <param name="keyFiles">The key files.</param>
|
||||
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles)
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(host, port, username, keyFiles))
|
||||
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(username, keyFiles))
|
||||
{
|
||||
this.KeyFiles = new Collection<PrivateKeyFile>(keyFiles);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user