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
  • Field Details

    • EOF

      protected static final String EOF
      Special marker to indicate that we exhausted all attempts
      See Also:
    • clientSession

      private org.apache.sshd.client.session.ClientSession clientSession
    • userInteraction

      private org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction
    • prompt

      private String prompt
    • nextPassword

      private AtomicReference<String> nextPassword
  • 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)