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
;
17 import org
.eclipse
.jgit
.util
.FS
;
19 import com
.jcraft
.jsch
.JSch
;
20 import com
.jcraft
.jsch
.JSchException
;
21 import com
.jcraft
.jsch
.Session
;
23 class EclipseSshSessionFactory
extends SshConfigSessionFactory
{
24 private final IJSchService provider
;
26 EclipseSshSessionFactory(final IJSchService p
) {
31 protected JSch
createDefaultJSch(FS fs
) throws JSchException
{
32 // Forcing a dummy session to be created will cause the known hosts
33 // and configured private keys to be initialized. This is needed by
34 // our parent class in case non-default JSch instances need to be made.
36 provider
.createSession("127.0.0.1", 0, "eclipse"); //$NON-NLS-1$ //$NON-NLS-2$
37 return provider
.getJSch();
41 protected Session
createSession(final OpenSshConfig
.Host hc
,
42 final String user
, final String host
, final int port
, FS fs
)
43 throws JSchException
{
44 final JSch jsch
= getJSch(hc
, FS
.DETECTED
);
45 if (jsch
== provider
.getJSch()) {
46 // If its the default JSch desired, let the provider
47 // manage the session creation for us.
49 return provider
.createSession(host
, port
, user
);
51 // This host configuration is using a different IdentityFile,
52 // one that is not available through the default JSch.
54 return jsch
.getSession(user
, host
, port
);
59 protected void configure(final OpenSshConfig
.Host hc
, final Session session
) {
60 if (!hc
.isBatchMode())
61 new UserInfoPrompter(session
);