Class InteractivePasswordIdentityProvider
java.lang.Object
org.apache.sshd.contrib.client.auth.password.InteractivePasswordIdentityProvider
- All Implemented Interfaces:
Iterator<String>,ClientSessionHolder,SessionContextHolder,SessionHolder<ClientSession>
public class InteractivePasswordIdentityProvider
extends Object
implements Iterator<String>, SessionHolder<ClientSession>, 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
FieldsModifier and TypeFieldDescriptionprivate ClientSessionprotected static final StringSpecial marker to indicate that we exhausted all attemptsprivate AtomicReference<String>private Stringprivate UserInteraction -
Constructor Summary
ConstructorsConstructorDescriptionInteractivePasswordIdentityProvider(ClientSession clientSession, UserInteraction userInteraction, String prompt) -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNext()next()static PasswordIdentityProviderproviderOf(ClientSession clientSession, String prompt) static PasswordIdentityProviderproviderOf(ClientSession clientSession, UserInteraction userInteraction, String prompt) protected StringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, removeMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Field Details
-
EOF
Special marker to indicate that we exhausted all attempts- See Also:
-
clientSession
-
userInteraction
-
prompt
-
nextPassword
-
-
Constructor Details
-
InteractivePasswordIdentityProvider
public InteractivePasswordIdentityProvider(ClientSession clientSession, UserInteraction userInteraction, String prompt)
-
-
Method Details
-
getClientSession
- Specified by:
getClientSessionin interfaceClientSessionHolder- Returns:
- The underlying
ClientSessionused
-
getSession
- Specified by:
getSessionin interfaceSessionHolder<ClientSession>
-
getUserInteraction
-
getPrompt
-
hasNext
public boolean hasNext() -
next
-
resolveNextPassword
-
providerOf
-
providerOf
public static PasswordIdentityProvider providerOf(ClientSession clientSession, UserInteraction userInteraction, String prompt)
-