You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace UMC.SshNet
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base class for all supported authentication methods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AuthenticationMethod : IAuthenticationMethod
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the authentication method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// The name of the authentication method.
|
|
|
|
|
/// </value>
|
|
|
|
|
public abstract string Name { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets connection username.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Username { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the list of allowed authentications.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string[] AllowedAuthentications { get; protected set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="AuthenticationMethod"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="username">The username.</param>
|
|
|
|
|
/// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or <c>null</c>.</exception>
|
|
|
|
|
protected AuthenticationMethod(string username)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(username))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("username");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Username = username;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Authenticates the specified session.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="session">The session to authenticate.</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// The result of the authentication process.
|
|
|
|
|
/// </returns>
|
|
|
|
|
public abstract AuthenticationResult Authenticate(Session session);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Authenticates the specified session.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="session">The session to authenticate.</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// The result of the authentication process.
|
|
|
|
|
/// </returns>
|
|
|
|
|
AuthenticationResult IAuthenticationMethod.Authenticate(ISession session)
|
|
|
|
|
{
|
|
|
|
|
return Authenticate((Session) session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|