2 * Copyright (C) 2008 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.egit
.ui
;
19 import java
.security
.AccessController
;
20 import java
.security
.PrivilegedAction
;
22 import org
.eclipse
.jsch
.core
.IJSchService
;
23 import org
.eclipse
.jsch
.ui
.UserInfoPrompter
;
24 import org
.spearce
.jgit
.transport
.SshSessionFactory
;
26 import com
.jcraft
.jsch
.JSchException
;
27 import com
.jcraft
.jsch
.Session
;
29 class EclipseSshSessionFactory
extends SshSessionFactory
{
30 private final IJSchService provider
;
32 EclipseSshSessionFactory(final IJSchService p
) {
37 public Session
getSession(final String user
, final String pass
,
38 final String host
, final int port
) throws JSchException
{
39 final Session session
= provider
.createSession(host
, port
> 0 ? port
40 : -1, user
!= null ? user
: userName());
42 session
.setPassword(pass
);
44 new UserInfoPrompter(session
);
48 private static String
userName() {
49 return AccessController
.doPrivileged(new PrivilegedAction
<String
>() {
51 return System
.getProperty("user.name");