AuthenticationMethod.cs 1.7 KB

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