AuthenticationMethod.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using Renci.SshNet.Common;
  4. namespace Renci.SshNet
  5. {
  6. /// <summary>
  7. /// Base class for all supported authentication methods
  8. /// </summary>
  9. public abstract class AuthenticationMethod
  10. {
  11. /// <summary>
  12. /// Gets authentication method name
  13. /// </summary>
  14. public abstract string Name { get; }
  15. /// <summary>
  16. /// Gets connection username.
  17. /// </summary>
  18. public string Username { get; private set; }
  19. /// <summary>
  20. /// Gets the authentication error message.
  21. /// </summary>
  22. public string ErrorMessage { get; private set; }
  23. /// <summary>
  24. /// Gets list of allowed authentications.
  25. /// </summary>
  26. public IEnumerable<string> AllowedAuthentications { get; protected set; }
  27. /// <summary>
  28. /// Initializes a new instance of the <see cref="AuthenticationMethod"/> class.
  29. /// </summary>
  30. /// <param name="username">The username.</param>
  31. /// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or null.</exception>
  32. protected AuthenticationMethod(string username)
  33. {
  34. if (username.IsNullOrWhiteSpace())
  35. throw new ArgumentException("username");
  36. this.Username = username;
  37. }
  38. /// <summary>
  39. /// Authenticates the specified session.
  40. /// </summary>
  41. /// <param name="session">The session to authenticate.</param>
  42. /// <returns>Result of authentication process.</returns>
  43. public abstract AuthenticationResult Authenticate(Session session);
  44. }
  45. }