From 451eb5409fe23987f07ec3fe9b84b5a0983998a2 Mon Sep 17 00:00:00 2001 From: Cerber Date: Mon, 10 Feb 2014 14:14:19 +0100 Subject: [PATCH] Added support for SSH agents --- pom.xml | 20 ++++++++++-- .../jsch/ForgeJschConfigSessionFactory.java | 31 ++++++++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 74d6b16..6460c5a 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,8 @@ 2.0.0.201206130900-r 1.1 2.0.1 - 0.1.48 + 0.1.49 + 0.0.7 @@ -48,6 +49,21 @@ jsch ${jsch.version} + + com.jcraft + jsch.agentproxy.core + ${jsch.agent.version} + + + com.jcraft + jsch.agentproxy.jsch + ${jsch.agent.version} + + + com.jcraft + jsch.agentproxy.connector-factory + ${jsch.agent.version} + com.openshift openshift-java-client @@ -63,7 +79,7 @@ apache-log4j-extras ${log4j.extras.version} - + JBOSS_NEXUS diff --git a/src/main/java/com/redhat/openshift/forge/jsch/ForgeJschConfigSessionFactory.java b/src/main/java/com/redhat/openshift/forge/jsch/ForgeJschConfigSessionFactory.java index e0d9e7b..254732a 100755 --- a/src/main/java/com/redhat/openshift/forge/jsch/ForgeJschConfigSessionFactory.java +++ b/src/main/java/com/redhat/openshift/forge/jsch/ForgeJschConfigSessionFactory.java @@ -22,16 +22,19 @@ package com.redhat.openshift.forge.jsch; -import java.util.Properties; - import javax.inject.Inject; import org.eclipse.jgit.transport.JschConfigSessionFactory; import org.eclipse.jgit.transport.OpenSshConfig.Host; +import org.eclipse.jgit.util.FS; +import com.jcraft.jsch.IdentityRepository; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; -import org.eclipse.jgit.util.FS; +import com.jcraft.jsch.agentproxy.AgentProxyException; +import com.jcraft.jsch.agentproxy.Connector; +import com.jcraft.jsch.agentproxy.ConnectorFactory; +import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; /** * @author Rafael Benevides @@ -45,8 +48,9 @@ public class ForgeJschConfigSessionFactory extends JschConfigSessionFactory { /* * (non-Javadoc) * - * @see org.eclipse.jgit.transport.JschConfigSessionFactory#configure(org.eclipse.jgit.transport.OpenSshConfig.Host, - * com.jcraft.jsch.Session) + * @see + * org.eclipse.jgit.transport.JschConfigSessionFactory#configure(org.eclipse + * .jgit.transport.OpenSshConfig.Host, com.jcraft.jsch.Session) */ @Override protected void configure(Host hc, Session session) { @@ -54,8 +58,20 @@ protected void configure(Host hc, Session session) { try { session.setUserInfo(forgeUserInfo); - //JSch jsch = this.getJSch(hc, FS.DETECTED); - + JSch jsch = this.getJSch(hc, FS.DETECTED); + JSch.setConfig("PreferredAuthentications", "publickey"); + + Connector con; + try { + ConnectorFactory cf = ConnectorFactory.getDefault(); + con = cf.createConnector(); + if (con != null) { + IdentityRepository irepo = new RemoteIdentityRepository(con); + jsch.setIdentityRepository(irepo); + } + } catch (AgentProxyException e) { + System.out.println(e); + } //Properties config = new Properties(); //config.put("StrictHostKeyChecking", "no"); //config.put("GSSAPIAuthentication", "no"); @@ -66,5 +82,4 @@ protected void configure(Host hc, Session session) { e.printStackTrace(); } } - }