// Set repository to session
session.setIdentityRepository(identityRepository);
// Set the user info
SSHKeyPasswordHandler sshKeyPasswordHandler
= new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);
session.setUserInfo(sshKeyPasswordHandler);
} else if (authenticationInfo instanceof SSHPublicKeyAuthentication) {
SSHPublicKeyAuthentication sshPublicKeyAuthentication
= (SSHPublicKeyAuthentication) authenticationInfo;
Identity identityFile;
try {
String name = serverInfo.getUserName() + "_" + serverInfo.getHost();
identityFile = GSISSHIdentityFile.newInstance(name,
sshPublicKeyAuthentication.getPrivateKey(serverInfo.getUserName(), serverInfo.getHost()),
sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), jSch);
} catch (JSchException e) {
throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " +
"(private key and public key)." +
"Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() +
" connecting user name - "
+ serverInfo.getUserName(), e);
}
// Add identity to identity repository
GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jSch);
identityRepository.add(identityFile);
// Set repository to session
session.setIdentityRepository(identityRepository);
// Set the user info
SSHKeyPasswordHandler sshKeyPasswordHandler
= new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);
session.setUserInfo(sshKeyPasswordHandler);
}