Module org.eclipse.jgit.ssh.jsch
Class JschConfigSessionFactory
java.lang.Object
org.eclipse.jgit.transport.SshSessionFactory
org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory
public class JschConfigSessionFactory
extends org.eclipse.jgit.transport.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 appropriate UserInfo to the session.
- Since:
- 6.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigure(OpenSshConfig.Host hc, com.jcraft.jsch.Session session) Provide additional configuration for the session based on the host information.protected voidconfigureJSch(com.jcraft.jsch.JSch jsch) Provide additional configuration for the JSch instance.protected com.jcraft.jsch.JSchcreateDefaultJSch(org.eclipse.jgit.util.FS fs) Create default instance of jschcom.jcraft.jsch.SessioncreateSession(org.eclipse.jgit.transport.CredentialsProvider credentialsProvider, org.eclipse.jgit.util.FS fs, String user, String pass, String host, int port, OpenSshConfig.Host hc) Use for tests onlyprotected com.jcraft.jsch.SessioncreateSession(OpenSshConfig.Host hc, String user, String host, int port, org.eclipse.jgit.util.FS fs) Create a new remote session for the requested address.protected com.jcraft.jsch.JSchgetJSch(OpenSshConfig.Host hc, org.eclipse.jgit.util.FS fs) Obtain the JSch used to create new sessions.org.eclipse.jgit.transport.RemoteSessiongetSession(org.eclipse.jgit.transport.URIish uri, org.eclipse.jgit.transport.CredentialsProvider credentialsProvider, org.eclipse.jgit.util.FS fs, int tms) getType()voidsetConfig(OpenSshConfig config) Set theOpenSshConfigto use.Methods inherited from class org.eclipse.jgit.transport.SshSessionFactory
getInstance, getLocalUserName, releaseSession, setInstance
-
Constructor Details
-
JschConfigSessionFactory
public JschConfigSessionFactory()
-
-
Method Details
-
getSession
public org.eclipse.jgit.transport.RemoteSession getSession(org.eclipse.jgit.transport.URIish uri, org.eclipse.jgit.transport.CredentialsProvider credentialsProvider, org.eclipse.jgit.util.FS fs, int tms) throws org.eclipse.jgit.errors.TransportException - Specified by:
getSessionin classorg.eclipse.jgit.transport.SshSessionFactory- Throws:
org.eclipse.jgit.errors.TransportException
-
getType
- Specified by:
getTypein classorg.eclipse.jgit.transport.SshSessionFactory
-
createSession
public com.jcraft.jsch.Session createSession(org.eclipse.jgit.transport.CredentialsProvider credentialsProvider, org.eclipse.jgit.util.FS fs, String user, String pass, String host, int port, OpenSshConfig.Host hc) throws com.jcraft.jsch.JSchException Use for tests only- Parameters:
credentialsProvider- credentials providefs- FS object to useuser- userpass- passwordhost- host nameport- port numberhc- host config- Returns:
- session the session
- Throws:
com.jcraft.jsch.JSchException- jsch failed
-
createSession
protected com.jcraft.jsch.Session createSession(OpenSshConfig.Host hc, String user, String host, int port, org.eclipse.jgit.util.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
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, org.eclipse.jgit.util.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(org.eclipse.jgit.util.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.
-
setConfig
Set theOpenSshConfigto use. Intended for use in tests.- Parameters:
config- to use
-