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 Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.sshd.client.session.ClientSessionprotected static final StringSpecial marker to indicate that we exhausted all attemptsprivate AtomicReference<String> private Stringprivate org.apache.sshd.client.auth.keyboard.UserInteraction -
Constructor Summary
ConstructorsConstructorDescriptionInteractivePasswordIdentityProvider(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt) -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.sshd.client.session.ClientSessionorg.apache.sshd.client.session.ClientSessionorg.apache.sshd.client.auth.keyboard.UserInteractionbooleanhasNext()next()static org.apache.sshd.client.auth.password.PasswordIdentityProviderproviderOf(org.apache.sshd.client.session.ClientSession clientSession, String prompt) static org.apache.sshd.client.auth.password.PasswordIdentityProviderproviderOf(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction, String prompt) protected StringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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
private org.apache.sshd.client.session.ClientSession clientSession -
userInteraction
private org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction -
prompt
-
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:
getClientSessionin interfaceorg.apache.sshd.client.session.ClientSessionHolder
-
getSession
public org.apache.sshd.client.session.ClientSession getSession()- Specified by:
getSessionin interfaceorg.apache.sshd.common.session.SessionHolder<org.apache.sshd.client.session.ClientSession>
-
getUserInteraction
public org.apache.sshd.client.auth.keyboard.UserInteraction getUserInteraction() -
getPrompt
-
hasNext
-
next
-
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)
-