Class JschConfigSessionFactory
java.lang.Object
org.eclipse.jgit.transport.SshSessionFactory
org.eclipse.jgit.transport.JschConfigSessionFactory
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.OpenSshConfig.Host, Session) to
supply appropriate UserInfo to the session.
-
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(FS fs) Create default instance of jschprotected com.jcraft.jsch.SessioncreateSession(OpenSshConfig.Host hc, String user, String host, int port, FS fs) Create a new remote session for the requested address.protected com.jcraft.jsch.JSchgetJSch(OpenSshConfig.Host hc, FS fs) Obtain the JSch used to create new sessions.getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) Opens (or reuses) a session to a host.getType()The name of the type of session factory.Methods inherited from class SshSessionFactory
getInstance, getLocalUserName, releaseSession, setInstance
-
Constructor Details
-
JschConfigSessionFactory
public JschConfigSessionFactory()
-
-
Method Details
-
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:
getSessionin classSshSessionFactory- Parameters:
uri- URI of the remote host to connect tocredentialsProvider- provider to support authentication, may benullif 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
Description copied from class:SshSessionFactoryThe name of the type of session factory.- Specified by:
getTypein classSshSessionFactory- Returns:
- the name of the type of session factory.
-
createSession
protected com.jcraft.jsch.Session createSession(OpenSshConfig.Host hc, String user, 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
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
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.
-