Class InteractivePasswordIdentityProvider
- java.lang.Object
-
- org.apache.sshd.contrib.client.auth.password.InteractivePasswordIdentityProvider
-
- All Implemented Interfaces:
java.util.Iterator<java.lang.String>,ClientSessionHolder,SessionContextHolder,SessionHolder<ClientSession>
public class InteractivePasswordIdentityProvider extends java.lang.Object implements java.util.Iterator<java.lang.String>, SessionHolder<ClientSession>, ClientSessionHolder
Helps implement a
PasswordIdentityProviderby delegating calls toUserInteraction.getUpdatedPassword(ClientSession, String, String). The way to use it would be as follows:
Note: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...); }UserInteraction.isInteractionAllowed(ClientSession)is consulted prior to invokinggetUpdatedPassword- if returnsfalsethen 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 ClientSessionclientSessionprotected static java.lang.StringEOFSpecial marker to indicate that we exhausted all attemptsprivate java.util.concurrent.atomic.AtomicReference<java.lang.String>nextPasswordprivate java.lang.Stringpromptprivate UserInteractionuserInteraction
-
Constructor Summary
Constructors Constructor Description InteractivePasswordIdentityProvider(ClientSession clientSession, UserInteraction userInteraction, java.lang.String prompt)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientSessiongetClientSession()java.lang.StringgetPrompt()ClientSessiongetSession()UserInteractiongetUserInteraction()booleanhasNext()java.lang.Stringnext()static PasswordIdentityProviderproviderOf(ClientSession clientSession, java.lang.String prompt)static PasswordIdentityProviderproviderOf(ClientSession clientSession, UserInteraction userInteraction, java.lang.String prompt)protected java.lang.StringresolveNextPassword()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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 ClientSession clientSession
-
userInteraction
private UserInteraction userInteraction
-
prompt
private java.lang.String prompt
-
nextPassword
private java.util.concurrent.atomic.AtomicReference<java.lang.String> nextPassword
-
-
Constructor Detail
-
InteractivePasswordIdentityProvider
public InteractivePasswordIdentityProvider(ClientSession clientSession, UserInteraction userInteraction, java.lang.String prompt)
-
-
Method Detail
-
getClientSession
public ClientSession getClientSession()
- Specified by:
getClientSessionin interfaceClientSessionHolder- Returns:
- The underlying
ClientSessionused
-
getSession
public ClientSession getSession()
- Specified by:
getSessionin interfaceSessionHolder<ClientSession>
-
getUserInteraction
public UserInteraction getUserInteraction()
-
getPrompt
public java.lang.String getPrompt()
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<java.lang.String>
-
next
public java.lang.String next()
- Specified by:
nextin interfacejava.util.Iterator<java.lang.String>
-
resolveNextPassword
protected java.lang.String resolveNextPassword()
-
providerOf
public static PasswordIdentityProvider providerOf(ClientSession clientSession, java.lang.String prompt)
-
providerOf
public static PasswordIdentityProvider providerOf(ClientSession clientSession, UserInteraction userInteraction, java.lang.String prompt)
-
-