AuthenticationMethod.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 : IAuthenticationMethod
  10. {
  11. /// <summary>
  12. /// Gets the name of the authentication method.
  13. /// </summary>
  14. /// <value>
  15. /// The name of the authentication method.
  16. /// </value>
  17. public abstract string Name { get; }
  18. /// <summary>
  19. /// Gets connection username.
  20. /// </summary>
  21. public string Username { get; private set; }
  22. /// <summary>
  23. /// Gets list of allowed authentications.
  24. /// </summary>
  25. public IList<string> AllowedAuthentications { get; protected set; }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="AuthenticationMethod"/> class.
  28. /// </summary>
  29. /// <param name="username">The username.</param>
  30. /// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or null.</exception>
  31. protected AuthenticationMethod(string username)
  32. {
  33. if (username.IsNullOrWhiteSpace())
  34. throw new ArgumentException("username");
  35. Username = username;
  36. }
  37. /// <summary>
  38. /// Authenticates the specified session.
  39. /// </summary>
  40. /// <param name="session">The session to authenticate.</param>
  41. /// <returns>
  42. /// The result of the authentication process.
  43. /// </returns>
  44. public abstract AuthenticationResult Authenticate(Session session);
  45. /// <summary>
  46. /// Authenticates the specified session.
  47. /// </summary>
  48. /// <param name="session">The session to authenticate.</param>
  49. /// <returns>
  50. /// The result of the authentication process.
  51. /// </returns>
  52. AuthenticationResult IAuthenticationMethod.Authenticate(ISession session)
  53. {
  54. return Authenticate((Session) session);
  55. }
  56. }
  57. }