Class JschConfigSessionFactory
- java.lang.Object
-
- org.eclipse.jgit.transport.SshSessionFactory
-
- org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory
-
public class JschConfigSessionFactory extends SshSessionFactory
The base session factory that loads known hosts and private keys from$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.ssh.jsch.OpenSshConfig.Host, Session)
to supply appropriateUserInfo
to the session.- Since:
- 6.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JschConfigSessionFactory.JschBugFixingConfigRepository
-
Field Summary
Fields Modifier and Type Field 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 java.lang.String
JSCH
private static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description JschConfigSessionFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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)
private void
copyGlobalConfigIfNotSet(java.lang.String from, java.lang.String to)
protected com.jcraft.jsch.JSch
createDefaultJSch(FS fs)
Create default instance of jschcom.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)
Use for tests onlyprotected 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)
Opens (or reuses) a session to a host.java.lang.String
getType()
The name of the type of session factory.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)
void
setConfig(OpenSshConfig config)
Set theOpenSshConfig
to use.private static void
setPreferredKeyTypesOrder(com.jcraft.jsch.Session session)
private void
setUserName(com.jcraft.jsch.Session session, java.lang.String userName)
-
Methods inherited from class org.eclipse.jgit.transport.SshSessionFactory
getInstance, getLocalUserName, releaseSession, setInstance
-
-
-
-
Field Detail
-
JSCH
private static final java.lang.String JSCH
- See Also:
- Constant Field Values
-
LOG
private static final org.slf4j.Logger LOG
-
byIdentityFile
private final 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. Jsch by default would cache decrypted keys only per session, which results in repeated password prompts. Using different Jsch instances, we can cache the keys on these instances so that they will be re-used for successive sessions, and thus the user is prompted for a key password only once while Eclipse runs.
-
defaultJSch
private com.jcraft.jsch.JSch defaultJSch
-
config
private OpenSshConfig config
-
-
Method Detail
-
getSession
public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException
Opens (or reuses) a session to a host. The returned session is connected and authenticated and is ready for further use.- Specified by:
getSession
in classSshSessionFactory
- Parameters:
uri
- URI of the remote host to connect tocredentialsProvider
- provider to support authentication, may benull
if no user input for authentication is neededfs
- the file system abstraction to use for certain file operations, such as reading configuration filestms
- connection timeout for creating the session, in milliseconds- Returns:
- a connected and authenticated session for communicating with the
remote host given by the
uri
- Throws:
TransportException
- if the session could not be created
-
getType
public java.lang.String getType()
Description copied from class:SshSessionFactory
The name of the type of session factory.- Specified by:
getType
in classSshSessionFactory
- Returns:
- the name of the type of session factory.
-
isAuthenticationFailed
private static boolean isAuthenticationFailed(com.jcraft.jsch.JSchException e)
-
isAuthenticationCanceled
private static boolean isAuthenticationCanceled(com.jcraft.jsch.JSchException e)
-
createSession
public 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
Use for tests only- Parameters:
credentialsProvider
-fs
-user
-pass
-host
-port
-hc
-- Returns:
- session
- Throws:
com.jcraft.jsch.JSchException
-
safeConfig
private void safeConfig(com.jcraft.jsch.Session session, com.jcraft.jsch.ConfigRepository.Config cfg)
-
setPreferredKeyTypesOrder
private static void setPreferredKeyTypesOrder(com.jcraft.jsch.Session session)
-
hostName
private static java.lang.String hostName(com.jcraft.jsch.Session s)
-
copyConfigValueToSession
private void copyConfigValueToSession(com.jcraft.jsch.Session session, com.jcraft.jsch.ConfigRepository.Config cfg, java.lang.String from, java.lang.String to)
-
setUserName
private void setUserName(com.jcraft.jsch.Session session, java.lang.String userName)
-
createSession
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
Create a new remote session for the requested address.- Parameters:
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.- Returns:
- new session instance, but otherwise unconfigured.
- Throws:
com.jcraft.jsch.JSchException
- the session could not be created.
-
configureJSch
protected void configureJSch(com.jcraft.jsch.JSch jsch)
Provide additional configuration for the JSch instance. This method could be overridden to supply a preferredIdentityRepository
.- Parameters:
jsch
- jsch instance- Since:
- 4.5
-
configure
protected void configure(OpenSshConfig.Host hc, com.jcraft.jsch.Session session)
Provide additional configuration for the session based on the host information. This method could be used to supplyUserInfo
.- Parameters:
hc
- host configurationsession
- session to configure
-
getJSch
protected com.jcraft.jsch.JSch getJSch(OpenSshConfig.Host hc, FS fs) throws com.jcraft.jsch.JSchException
Obtain the JSch used to create new sessions.- Parameters:
hc
- host configurationfs
- the file system abstraction which will be necessary to perform certain file system operations.- Returns:
- the JSch instance to use.
- Throws:
com.jcraft.jsch.JSchException
- the user configuration could not be created.
-
createDefaultJSch
protected com.jcraft.jsch.JSch createDefaultJSch(FS fs) throws com.jcraft.jsch.JSchException
Create default instance of jsch- Parameters:
fs
- the file system abstraction which will be necessary to perform certain file system operations.- Returns:
- the new default JSch implementation.
- Throws:
com.jcraft.jsch.JSchException
- known host keys cannot be loaded.
-
copyGlobalConfigIfNotSet
private void copyGlobalConfigIfNotSet(java.lang.String from, java.lang.String to)
-
knownHosts
private static void knownHosts(com.jcraft.jsch.JSch sch, FS fs) throws com.jcraft.jsch.JSchException
- Throws:
com.jcraft.jsch.JSchException
-
identities
private static void identities(com.jcraft.jsch.JSch sch, FS fs)
-
loadIdentity
private static void loadIdentity(com.jcraft.jsch.JSch sch, java.io.File priv)
-
setConfig
public void setConfig(OpenSshConfig config)
Set theOpenSshConfig
to use. Intended for use in tests.- Parameters:
config
- to use
-
-