public class DefaultSessionFactory extends java.lang.Object implements SessionFactory
SessionFactory. This class provides sane defaults for all
conventional configuration including
username: System property user.name
hostname: localhost
port: 22
.ssh directory: System property jsch.dotSsh, or system
property user.home concatenated with "/.ssh"
known hosts: System property jsch.knownHosts.file or,
.ssh directory concatenated with "/known_hosts".
private keys: First checks for an agent proxy using
ConnectorFactory.createConnector(), then system property
jsch.privateKey.files split on ",", otherwise, .ssh
directory concatenated with all 3 of "/id_rsa",
"/id_dsa", and "/id_ecdsa" if they exist.
SessionFactory.SessionFactoryBuilder| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
PROPERTY_JSCH_DOT_SSH |
static java.lang.String |
PROPERTY_JSCH_KNOWN_HOSTS_FILE |
static java.lang.String |
PROPERTY_JSCH_PRIVATE_KEY_FILES |
SSH_PORT| Constructor and Description |
|---|
DefaultSessionFactory()
Creates a default DefaultSessionFactory.
|
DefaultSessionFactory(java.lang.String username,
java.lang.String hostname,
java.lang.Integer port)
Constructs a DefaultSessionFactory with the supplied properties.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getHostname()
Returns the hostname that sessions built by this factory will connect to.
|
int |
getPort()
Returns the port that sessions built by this factory will connect to.
|
com.jcraft.jsch.Proxy |
getProxy()
Returns the proxy that sessions built by this factory will connect
through, if any.
|
com.jcraft.jsch.UserInfo |
getUserInfo()
Returns the userInfo that sessions built by this factory will connect
with.
|
java.lang.String |
getUsername()
Returns the username that sessions built by this factory will connect
with.
|
com.jcraft.jsch.Session |
newSession()
Returns a new session using the configured properties.
|
SessionFactory.SessionFactoryBuilder |
newSessionFactoryBuilder()
Returns a builder for another session factory pre-initialized with the
configuration for this session factory.
|
void |
setConfig(java.util.Map<java.lang.String,java.lang.String> config)
Sets the configuration options for the sessions created by this factory.
|
void |
setConfig(java.lang.String key,
java.lang.String value)
Adds a single configuration options for the sessions created by this
factory.
|
void |
setHostname(java.lang.String hostname)
Sets the hostname.
|
void |
setIdentitiesFromPrivateKeys(java.util.List<java.lang.String> privateKeys)
Configures this factory to use a list of identities authenticated by the
supplied private keys.
|
void |
setIdentityFromPrivateKey(java.lang.String privateKey)
Configures this factory to use a single identity authenticated by the
supplied private key.
|
void |
setIdentityFromPrivateKey(java.lang.String privateKey,
java.lang.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(java.io.InputStream knownHosts)
Sets the known hosts from the stream.
|
void |
setKnownHosts(java.lang.String knownHosts)
Sets the known hosts from a file at path
knownHosts. |
void |
setPassword(java.lang.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(java.lang.String username)
Sets the username.
|
java.lang.String |
toString() |
public static final java.lang.String PROPERTY_JSCH_DOT_SSH
public static final java.lang.String PROPERTY_JSCH_KNOWN_HOSTS_FILE
public static final java.lang.String PROPERTY_JSCH_PRIVATE_KEY_FILES
public DefaultSessionFactory()
public DefaultSessionFactory(java.lang.String username,
java.lang.String hostname,
java.lang.Integer port)
username - The usernamehostname - The hostnameport - The portpublic java.lang.String getHostname()
SessionFactorygetHostname in interface SessionFactorypublic int getPort()
SessionFactorygetPort in interface SessionFactorypublic com.jcraft.jsch.Proxy getProxy()
SessionFactorynull will be
returned.getProxy in interface SessionFactorypublic java.lang.String getUsername()
SessionFactorygetUsername in interface SessionFactorypublic com.jcraft.jsch.UserInfo getUserInfo()
SessionFactorygetUserInfo in interface SessionFactorypublic com.jcraft.jsch.Session newSession()
throws com.jcraft.jsch.JSchException
SessionFactorynewSession in interface SessionFactorycom.jcraft.jsch.JSchException - If username or hostname are invalidJSch.getSession(String, String, int)public SessionFactory.SessionFactoryBuilder newSessionFactoryBuilder()
SessionFactorynewSessionFactoryBuilder in interface SessionFactorypublic void setConfig(java.util.Map<java.lang.String,java.lang.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 Session.applyConfig().config - The configuration optionsSession.setConfig(java.util.Hashtable),
Session.applyConfig()public void setConfig(java.lang.String key,
java.lang.String value)
Session.applyConfig().key - The name of the optionvalue - The value of the optionsetConfig(Map),
Session.setConfig(java.util.Hashtable),
Session.applyConfig()public void setHostname(java.lang.String hostname)
hostname - The hostname.public void setIdentityFromPrivateKey(java.lang.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(java.lang.String privateKey,
java.lang.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(java.util.List<java.lang.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(java.io.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(java.lang.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 void setPassword(java.lang.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 void setPort(int port)
port - The portpublic void setProxy(com.jcraft.jsch.Proxy proxy)
proxy - The proxypublic 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 - public void setUsername(java.lang.String username)
username - The usernamepublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2018 pastdev.com. All Rights Reserved.