|
|
|
@ -106,6 +106,46 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory {
|
|
|
|
|
if (user == null) |
|
|
|
|
user = hc.getUser(); |
|
|
|
|
|
|
|
|
|
Session session = createSession(credentialsProvider, fs, user, |
|
|
|
|
pass, host, port, hc); |
|
|
|
|
|
|
|
|
|
int retries = 0; |
|
|
|
|
while (!session.isConnected() && retries < 3) { |
|
|
|
|
try { |
|
|
|
|
retries++; |
|
|
|
|
session.connect(tms); |
|
|
|
|
} catch (JSchException e) { |
|
|
|
|
session.disconnect(); |
|
|
|
|
session = null; |
|
|
|
|
// if authentication failed maybe credentials changed at the
|
|
|
|
|
// remote end therefore reset credentials and retry
|
|
|
|
|
if (credentialsProvider != null && e.getCause() == null |
|
|
|
|
&& e.getMessage().equals("Auth fail")) { |
|
|
|
|
credentialsProvider.reset(uri); |
|
|
|
|
session = createSession(credentialsProvider, fs, user, |
|
|
|
|
pass, host, port, hc); |
|
|
|
|
} else { |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new JschSession(session, uri); |
|
|
|
|
|
|
|
|
|
} catch (JSchException je) { |
|
|
|
|
final Throwable c = je.getCause(); |
|
|
|
|
if (c instanceof UnknownHostException) |
|
|
|
|
throw new TransportException(uri, JGitText.get().unknownHost); |
|
|
|
|
if (c instanceof ConnectException) |
|
|
|
|
throw new TransportException(uri, c.getMessage()); |
|
|
|
|
throw new TransportException(uri, je.getMessage(), je); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Session createSession(CredentialsProvider credentialsProvider, |
|
|
|
|
FS fs, String user, final String pass, String host, int port, |
|
|
|
|
final OpenSshConfig.Host hc) throws JSchException { |
|
|
|
|
final Session session = createSession(hc, user, host, port, fs); |
|
|
|
|
if (pass != null) |
|
|
|
|
session.setPassword(pass); |
|
|
|
@ -123,21 +163,7 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory {
|
|
|
|
|
credentialsProvider)); |
|
|
|
|
} |
|
|
|
|
configure(hc, session); |
|
|
|
|
|
|
|
|
|
if (!session.isConnected()) |
|
|
|
|
session.connect(tms); |
|
|
|
|
|
|
|
|
|
return new JschSession(session, uri); |
|
|
|
|
|
|
|
|
|
} catch (JSchException je) { |
|
|
|
|
final Throwable c = je.getCause(); |
|
|
|
|
if (c instanceof UnknownHostException) |
|
|
|
|
throw new TransportException(uri, JGitText.get().unknownHost); |
|
|
|
|
if (c instanceof ConnectException) |
|
|
|
|
throw new TransportException(uri, c.getMessage()); |
|
|
|
|
throw new TransportException(uri, je.getMessage(), je); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|