Class InteractivePasswordIdentityProvider

java.lang.Object
org.apache.sshd.contrib.client.auth.password.InteractivePasswordIdentityProvider
All Implemented Interfaces:
Iterator<String>, org.apache.sshd.client.session.ClientSessionHolder, org.apache.sshd.common.session.SessionContextHolder, org.apache.sshd.common.session.SessionHolder<org.apache.sshd.client.session.ClientSession>

public class InteractivePasswordIdentityProvider extends Object implements Iterator<String>, org.apache.sshd.common.session.SessionHolder<org.apache.sshd.client.session.ClientSession>, org.apache.sshd.client.session.ClientSessionHolder

Helps implement a PasswordIdentityProvider by delegating calls to UserInteraction.getUpdatedPassword(ClientSession, String, String). The way to use it would be as follows:


try (ClientSession session = client.connect(login, host, port).await().getSession()) {
    session.setUserInteraction(...);     // this can also be set at the client level
    PasswordIdentityProvider passwordIdentityProvider =
         InteractivePasswordIdentityProvider.providerOf(session, "My prompt");
    session.setPasswordIdentityProvider(passwordIdentityProvider);
    session.auth.verify(...timeout...);
}

or

UserInteraction ui = ....;
try (ClientSession session = client.connect(login, host, port).await().getSession()) {
    PasswordIdentityProvider passwordIdentityProvider =
         InteractivePasswordIdentityProvider.providerOf(session, ui, "My prompt");
    session.setPasswordIdentityProvider(passwordIdentityProvider);
    session.auth.verify(...timeout...);
}

Note: UserInteraction.isInteractionAllowed(ClientSession) is consulted prior to invoking getUpdatedPassword - if returns false then password retrieval method is not invoked, and it is assumed that no more passwords are available
Author:
Apache MINA SSHD Project
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Special marker to indicate that we exhausted all attempts
  • Constructor Summary

    Constructors
    Constructor
    Description
    InteractivePasswordIdentityProvider(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.sshd.client.session.ClientSession
     
     
    org.apache.sshd.client.session.ClientSession
     
    org.apache.sshd.client.auth.keyboard.UserInteraction
     
    boolean
     
     
    static org.apache.sshd.client.auth.password.PasswordIdentityProvider
    providerOf(org.apache.sshd.client.session.ClientSession clientSession, String prompt)
     
    static org.apache.sshd.client.auth.password.PasswordIdentityProvider
    providerOf(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt)
     
    protected String
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Iterator

    forEachRemaining, remove

    Methods inherited from interface org.apache.sshd.common.session.SessionHolder

    getSessionContext
  • Field Details

  • Constructor Details

    • InteractivePasswordIdentityProvider

      public InteractivePasswordIdentityProvider(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt)
  • Method Details

    • getClientSession

      public org.apache.sshd.client.session.ClientSession getClientSession()
      Specified by:
      getClientSession in interface org.apache.sshd.client.session.ClientSessionHolder
    • getSession

      public org.apache.sshd.client.session.ClientSession getSession()
      Specified by:
      getSession in interface org.apache.sshd.common.session.SessionHolder<org.apache.sshd.client.session.ClientSession>
    • getUserInteraction

      public org.apache.sshd.client.auth.keyboard.UserInteraction getUserInteraction()
    • getPrompt

      public String getPrompt()
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<String>
    • next

      public String next()
      Specified by:
      next in interface Iterator<String>
    • resolveNextPassword

      protected String resolveNextPassword()
    • providerOf

      public static org.apache.sshd.client.auth.password.PasswordIdentityProvider providerOf(org.apache.sshd.client.session.ClientSession clientSession, String prompt)
    • providerOf

      public static org.apache.sshd.client.auth.password.PasswordIdentityProvider providerOf(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt)