Class InteractivePasswordIdentityProvider
- java.lang.Object
-
- org.apache.sshd.contrib.client.auth.password.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 toUserInteraction.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...); }
UserInteraction.isInteractionAllowed(ClientSession)
is consulted prior to invokinggetUpdatedPassword
- if returnsfalse
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 attemptsprivate 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()
-
-
-
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
-
-
Method Detail
-
getClientSession
public org.apache.sshd.client.session.ClientSession getClientSession()
- Specified by:
getClientSession
in interfaceorg.apache.sshd.client.session.ClientSessionHolder
-
getSession
public org.apache.sshd.client.session.ClientSession getSession()
- Specified by:
getSession
in interfaceorg.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 interfacejava.util.Iterator<java.lang.String>
-
next
public java.lang.String next()
- Specified by:
next
in interfacejava.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)
-
-