1 /*******************************************************************************
2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * Copyright (C) 2009, Google, Inc.
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
;
13 import org
.eclipse
.jsch
.core
.IJSchService
;
14 import org
.eclipse
.jsch
.ui
.UserInfoPrompter
;
15 import org
.eclipse
.jgit
.transport
.OpenSshConfig
;
16 import org
.eclipse
.jgit
.transport
.SshConfigSessionFactory
;
18 import com
.jcraft
.jsch
.JSch
;
19 import com
.jcraft
.jsch
.JSchException
;
20 import com
.jcraft
.jsch
.Session
;
22 class EclipseSshSessionFactory
extends SshConfigSessionFactory
{
23 private final IJSchService provider
;
25 EclipseSshSessionFactory(final IJSchService p
) {
30 protected JSch
createDefaultJSch() throws JSchException
{
31 // Forcing a dummy session to be created will cause the known hosts
32 // and configured private keys to be initialized. This is needed by
33 // our parent class in case non-default JSch instances need to be made.
35 provider
.createSession("127.0.0.1", 0, "eclipse"); //$NON-NLS-1$ //$NON-NLS-2$
36 return provider
.getJSch();
40 protected Session
createSession(final OpenSshConfig
.Host hc
,
41 final String user
, final String host
, final int port
)
42 throws JSchException
{
43 final JSch jsch
= getJSch(hc
);
44 if (jsch
== provider
.getJSch()) {
45 // If its the default JSch desired, let the provider
46 // manage the session creation for us.
48 return provider
.createSession(host
, port
, user
);
50 // This host configuration is using a different IdentityFile,
51 // one that is not available through the default JSch.
53 return jsch
.getSession(user
, host
, port
);
58 protected void configure(final OpenSshConfig
.Host hc
, final Session session
) {
59 if (!hc
.isBatchMode())
60 new UserInfoPrompter(session
);