Class UserAuthImpl

java.lang.Object
net.schmizz.sshj.AbstractService
net.schmizz.sshj.userauth.UserAuthImpl
All Implemented Interfaces:
ErrorNotifiable, SSHPacketHandler, Service, UserAuth

public class UserAuthImpl extends AbstractService implements UserAuth
UserAuth implementation.
  • Field Details

    • authenticated

      private final Promise<Boolean,UserAuthException> authenticated
    • partialSuccess

      private volatile boolean partialSuccess
    • allowedMethods

      private volatile List<String> allowedMethods
    • currentMethod

      private volatile AuthMethod currentMethod
    • nextService

      private volatile Service nextService
  • Constructor Details

    • UserAuthImpl

      public UserAuthImpl(Transport trans)
  • Method Details

    • authenticate

      public boolean authenticate(String username, Service nextService, AuthMethod method, int timeoutMs) throws UserAuthException, TransportException
      Description copied from interface: UserAuth
      Attempt to authenticate username using each of methods in order. nextService is the Service that will be enabled on successful authentication.

      Authentication fails if there are no method available, i.e. if all the method failed or there were method available but could not be attempted because the server did not allow them.

      Further attempts may also be made by catching UserAuthException and retrying with this method.

      Specified by:
      authenticate in interface UserAuth
      Parameters:
      username - the user to authenticate
      nextService - the service to set on successful authentication
      method - the AuthMethod's to try
      Returns:
      whether authentication was successful
      Throws:
      UserAuthException - in case of authentication failure
      TransportException - if there was a transport-layer error
    • getBanner

      public String getBanner()
      Description copied from interface: UserAuth
      Returns the authentication banner (if any). In some cases this is available even before the first authentication request has been made.
      Specified by:
      getBanner in interface UserAuth
      Returns:
      the banner, or an empty string if none was received
    • hadPartialSuccess

      public boolean hadPartialSuccess()
      Specified by:
      hadPartialSuccess in interface UserAuth
      Returns:
      whether authentication was partially successful. Some server's may be configured to require multiple authentications; and this value will be true if at least one of the method supplied succeeded.
    • getAllowedMethods

      public Collection<String> getAllowedMethods()
      Description copied from interface: UserAuth
      The available authentication methods. This is only defined once an unsuccessful authentication has taken place.
      Specified by:
      getAllowedMethods in interface UserAuth
    • handle

      public void handle(Message msg, SSHPacket buf) throws SSHException
      Description copied from interface: SSHPacketHandler
      Delegate handling of some SSH packet to this object.
      Specified by:
      handle in interface SSHPacketHandler
      Overrides:
      handle in class AbstractService
      Parameters:
      msg - the SSH message identifier
      buf - SSHPacket containing rest of the request
      Throws:
      SSHException - if there is a non-recoverable error
    • notifyError

      public void notifyError(SSHException error)
      Description copied from interface: ErrorNotifiable
      Notifies this object of an error.
      Specified by:
      notifyError in interface ErrorNotifiable
      Overrides:
      notifyError in class AbstractService
    • makeAuthParams

      private AuthParams makeAuthParams(String username, Service nextService)