public class DefaultSessionFactory extends Object implements ISessionFactory
SessionFactory. This class provides sane defaults for all
conventional configuration including
user.namejsch.dotSsh, or
system property user.home concatenated with
"/.ssh"jsch.knownHosts.file or,
.ssh directory concatenated with "/known_hosts".jsch.privateKey.files split on ",", otherwise, .ssh
directory concatenated with all 3 of "/id_rsa",
"/id_dsa", and "/id_ecdsa" if they exist.| Modifier and Type | Field and Description |
|---|---|
static String |
PROPERTY_JSCH_DOT_SSH |
static String |
PROPERTY_JSCH_KNOWN_HOSTS_FILE |
static String |
PROPERTY_JSCH_PRIVATE_KEY_FILES |
SSH_PORT| Constructor and Description |
|---|
DefaultSessionFactory()
Creates a default DefaultSessionFactory.
|
DefaultSessionFactory(String username,
String hostname,
int port)
Constructs a DefaultSessionFactory with the supplied properties.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getHostname() |
int |
getPort() |
com.jcraft.jsch.Proxy |
getProxy() |
com.jcraft.jsch.UserInfo |
getUserInfo() |
String |
getUsername() |
com.jcraft.jsch.Session |
newSession() |
AbstractSessionFactoryBuilder |
newSessionFactoryBuilder()
Returns a builder for another session factory pre-initialized with the
configuration for this session factory.
|
void |
setConfig(com.helger.commons.collection.impl.ICommonsMap<String,String> config)
Sets the configuration options for the sessions created by this factory.
|
void |
setConfig(String key,
String value)
Adds a single configuration options for the sessions created by this
factory.
|
void |
setHostname(String hostname)
Sets the hostname.
|
void |
setIdentitiesFromPrivateKeys(List<String> privateKeys)
Configures this factory to use a list of identities authenticated by the
supplied private keys.
|
void |
setIdentityFromPrivateKey(String privateKey)
Configures this factory to use a single identity authenticated by the
supplied private key.
|
void |
setIdentityFromPrivateKey(String privateKey,
String passPhrase)
Configures this factory to use a single identity authenticated by the
supplied private key and pass phrase.
|
void |
setIdentityRepository(com.jcraft.jsch.IdentityRepository identityRepository)
Sets the
IdentityRepository for this factory. |
void |
setKnownHosts(InputStream knownHosts)
Sets the known hosts from the stream.
|
void |
setKnownHosts(String knownHosts)
Sets the known hosts from a file at path
knownHosts. |
void |
setPassword(String password)
Sets the
password used to authenticate username. |
void |
setPort(int port)
Sets the port.
|
void |
setProxy(com.jcraft.jsch.Proxy proxy)
Sets the proxy through which all connections will be piped.
|
void |
setUserInfo(com.jcraft.jsch.UserInfo userInfo)
Sets the
UserInfo for use with keyboard-interactive
authentication. |
void |
setUsername(String username)
Sets the username.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAsStringpublic static final String PROPERTY_JSCH_DOT_SSH
public static final String PROPERTY_JSCH_KNOWN_HOSTS_FILE
public static final String PROPERTY_JSCH_PRIVATE_KEY_FILES
public DefaultSessionFactory()
public void setConfig(com.helger.commons.collection.impl.ICommonsMap<String,String> config)
config
map. If you want to add, rather than replace, see
setConfig(String, String). All of these options will be added one
at a time using Session.setConfig(String, String). Details on the supported options can be
found in the source for com.jcraft.jsch.Session#applyConfig()config - The configuration optionsSession.setConfig(java.util.Hashtable)public void setConfig(@Nonnull String key, @Nonnull String value)
com.jcraft.jsch.Session#applyConfig()key - The name of the optionvalue - The value of the optionsetConfig(ICommonsMap),
Session.setConfig(java.util.Hashtable)public String getHostname()
getHostname in interface ISessionFactorypublic void setHostname(String hostname)
hostname - The hostname.public void setPassword(String password)
password used to authenticate username. This mode
of authentication is not recommended as it would keep the password in
memory and if the application dies and writes a heap dump, it would be
available. Using Identity would be better, or even using ssh agent
support.password - the password for usernamepublic int getPort()
getPort in interface ISessionFactorypublic void setPort(int port)
port - The portpublic com.jcraft.jsch.Proxy getProxy()
getProxy in interface ISessionFactorynull will be returned.public void setProxy(com.jcraft.jsch.Proxy proxy)
proxy - The proxypublic String getUsername()
getUsername in interface ISessionFactorypublic void setUsername(String username)
username - The usernamepublic com.jcraft.jsch.UserInfo getUserInfo()
getUserInfo in interface ISessionFactorypublic void setUserInfo(com.jcraft.jsch.UserInfo userInfo)
UserInfo for use with keyboard-interactive
authentication. This may be useful, however, setting the password with
setPassword(String) is likely sufficient.userInfo - User infopublic void setIdentityFromPrivateKey(String privateKey) throws com.jcraft.jsch.JSchException
IdentityRepository
before adding this key.privateKey - Path to a private key filecom.jcraft.jsch.JSchException - If the key is invalidpublic void setIdentityFromPrivateKey(String privateKey, String passPhrase) throws com.jcraft.jsch.JSchException
IdentityRepository before adding this key.privateKey - Path to a private key filepassPhrase - Pass phrase for private keycom.jcraft.jsch.JSchException - If the key is invalidpublic void setIdentitiesFromPrivateKeys(List<String> privateKeys) throws com.jcraft.jsch.JSchException
IdentityRepository before adding these keys.privateKeys - A list of paths to private key filescom.jcraft.jsch.JSchException - If one (or more) of the keys are invalidpublic void setIdentityRepository(com.jcraft.jsch.IdentityRepository identityRepository)
IdentityRepository for this factory. This will replace any
current IdentityRepository, so you should be sure to call this before any
of the setIdentit(y|ies)Xxx if you plan on using both.identityRepository - The identity repositoryJSch.setIdentityRepository(IdentityRepository)public void setKnownHosts(InputStream knownHosts) throws com.jcraft.jsch.JSchException
knownHosts - A stream of known hostscom.jcraft.jsch.JSchException - If an I/O error occursJSch.setKnownHosts(InputStream)public void setKnownHosts(String knownHosts) throws com.jcraft.jsch.JSchException
knownHosts.knownHosts - The path to a known hosts filecom.jcraft.jsch.JSchException - If an I/O error occursJSch.setKnownHosts(String)public com.jcraft.jsch.Session newSession()
throws com.jcraft.jsch.JSchException
newSession in interface ISessionFactorycom.jcraft.jsch.JSchException - If username or hostname are invalidJSch.getSession(String, String, int)public AbstractSessionFactoryBuilder newSessionFactoryBuilder()
ISessionFactorynewSessionFactoryBuilder in interface ISessionFactoryCopyright © 2020 Philip Helger. All rights reserved.