Package org.apache.sshd.client
Class SshClient
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,ClientAuthenticationManager,ClientFactoryManager,ClientIdentityLoaderHolder,ClientIdentityLoaderManager,ClientProxyConnectorHolder,ClientSessionCreator,AttributeRepository,AttributeStore,UserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>,ChannelListenerManager,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,Closeable,FilePasswordProviderHolder,FilePasswordProviderManager,FactoryManager,PortForwardingEventListenerManager,IoServiceEventListenerManager,KexExtensionHandlerManager,KexFactoryManager,KeyIdentityProviderHolder,PropertyResolver,ReservedSessionMessagesManager,SessionDisconnectHandlerManager,SessionHeartbeatController,SessionListenerManager,UnknownChannelReferenceHandlerManager,SignatureFactoriesHolder,SignatureFactoriesManager
public class SshClient extends AbstractFactoryManager implements ClientFactoryManager, Closeable
Entry point for the client side of the SSH protocol.
The default configured client can be created using the
setUpDefaultClient(). The next step is to configure and then start the client using thestart()method.Sessions can then be created using on of the
ClientSessionCreator.connect(String, String, int)orClientSessionCreator.connect(String, java.net.SocketAddress)methods.The client can be stopped any time using the
stop()method.Following is an example of using the
SshClient:
Note: the idea is to have onetry (SshClient client = SshClient.setUpDefaultClient()) { ...further configuration of the client... client.start(); try (ClientSession session = client.connect(login, host, port) .verify(...timeout...) .getSession()) { session.addPasswordIdentity(password); session.auth().verify(...timeout...); try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) { channel.setIn(new NoCloseInputStream(System.in)); channel.setOut(new NoCloseOutputStream(System.out)); channel.setErr(new NoCloseOutputStream(System.err)); channel.open(); channel.waitFor(ClientChannel.CLOSED, 0); } finally { session.close(false); } } finally { client.stop(); } }SshClientinstance for the entire application and re-use it repeatedly in order to create as many sessions as necessary - possibly with different hosts, ports, users, passwords, etc. - including concurrently. In other words, except for exceptional cases, it is recommended to initialize one instance ofSshClientfor the application and then use throughout - including for multi-threading. As long as theSshClientis not re-configured it should be multi-thread safe regardless of the target session being created.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
-
Field Summary
-
Fields inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListeners
-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.client.session.ClientSessionCreator
TARGET_SERVER
-
Fields inherited from interface org.apache.sshd.common.FactoryManager
DEFAULT_VERSION
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
-
Constructor Summary
Constructors Constructor Description SshClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPasswordIdentity(java.lang.String password)voidaddPublicKeyIdentity(java.security.KeyPair kp)protected voidcheckConfig()ConnectFutureconnect(java.lang.String uriStr)Resolves the effectiveHostConfigEntryand connects to itConnectFutureconnect(java.lang.String username, java.lang.String host, int port, AttributeRepository context, java.net.SocketAddress localAddress)Resolves the effectiveHostConfigEntryand connects to itConnectFutureconnect(java.lang.String username, java.net.SocketAddress targetAddress, AttributeRepository context, java.net.SocketAddress localAddress)Resolves the effectiveHostConfigEntryand connects to itConnectFutureconnect(HostConfigEntry hostConfig, AttributeRepository context, java.net.SocketAddress localAddress)protected SshFutureListener<IoConnectFuture>createConnectCompletionListener(ConnectFuture connectFuture, java.lang.String username, java.net.SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig)protected IoConnectorcreateConnector()protected SessionFactorycreateSessionFactory()protected ConnectFuturedoConnect(java.lang.String username, java.net.SocketAddress targetAddress, AttributeRepository context, java.net.SocketAddress localAddress, KeyIdentityProvider identities, HostConfigEntry hostConfig)protected ConnectFuturedoConnect(HostConfigEntry hostConfig, java.util.List<HostConfigEntry> jumps, AttributeRepository context, java.net.SocketAddress localAddress)ClientIdentityLoadergetClientIdentityLoader()ClientProxyConnectorgetClientProxyConnector()FilePasswordProvidergetFilePasswordProvider()HostBasedAuthenticationReportergetHostBasedAuthenticationReporter()HostConfigEntryResolvergetHostConfigEntryResolver()protected CloseablegetInnerCloseable()KeyIdentityProvidergetKeyIdentityProvider()PasswordAuthenticationReportergetPasswordAuthenticationReporter()PasswordIdentityProvidergetPasswordIdentityProvider()RetrievePasswordIdentityProviderused to provide password candidatesPublicKeyAuthenticationReportergetPublicKeyAuthenticationReporter()AuthenticationIdentitiesProvidergetRegisteredIdentities()ServerKeyVerifiergetServerKeyVerifier()Retrieve the server key verifier to be used to check the key when connecting to an SSH server.SessionFactorygetSessionFactory()java.util.List<UserAuthFactory>getUserAuthFactories()Retrieve the list of named factories forUserAuthobjects.UserInteractiongetUserInteraction()booleanisStarted()protected voidonConnectOperationComplete(IoSession ioSession, ConnectFuture connectFuture, java.lang.String username, java.net.SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig)voidopen()protected java.util.List<HostConfigEntry>parseProxyJumps(java.lang.String proxyJump, AttributeRepository context)protected KeyIdentityProviderpreloadClientIdentities(java.util.Collection<? extends NamedResource> locations)java.lang.StringremovePasswordIdentity(java.lang.String password)java.security.KeyPairremovePublicKeyIdentity(java.security.KeyPair kp)protected HostConfigEntryresolveHost(java.lang.String username, java.lang.String host, int port, AttributeRepository context, java.net.SocketAddress localAddress)voidsetClientIdentityLoader(ClientIdentityLoader loader)voidsetClientProxyConnector(ClientProxyConnector proxyConnector)voidsetFilePasswordProvider(FilePasswordProvider provider)voidsetHostBasedAuthenticationReporter(HostBasedAuthenticationReporter reporter)voidsetHostConfigEntryResolver(HostConfigEntryResolver resolver)voidsetKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider)static <C extends SshClient>
CsetKeyPairProvider(C client, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)static <C extends SshClient>
CsetKeyPairProvider(C client, java.nio.file.Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)voidsetPasswordAuthenticationReporter(PasswordAuthenticationReporter reporter)voidsetPasswordIdentityProvider(PasswordIdentityProvider provider)voidsetPublicKeyAuthenticationReporter(PublicKeyAuthenticationReporter reporter)voidsetServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)voidsetSessionFactory(SessionFactory sessionFactory)static SshClientsetUpDefaultClient()Setup a default client.protected voidsetupDefaultSessionIdentities(ClientSession session, KeyIdentityProvider extraIdentities)static SimpleClientsetUpDefaultSimpleClient()Setup a default client, starts it and then wraps it as aSimpleClientvoidsetUserAuthFactories(java.util.List<UserAuthFactory> userAuthFactories)voidsetUserInteraction(UserInteraction userInteraction)voidstart()Starts the SSH client and can start creating sessions using it.voidstop()java.lang.StringtoString()static SimpleClientwrapAsSimpleClient(SshClient client)Wraps anSshClientinstance as aSimpleClient-
Methods inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
addChannelListener, addPortForwardingEventListener, addSessionListener, attributeKeys, clearAttributes, computeAttributeIfAbsent, createSessionTimeoutListener, getAgentFactory, getAttribute, getAttributesCount, getChannelFactories, getChannelListenerProxy, getChannelStreamWriterResolver, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceEventListener, getIoServiceFactory, getIoServiceFactoryFactory, getNioWorkers, getParentPropertyResolver, getPortForwardingEventListenerProxy, getProperties, getRandomFactory, getReservedSessionMessagesHandler, getScheduledExecutorService, getServiceFactories, getSessionDisconnectHandler, getSessionListenerProxy, getUnknownChannelReferenceHandler, getVersion, removeAttribute, removeChannelListener, removePortForwardingEventListener, removeSessionListener, removeSessionTimeout, resolveUnknownChannelReferenceHandler, setAgentFactory, setAttribute, setChannelFactories, setChannelStreamWriterResolver, setFileSystemFactory, setForwarderFactory, setForwardingFilter, setGlobalRequestHandlers, setIoServiceEventListener, setIoServiceFactoryFactory, setNioWorkers, setParentPropertyResolver, setRandomFactory, setReservedSessionMessagesHandler, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setupSessionTimeout, stopSessionTimeoutListener
-
Methods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactories
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCount
-
Methods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
-
Methods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListener
-
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
-
Methods inherited from interface org.apache.sshd.client.ClientAuthenticationManager
setUserAuthFactoriesNames
-
Methods inherited from interface org.apache.sshd.client.session.ClientSessionCreator
connect, connect, connect, connect, connect, connect, connect, connect, connect
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttribute
-
Methods inherited from interface org.apache.sshd.common.io.IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListener
-
Methods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandler
-
Methods inherited from interface org.apache.sshd.common.kex.KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty
-
Methods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandler
-
Methods inherited from interface org.apache.sshd.common.session.SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandler
-
Methods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeat
-
Methods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListener
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandler
-
Methods inherited from interface org.apache.sshd.common.auth.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
-
-
-
Field Detail
-
DEFAULT_USER_AUTH_FACTORIES
public static final java.util.List<UserAuthFactory> DEFAULT_USER_AUTH_FACTORIES
Default user authentication preferences if not set- See Also:
- ssh_config(5) - PreferredAuthentications
-
DEFAULT_SERVICE_FACTORIES
public static final java.util.List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
-
connector
protected IoConnector connector
-
sessionFactory
protected SessionFactory sessionFactory
-
userAuthFactories
protected java.util.List<UserAuthFactory> userAuthFactories
-
proxyConnector
private ClientProxyConnector proxyConnector
-
serverKeyVerifier
private ServerKeyVerifier serverKeyVerifier
-
hostConfigEntryResolver
private HostConfigEntryResolver hostConfigEntryResolver
-
clientIdentityLoader
private ClientIdentityLoader clientIdentityLoader
-
keyIdentityProvider
private KeyIdentityProvider keyIdentityProvider
-
publicKeyAuthenticationReporter
private PublicKeyAuthenticationReporter publicKeyAuthenticationReporter
-
filePasswordProvider
private FilePasswordProvider filePasswordProvider
-
passwordIdentityProvider
private PasswordIdentityProvider passwordIdentityProvider
-
passwordAuthenticationReporter
private PasswordAuthenticationReporter passwordAuthenticationReporter
-
hostBasedAuthenticationReporter
private HostBasedAuthenticationReporter hostBasedAuthenticationReporter
-
userInteraction
private UserInteraction userInteraction
-
identities
private final java.util.List<java.lang.Object> identities
-
identitiesProvider
private final AuthenticationIdentitiesProvider identitiesProvider
-
started
private final java.util.concurrent.atomic.AtomicBoolean started
-
-
Method Detail
-
getSessionFactory
public SessionFactory getSessionFactory()
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
-
getClientProxyConnector
public ClientProxyConnector getClientProxyConnector()
- Specified by:
getClientProxyConnectorin interfaceClientProxyConnectorHolder
-
setClientProxyConnector
public void setClientProxyConnector(ClientProxyConnector proxyConnector)
- Specified by:
setClientProxyConnectorin interfaceClientProxyConnectorHolder
-
getServerKeyVerifier
public ServerKeyVerifier getServerKeyVerifier()
Description copied from interface:ClientAuthenticationManagerRetrieve the server key verifier to be used to check the key when connecting to an SSH server.- Specified by:
getServerKeyVerifierin interfaceClientAuthenticationManager- Returns:
- the
ServerKeyVerifierto use - nevernull
-
setServerKeyVerifier
public void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
- Specified by:
setServerKeyVerifierin interfaceClientAuthenticationManager
-
getHostConfigEntryResolver
public HostConfigEntryResolver getHostConfigEntryResolver()
- Specified by:
getHostConfigEntryResolverin interfaceClientFactoryManager- Returns:
- The
HostConfigEntryResolverto use in order to resolve the effective session parameters - nevernull
-
setHostConfigEntryResolver
public void setHostConfigEntryResolver(HostConfigEntryResolver resolver)
- Specified by:
setHostConfigEntryResolverin interfaceClientFactoryManager
-
getFilePasswordProvider
public FilePasswordProvider getFilePasswordProvider()
- Specified by:
getFilePasswordProviderin interfaceFilePasswordProviderHolder- Returns:
- The
FilePasswordProviderto use if need to load encrypted identities keys - nevernull - See Also:
FilePasswordProvider.EMPTY
-
setFilePasswordProvider
public void setFilePasswordProvider(FilePasswordProvider provider)
- Specified by:
setFilePasswordProviderin interfaceFilePasswordProviderManager
-
getClientIdentityLoader
public ClientIdentityLoader getClientIdentityLoader()
- Specified by:
getClientIdentityLoaderin interfaceClientIdentityLoaderHolder- Returns:
- The
ClientIdentityLoaderto use in order to load client key pair identities - nevernull
-
setClientIdentityLoader
public void setClientIdentityLoader(ClientIdentityLoader loader)
- Specified by:
setClientIdentityLoaderin interfaceClientIdentityLoaderManager
-
getUserInteraction
public UserInteraction getUserInteraction()
- Specified by:
getUserInteractionin interfaceClientAuthenticationManager- Returns:
- A
UserInteractionobject to communicate with the user (may benullto indicate that no such communication is allowed)
-
setUserInteraction
public void setUserInteraction(UserInteraction userInteraction)
- Specified by:
setUserInteractionin interfaceClientAuthenticationManager
-
getPasswordAuthenticationReporter
public PasswordAuthenticationReporter getPasswordAuthenticationReporter()
- Specified by:
getPasswordAuthenticationReporterin interfaceClientAuthenticationManager
-
setPasswordAuthenticationReporter
public void setPasswordAuthenticationReporter(PasswordAuthenticationReporter reporter)
- Specified by:
setPasswordAuthenticationReporterin interfaceClientAuthenticationManager
-
getHostBasedAuthenticationReporter
public HostBasedAuthenticationReporter getHostBasedAuthenticationReporter()
- Specified by:
getHostBasedAuthenticationReporterin interfaceClientAuthenticationManager
-
setHostBasedAuthenticationReporter
public void setHostBasedAuthenticationReporter(HostBasedAuthenticationReporter reporter)
- Specified by:
setHostBasedAuthenticationReporterin interfaceClientAuthenticationManager
-
getUserAuthFactories
public java.util.List<UserAuthFactory> getUserAuthFactories()
Description copied from interface:UserAuthFactoriesManagerRetrieve the list of named factories forUserAuthobjects.- Specified by:
getUserAuthFactoriesin interfaceUserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>- Returns:
- a list of named
UserAuthfactories, nevernull/empty
-
setUserAuthFactories
public void setUserAuthFactories(java.util.List<UserAuthFactory> userAuthFactories)
- Specified by:
setUserAuthFactoriesin interfaceUserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>
-
getRegisteredIdentities
public AuthenticationIdentitiesProvider getRegisteredIdentities()
- Specified by:
getRegisteredIdentitiesin interfaceClientAuthenticationManager- Returns:
- The
AuthenticationIdentitiesProviderto be used for attempting password or public key authentication
-
getPasswordIdentityProvider
public PasswordIdentityProvider getPasswordIdentityProvider()
Description copied from interface:ClientAuthenticationManagerRetrievePasswordIdentityProviderused to provide password candidates- Specified by:
getPasswordIdentityProviderin interfaceClientAuthenticationManager- Returns:
- The
PasswordIdentityProviderinstance - ignored ifnull(i.e., no passwords available). - See Also:
ClientAuthenticationManager.addPasswordIdentity(String)
-
setPasswordIdentityProvider
public void setPasswordIdentityProvider(PasswordIdentityProvider provider)
- Specified by:
setPasswordIdentityProviderin interfaceClientAuthenticationManager
-
addPasswordIdentity
public void addPasswordIdentity(java.lang.String password)
- Specified by:
addPasswordIdentityin interfaceClientAuthenticationManager- Parameters:
password- Password to be added - may not benull/empty. Note: this password is in addition to whatever passwords are available via thePasswordIdentityProvider(if any)
-
removePasswordIdentity
public java.lang.String removePasswordIdentity(java.lang.String password)
- Specified by:
removePasswordIdentityin interfaceClientAuthenticationManager- Parameters:
password- The password to remove - ignored ifnull/empty- Returns:
- The removed password - same one that was added via
ClientAuthenticationManager.addPasswordIdentity(String)- ornullif no match found
-
addPublicKeyIdentity
public void addPublicKeyIdentity(java.security.KeyPair kp)
- Specified by:
addPublicKeyIdentityin interfaceClientAuthenticationManager- Parameters:
kp- TheKeyPairto add - may not benullNote: this key is in addition to whatever keys are available via theKeyIdentityProvider(if any)
-
removePublicKeyIdentity
public java.security.KeyPair removePublicKeyIdentity(java.security.KeyPair kp)
- Specified by:
removePublicKeyIdentityin interfaceClientAuthenticationManager- Parameters:
kp- TheKeyPairto remove - ignored ifnull- Returns:
- The removed
KeyPair- same one that was added viaClientAuthenticationManager.addPublicKeyIdentity(KeyPair)- ornullif no match found
-
getKeyIdentityProvider
public KeyIdentityProvider getKeyIdentityProvider()
- Specified by:
getKeyIdentityProviderin interfaceKeyIdentityProviderHolder- Returns:
- The
KeyIdentityProviderused to provide key-pair(s) for public key authentication
-
setKeyIdentityProvider
public void setKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider)
- Specified by:
setKeyIdentityProviderin interfaceKeyIdentityProviderHolder
-
getPublicKeyAuthenticationReporter
public PublicKeyAuthenticationReporter getPublicKeyAuthenticationReporter()
- Specified by:
getPublicKeyAuthenticationReporterin interfaceClientAuthenticationManager
-
setPublicKeyAuthenticationReporter
public void setPublicKeyAuthenticationReporter(PublicKeyAuthenticationReporter reporter)
- Specified by:
setPublicKeyAuthenticationReporterin interfaceClientAuthenticationManager
-
checkConfig
protected void checkConfig()
- Overrides:
checkConfigin classAbstractFactoryManager
-
isStarted
public boolean isStarted()
-
start
public void start()
Starts the SSH client and can start creating sessions using it. Ignored if alreadystarted.
-
stop
public void stop()
-
open
public void open() throws java.io.IOException- Throws:
java.io.IOException
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
connect
public ConnectFuture connect(java.lang.String uriStr) throws java.io.IOException
Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin interfaceClientSessionCreator- Parameters:
uriStr- The server uri to connect to- Returns:
- A
ConnectFuture - Throws:
java.io.IOException- If failed to resolve the effective target or connect to it- See Also:
ClientSessionCreator.connect(HostConfigEntry)
-
connect
public ConnectFuture connect(java.lang.String username, java.net.SocketAddress targetAddress, AttributeRepository context, java.net.SocketAddress localAddress) throws java.io.IOException
Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin interfaceClientSessionCreator- Parameters:
username- The intended usernametargetAddress- The intended targetSocketAddress- nevernull. If this is anInetSocketAddressthen the effectiveHostConfigEntryis resolved and used.context- An optional "context" to be attached to the established session if successfully connectedlocalAddress- The local address to use - ifnullan automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture - Throws:
java.io.IOException- If failed to resolve the effective target or connect to it
-
connect
public ConnectFuture connect(java.lang.String username, java.lang.String host, int port, AttributeRepository context, java.net.SocketAddress localAddress) throws java.io.IOException
Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin interfaceClientSessionCreator- Parameters:
username- The intended usernamehost- The target host name/address - nevernull/emptyport- The target portcontext- An optional "context" to be attached to the established session if successfully connectedlocalAddress- The local address to use - ifnullan automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture - Throws:
java.io.IOException- If failed to resolve the effective target or connect to it
-
connect
public ConnectFuture connect(HostConfigEntry hostConfig, AttributeRepository context, java.net.SocketAddress localAddress) throws java.io.IOException
- Specified by:
connectin interfaceClientSessionCreator- Parameters:
hostConfig- The effectiveHostConfigEntryto connect to - nevernullcontext- An optional "context" to be attached to the established session if successfully connectedlocalAddress- The local address to use - ifnullan automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture - Throws:
java.io.IOException- If failed to create the connection future
-
doConnect
protected ConnectFuture doConnect(HostConfigEntry hostConfig, java.util.List<HostConfigEntry> jumps, AttributeRepository context, java.net.SocketAddress localAddress) throws java.io.IOException
- Throws:
java.io.IOException
-
doConnect
protected ConnectFuture doConnect(java.lang.String username, java.net.SocketAddress targetAddress, AttributeRepository context, java.net.SocketAddress localAddress, KeyIdentityProvider identities, HostConfigEntry hostConfig) throws java.io.IOException
- Throws:
java.io.IOException
-
parseProxyJumps
protected java.util.List<HostConfigEntry> parseProxyJumps(java.lang.String proxyJump, AttributeRepository context) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveHost
protected HostConfigEntry resolveHost(java.lang.String username, java.lang.String host, int port, AttributeRepository context, java.net.SocketAddress localAddress) throws java.io.IOException
- Throws:
java.io.IOException
-
preloadClientIdentities
protected KeyIdentityProvider preloadClientIdentities(java.util.Collection<? extends NamedResource> locations) throws java.io.IOException
- Throws:
java.io.IOException
-
createConnectCompletionListener
protected SshFutureListener<IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, java.lang.String username, java.net.SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig)
-
onConnectOperationComplete
protected void onConnectOperationComplete(IoSession ioSession, ConnectFuture connectFuture, java.lang.String username, java.net.SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
setupDefaultSessionIdentities
protected void setupDefaultSessionIdentities(ClientSession session, KeyIdentityProvider extraIdentities) throws java.io.IOException, java.security.GeneralSecurityException
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
createConnector
protected IoConnector createConnector()
-
createSessionFactory
protected SessionFactory createSessionFactory()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setUpDefaultSimpleClient
public static SimpleClient setUpDefaultSimpleClient()
Setup a default client, starts it and then wraps it as aSimpleClient- Returns:
- The
SimpleClientwrapper. Note: when the wrapper is closed the client is also stopped - See Also:
setUpDefaultClient(),wrapAsSimpleClient(SshClient)
-
wrapAsSimpleClient
public static SimpleClient wrapAsSimpleClient(SshClient client)
Wraps anSshClientinstance as aSimpleClient- Parameters:
client- The client instance - nevernull. Note: client must be started before the simple client wrapper is used.- Returns:
- The
SimpleClientwrapper. Note: when the wrapper is closed the client is also stopped
-
setUpDefaultClient
public static SshClient setUpDefaultClient()
Setup a default client. The client does not require any additional setup.- Returns:
- a newly create
SshClientwith default configurations
-
setKeyPairProvider
public static <C extends SshClient> C setKeyPairProvider(C client, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Type Parameters:
C- The generic client class- Parameters:
client- TheSshClientto updatedstrict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- The updated client instance - provided a non-
nullKeyPairProviderwas generated - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
setKeyPairProvider(SshClient, Path, boolean, boolean, FilePasswordProvider, LinkOption...)
-
setKeyPairProvider
public static <C extends SshClient> C setKeyPairProvider(C client, java.nio.file.Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Type Parameters:
C- The generic client class- Parameters:
client- TheSshClientto updateddir- The folder to scan for the built-in identitiesstrict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- The updated client instance - provided a non-
nullKeyIdentityProviderwas generated - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
ClientIdentity.loadDefaultKeyPairProvider(Path, boolean, boolean, FilePasswordProvider, LinkOption...)
-
-