Search in sources :

Example 1 with Host

use of org.eclipse.jgit.transport.OpenSshConfig.Host in project gerrit by GerritCodeReview.

the class GitUtil method initSsh.

public static void initSsh(final TestAccount a) {
    final Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    JSch.setConfig(config);
    // register a JschConfigSessionFactory that adds the private key as identity
    // to the JSch instance of JGit so that SSH communication via JGit can
    // succeed
    SshSessionFactory.setInstance(new JschConfigSessionFactory() {

        @Override
        protected void configure(Host hc, Session session) {
            try {
                final JSch jsch = getJSch(hc, FS.DETECTED);
                jsch.addIdentity("KeyPair", a.privateKey(), a.sshKey.getPublicKeyBlob(), null);
            } catch (JSchException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : JSchException(com.jcraft.jsch.JSchException) Host(org.eclipse.jgit.transport.OpenSshConfig.Host) JschConfigSessionFactory(org.eclipse.jgit.transport.JschConfigSessionFactory) Properties(java.util.Properties) JSch(com.jcraft.jsch.JSch) Session(com.jcraft.jsch.Session)

Aggregations

JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 Properties (java.util.Properties)1 JschConfigSessionFactory (org.eclipse.jgit.transport.JschConfigSessionFactory)1 Host (org.eclipse.jgit.transport.OpenSshConfig.Host)1