JCLOUDS-921 prioritise key over password in SessionConnection

This commit is contained in:
Ignasi Barrera 2015-06-11 13:29:23 +02:00
parent f88acd67c0
commit 7e1838afbb
2 changed files with 3 additions and 12 deletions

View File

@ -1,9 +0,0 @@
# use glob syntax.
syntax: glob
target
.settings
.classpath
.project
jclouds-jsch.iml
jclouds-jsch.ipr
jclouds-jsch.iws

View File

@ -169,11 +169,11 @@ public final class SessionConnection implements Connection<Session> {
.getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
if (sessionTimeout != 0)
session.setTimeout(sessionTimeout);
if (loginCredentials.getOptionalPassword().isPresent()) {
session.setPassword(loginCredentials.getOptionalPassword().orNull());
} else if (loginCredentials.hasUnencryptedPrivateKey()) {
if (loginCredentials.hasUnencryptedPrivateKey()) {
byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes();
jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
} else if (loginCredentials.getOptionalPassword().isPresent()) {
session.setPassword(loginCredentials.getOptionalPassword().orNull());
} else if (agentConnector.isPresent()) {
JSch.setConfig("PreferredAuthentications", "publickey");
jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));