Class 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.OpenSshConfig.Host, Session) to supply appropriate UserInfo to the session.

    • Constructor Detail

      • JschConfigSessionFactory

        public JschConfigSessionFactory()
    • Method Detail

      • getSession

        public RemoteSession getSession​(URIish uri,
                                        CredentialsProvider credentialsProvider,
                                        FS fs,
                                        int tms)
                                 throws TransportException
        Open (or reuse) a session to a host.

        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.

        Specified by:
        getSession in class SshSessionFactory
        Parameters:
        uri - URI information about the remote host
        credentialsProvider - 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.
        Returns:
        a session that can contact the remote host.
        Throws:
        TransportException - the session could not be created.
      • 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 configuration
        user - 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 preferred IdentityRepository.
        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 supply UserInfo.
        Parameters:
        hc - host configuration
        session - 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 configuration
        fs - 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.