Class InteractivePasswordIdentityProvider

  • All Implemented Interfaces:
    java.util.Iterator<java.lang.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 java.lang.Object
    implements java.util.Iterator<java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.sshd.client.session.ClientSession clientSession  
      protected static java.lang.String EOF
      Special marker to indicate that we exhausted all attempts
      private java.util.concurrent.atomic.AtomicReference<java.lang.String> nextPassword  
      private java.lang.String prompt  
      private org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction  
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.sshd.client.session.ClientSession getClientSession()  
      java.lang.String getPrompt()  
      org.apache.sshd.client.session.ClientSession getSession()  
      org.apache.sshd.client.auth.keyboard.UserInteraction getUserInteraction()  
      boolean hasNext()  
      java.lang.String next()  
      static org.apache.sshd.client.auth.password.PasswordIdentityProvider providerOf​(org.apache.sshd.client.session.ClientSession clientSession, java.lang.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, java.lang.String prompt)  
      protected java.lang.String resolveNextPassword()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
      • Methods inherited from interface org.apache.sshd.common.session.SessionHolder

        getSessionContext
    • Field Detail

      • EOF

        protected static final java.lang.String EOF
        Special marker to indicate that we exhausted all attempts
        See Also:
        Constant Field Values
      • clientSession

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

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

        private java.lang.String prompt
      • nextPassword

        private java.util.concurrent.atomic.AtomicReference<java.lang.String> nextPassword
    • Constructor Detail

      • InteractivePasswordIdentityProvider

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

      • 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 java.lang.String getPrompt()
      • hasNext

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

        public java.lang.String next()
        Specified by:
        next in interface java.util.Iterator<java.lang.String>
      • resolveNextPassword

        protected java.lang.String resolveNextPassword()
      • providerOf

        public static org.apache.sshd.client.auth.password.PasswordIdentityProvider providerOf​(org.apache.sshd.client.session.ClientSession clientSession,
                                                                                               java.lang.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,
                                                                                               java.lang.String prompt)