Add configureJSch method to allow configuration of JSch objects

Example use case is to set a different IdentityRepository, for example,
a RemoteIdentityRepository to allow SSH Agent supplied credentials.

Change-Id: Id4a4afd64464e452ffe6d6ad49036f9e283b4655
Signed-off-by: markdingram <markdingram@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
markdingram 2016-06-21 17:31:20 +01:00 committed by Matthias Sohn
parent 13db3550a4
commit 583b34483a
1 changed files with 16 additions and 0 deletions

View File

@ -1,4 +1,5 @@
/*
* Copyright (C) 2016, Mark Ingram <markdingram@gmail.com>
* Copyright (C) 2009, Constantine Plotnikov <constantine.plotnikov@gmail.com>
* Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2009, Google, Inc.
@ -219,6 +220,19 @@ protected Session createSession(final OpenSshConfig.Host hc,
return getJSch(hc, fs).getSession(user, host, port);
}
/**
* Provide additional configuration for the JSch instance. This method could
* be overridden to supply a preferred
* {@link com.jcraft.jsch.IdentityRepository}.
*
* @param jsch
* jsch instance
* @since 4.5
*/
protected void configureJSch(JSch jsch) {
// No additional configuration required.
}
/**
* Provide additional configuration for the session based on the host
* information. This method could be used to supply {@link UserInfo}.
@ -257,6 +271,7 @@ protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException
JSch jsch = byIdentityFile.get(identityKey);
if (jsch == null) {
jsch = new JSch();
configureJSch(jsch);
jsch.setHostKeyRepository(defaultJSch.getHostKeyRepository());
jsch.addIdentity(identityKey);
byIdentityFile.put(identityKey, jsch);
@ -274,6 +289,7 @@ protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException
*/
protected JSch createDefaultJSch(FS fs) throws JSchException {
final JSch jsch = new JSch();
configureJSch(jsch);
knownHosts(jsch, fs);
identities(jsch, fs);
return jsch;