public abstract class JschConfigSessionFactory extends SshSessionFactory
$HOME/.ssh
.
This is the default implementation used by JGit and provides most of the compatibility necessary to match OpenSSH, a popular implementation of SSH used by C Git.
The factory does not provide UI behavior. Override the method
configure(org.eclipse.jgit.transport.OpenSshConfig.Host, Session)
to
supply appropriate UserInfo
to the session.
Modifier and Type | Class and Description |
---|---|
private static class |
JschConfigSessionFactory.JschBugFixingConfigRepository |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,com.jcraft.jsch.JSch> |
byIdentityFile
We use different Jsch instances for hosts that have an IdentityFile
configured in ~/.ssh/config.
|
private OpenSshConfig |
config |
private com.jcraft.jsch.JSch |
defaultJSch |
private static org.slf4j.Logger |
LOG |
Constructor and Description |
---|
JschConfigSessionFactory() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
configure(OpenSshConfig.Host hc,
com.jcraft.jsch.Session session)
Provide additional configuration for the session based on the host
information.
|
protected void |
configureJSch(com.jcraft.jsch.JSch jsch)
Provide additional configuration for the JSch instance.
|
private void |
copyConfigValueToSession(com.jcraft.jsch.Session session,
com.jcraft.jsch.ConfigRepository.Config cfg,
java.lang.String from,
java.lang.String to) |
protected com.jcraft.jsch.JSch |
createDefaultJSch(FS fs)
Create default instance of jsch
|
(package private) com.jcraft.jsch.Session |
createSession(CredentialsProvider credentialsProvider,
FS fs,
java.lang.String user,
java.lang.String pass,
java.lang.String host,
int port,
OpenSshConfig.Host hc) |
protected com.jcraft.jsch.Session |
createSession(OpenSshConfig.Host hc,
java.lang.String user,
java.lang.String host,
int port,
FS fs)
Create a new remote session for the requested address.
|
protected com.jcraft.jsch.JSch |
getJSch(OpenSshConfig.Host hc,
FS fs)
Obtain the JSch used to create new sessions.
|
RemoteSession |
getSession(URIish uri,
CredentialsProvider credentialsProvider,
FS fs,
int tms)
Open (or reuse) a session to a host.
|
private static java.lang.String |
hostName(com.jcraft.jsch.Session s) |
private static void |
identities(com.jcraft.jsch.JSch sch,
FS fs) |
private static boolean |
isAuthenticationCanceled(com.jcraft.jsch.JSchException e) |
private static boolean |
isAuthenticationFailed(com.jcraft.jsch.JSchException e) |
private static void |
knownHosts(com.jcraft.jsch.JSch sch,
FS fs) |
private static void |
loadIdentity(com.jcraft.jsch.JSch sch,
java.io.File priv) |
private void |
safeConfig(com.jcraft.jsch.Session session,
com.jcraft.jsch.ConfigRepository.Config cfg) |
(package private) void |
setConfig(OpenSshConfig config)
Set the
OpenSshConfig to use. |
private static void |
setPreferredKeyTypesOrder(com.jcraft.jsch.Session session) |
private void |
setUserName(com.jcraft.jsch.Session session,
java.lang.String userName) |
getInstance, getLocalUserName, releaseSession, setInstance
private static final org.slf4j.Logger LOG
private final java.util.Map<java.lang.String,com.jcraft.jsch.JSch> byIdentityFile
private com.jcraft.jsch.JSch defaultJSch
private OpenSshConfig config
public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException
A reasonable UserInfo that can interact with the end-user (if necessary) is installed on the returned session by this method.
The caller must connect the session by invoking connect()
if
it has not already been connected.
getSession
in class SshSessionFactory
uri
- URI information about the remote hostcredentialsProvider
- provider to support authentication, may be null.fs
- the file system abstraction which will be necessary to perform
certain file system operations.tms
- Timeout value, in milliseconds.TransportException
- the session could not be created.private static boolean isAuthenticationFailed(com.jcraft.jsch.JSchException e)
private static boolean isAuthenticationCanceled(com.jcraft.jsch.JSchException e)
com.jcraft.jsch.Session createSession(CredentialsProvider credentialsProvider, FS fs, java.lang.String user, java.lang.String pass, java.lang.String host, int port, OpenSshConfig.Host hc) throws com.jcraft.jsch.JSchException
com.jcraft.jsch.JSchException
private void safeConfig(com.jcraft.jsch.Session session, com.jcraft.jsch.ConfigRepository.Config cfg)
private static void setPreferredKeyTypesOrder(com.jcraft.jsch.Session session)
private static java.lang.String hostName(com.jcraft.jsch.Session s)
private void copyConfigValueToSession(com.jcraft.jsch.Session session, com.jcraft.jsch.ConfigRepository.Config cfg, java.lang.String from, java.lang.String to)
private void setUserName(com.jcraft.jsch.Session session, java.lang.String userName)
protected com.jcraft.jsch.Session createSession(OpenSshConfig.Host hc, java.lang.String user, java.lang.String host, int port, FS fs) throws com.jcraft.jsch.JSchException
hc
- host configurationuser
- login to authenticate as.host
- server name to connect to.port
- port number of the SSH daemon (typically 22).fs
- the file system abstraction which will be necessary to
perform certain file system operations.com.jcraft.jsch.JSchException
- the session could not be created.protected void configureJSch(com.jcraft.jsch.JSch jsch)
IdentityRepository
.jsch
- jsch instanceprotected abstract void configure(OpenSshConfig.Host hc, com.jcraft.jsch.Session session)
UserInfo
.hc
- host configurationsession
- session to configureprotected com.jcraft.jsch.JSch getJSch(OpenSshConfig.Host hc, FS fs) throws com.jcraft.jsch.JSchException
hc
- host configurationfs
- the file system abstraction which will be necessary to
perform certain file system operations.com.jcraft.jsch.JSchException
- the user configuration could not be created.protected com.jcraft.jsch.JSch createDefaultJSch(FS fs) throws com.jcraft.jsch.JSchException
fs
- the file system abstraction which will be necessary to perform
certain file system operations.com.jcraft.jsch.JSchException
- known host keys cannot be loaded.private static void knownHosts(com.jcraft.jsch.JSch sch, FS fs) throws com.jcraft.jsch.JSchException
com.jcraft.jsch.JSchException
private static void identities(com.jcraft.jsch.JSch sch, FS fs)
private static void loadIdentity(com.jcraft.jsch.JSch sch, java.io.File priv)
void setConfig(OpenSshConfig config)
OpenSshConfig
to use. Intended for use in tests.config
- to use