Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport.sshd

public final Class SshdSessionFactoryBuilder

extends Object
Class Inheritance
Imports
java.io.File, java.nio.file.Path, java.security.KeyPair, java.util.Collections, .List, java.util.function.BiFunction, .Function, org.eclipse.jgit.annotations.NonNull, org.eclipse.jgit.transport.CredentialsProvider, .SshConfigStore, org.eclipse.jgit.transport.sshd.agent.ConnectorFactory, org.eclipse.jgit.util.StringUtils

A builder API to configure SshdSessionFactories.
Since
5.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
private static class

Field Summary

Modifier and TypeField and Description
private final SshdSessionFactoryBuilder.State

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public SshdSessionFactory

Returns:

the SshdSessionFactory
build
(KeyCache
to use for caching ssh keys; may be null if no caching is desired.
cache
)

Builds a SshdSessionFactory as configured, using the given KeyCache for caching keys.

public SshdSessionFactoryBuilder
setConfigFile(Function<File, File>
returning a File for the SSH config file to use, or returning null if no config file is to be used
supplier
)

Sets a function that returns the SSH config file, given the SSH directory.

public SshdSessionFactoryBuilder
public SshdSessionFactoryBuilder
public SshdSessionFactoryBuilder
setDefaultIdentities(Function<File, List<Path>>
to get the default private key files
supplier
)

Sets a function that returns the default private key files, given the SSH directory.

public SshdSessionFactoryBuilder
setDefaultKeysProvider(Function<File, Iterable<KeyPair>>
to get the default private key files
provider
)

Sets a function that returns the default private keys, given the SSH directory.

public SshdSessionFactoryBuilder
setDefaultKnownHostsFiles(Function<File, List<Path>>
to get the default known hosts files
supplier
)

Sets a function that returns the default known hosts files, given the SSH directory.

public SshdSessionFactoryBuilder
setHomeDirectory(File
to use; may be null, in which case the home directory as defined by FS.userHome() is assumed
homeDirectory
)

Sets the home directory to use for SshdSessionFactories created by build(KeyCache).

public SshdSessionFactoryBuilder
public SshdSessionFactoryBuilder
setPreferredAuthentications(String
comma-separated list of authentication mechanism names; if null or empty, the default as specified by SshdSessionFactory#getDefaultPreferredAuthentications() will be used
authentications
)

Sets the default preferred authentication mechanisms to use for SshdSessionFactories created by build(KeyCache).

public SshdSessionFactoryBuilder
setProxyDataFactory(ProxyDataFactory
to use
proxyDataFactory
)

Sets the ProxyDataFactory to use for SshdSessionFactories created by build(KeyCache).

public SshdSessionFactoryBuilder
setServerKeyDatabase(BiFunction<File, File, ServerKeyDatabase>
to create a ServerKeyDatabase
factory
)

Sets a function that creates a new ServerKeyDatabase, given the SSH and home directory.

public SshdSessionFactoryBuilder
setSshDirectory(File
to use; may be null, in which case ".ssh" under the home directory is assumed
sshDirectory
)

Sets the SSH directory to use for SshdSessionFactories created by build(KeyCache).

public SshdSessionFactoryBuilder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stateback to summary
private final SshdSessionFactoryBuilder.State state

Constructor Detail

SshdSessionFactoryBuilderback to summary
public SshdSessionFactoryBuilder()

Method Detail

buildback to summary
public SshdSessionFactory build(KeyCache cache)

Builds a SshdSessionFactory as configured, using the given KeyCache for caching keys.

Different SshdSessionFactories should not share the same KeyCache since the cache is invalidated when the factory itself or when the last SshdSession created from the factory is closed.

Parameters
cache:KeyCache

to use for caching ssh keys; may be null if no caching is desired.

Returns:SshdSessionFactory

the SshdSessionFactory

setConfigFileback to summary
public SshdSessionFactoryBuilder setConfigFile(Function<File, File> supplier)

Sets a function that returns the SSH config file, given the SSH directory. The function may return null, in which case no SSH config file will be used. If a non-null file is returned, it will be used when it exists. If no supplier has been set, or the supplier has been set explicitly to null, by default a file named SshConstants.CONFIG in the SSH directory is used.

Parameters
supplier:Function<File, File>

returning a File for the SSH config file to use, or returning null if no config file is to be used

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setConfigStoreFactoryback to summary
public SshdSessionFactoryBuilder setConfigStoreFactory(SshdSessionFactoryBuilder.ConfigStoreFactory factory)

Sets a factory for the SshConfigStore to use. If not set or explicitly set to null, the default as specified by SshdSessionFactory#createSshConfigStore(File, File, String) is used.

Parameters
factory:SshdSessionFactoryBuilder.ConfigStoreFactory

to set

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setConnectorFactoryback to summary
public SshdSessionFactoryBuilder setConnectorFactory(ConnectorFactory factory)

Sets an explicit ConnectorFactory. If null, there will be no support for SSH agents.

If not set, the created SshdSessionFactory will use the java.util.ServiceLoader to find an ConnectorFactory.

Parameters
factory:ConnectorFactory

ConnectorFactory to use

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

Since
6.0
setDefaultIdentitiesback to summary
public SshdSessionFactoryBuilder setDefaultIdentities(Function<File, List<Path>> supplier)

Sets a function that returns the default private key files, given the SSH directory. If not set or explicitly set to null, the defaults as specified by SshdSessionFactory#getDefaultIdentities(File) are used.

Parameters
supplier:Function<File, List<Path>>

to get the default private key files

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setDefaultKeysProviderback to summary
public SshdSessionFactoryBuilder setDefaultKeysProvider(Function<File, Iterable<KeyPair>> provider)

Sets a function that returns the default private keys, given the SSH directory. If not set or explicitly set to null, the defaults as specified by SshdSessionFactory#getDefaultKeys(File) are used.

Parameters
provider:Function<File, Iterable<KeyPair>>

to get the default private key files

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setDefaultKnownHostsFilesback to summary
public SshdSessionFactoryBuilder setDefaultKnownHostsFiles(Function<File, List<Path>> supplier)

Sets a function that returns the default known hosts files, given the SSH directory. If not set or explicitly set to null, the defaults as specified by SshdSessionFactory#getDefaultKnownHostsFiles(File) are used.

Parameters
supplier:Function<File, List<Path>>

to get the default known hosts files

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setHomeDirectoryback to summary
public SshdSessionFactoryBuilder setHomeDirectory(File homeDirectory)

Sets the home directory to use for SshdSessionFactories created by build(KeyCache).

Parameters
homeDirectory:File

to use; may be null, in which case the home directory as defined by FS.userHome() is assumed

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setKeyPasswordProviderback to summary
public SshdSessionFactoryBuilder setKeyPasswordProvider(Function<CredentialsProvider, KeyPasswordProvider> factory)

Sets a factory function to create a KeyPasswordProvider. If not set or explicitly set to null, or if the factory returns null, the default as specified by SshdSessionFactory#createKeyPasswordProvider(CredentialsProvider) is used.

Parameters
factory:Function<CredentialsProvider, KeyPasswordProvider>

to create a KeyPasswordProvider

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setPreferredAuthenticationsback to summary
public SshdSessionFactoryBuilder setPreferredAuthentications(String authentications)

Sets the default preferred authentication mechanisms to use for SshdSessionFactories created by build(KeyCache).

Parameters
authentications:String

comma-separated list of authentication mechanism names; if null or empty, the default as specified by SshdSessionFactory#getDefaultPreferredAuthentications() will be used

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setProxyDataFactoryback to summary
public SshdSessionFactoryBuilder setProxyDataFactory(ProxyDataFactory proxyDataFactory)

Sets the ProxyDataFactory to use for SshdSessionFactories created by build(KeyCache).

Parameters
proxyDataFactory:ProxyDataFactory

to use

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setServerKeyDatabaseback to summary
public SshdSessionFactoryBuilder setServerKeyDatabase(BiFunction<File, File, ServerKeyDatabase> factory)

Sets a function that creates a new ServerKeyDatabase, given the SSH and home directory. If not set or explicitly set to null, or if the factory returns null, the default as specified by SshdSessionFactory#createServerKeyDatabase(File, File) is used.

Parameters
factory:BiFunction<File, File, ServerKeyDatabase>

to create a ServerKeyDatabase

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

setSshDirectoryback to summary
public SshdSessionFactoryBuilder setSshDirectory(File sshDirectory)

Sets the SSH directory to use for SshdSessionFactories created by build(KeyCache).

Parameters
sshDirectory:File

to use; may be null, in which case ".ssh" under the home directory is assumed

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

withDefaultConnectorFactoryback to summary
public SshdSessionFactoryBuilder withDefaultConnectorFactory()

Removes a previously set ConnectorFactory. The created SshdSessionFactory will use the java.util.ServiceLoader to find an ConnectorFactory. This is also the default if setConnectorFactory(ConnectorFactory) isn't called at all.

Returns:SshdSessionFactoryBuilder

this SshdSessionFactoryBuilder

Since
6.0
org.eclipse.jgit.transport.sshd back to summary

public Interface SshdSessionFactoryBuilder.ConfigStoreFactory

Annotations
@FunctionalInterface

A factory interface for creating a SshConfigStore.

Method Summary

Modifier and TypeMethod and Description
public SshConfigStore

Returns:

the SshConfigStore, or null if none is to be used
create
(File
to use for ~-replacements
homeDir
,
File
to use, may be null if none
configFile
,
String
name of the current user in the local OS
localUserName
)

Creates a SshConfigStore.

Method Detail

createback to summary
public SshConfigStore create(File homeDir, File configFile, String localUserName)

Creates a SshConfigStore. May return null if none is to be used.

Parameters
homeDir:File

to use for ~-replacements

configFile:File

to use, may be null if none

localUserName:String

name of the current user in the local OS

Returns:SshConfigStore

the SshConfigStore, or null if none is to be used

org.eclipse.jgit.transport.sshd back to summary

private Class SshdSessionFactoryBuilder.State

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.transport.sshd.SshdSessionFactoryBuilder.State

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv SshdSessionFactoryBuilder.ConfigStoreFactory
pack-priv Function<File, File>
pack-priv ConnectorFactory
pack-priv boolean
pack-priv Function<File, List<Path>>
pack-priv Function<File, Iterable<KeyPair>>
pack-priv File
pack-priv Function<File, List<Path>>
pack-priv Function<CredentialsProvider, KeyPasswordProvider>
pack-priv String
pack-priv ProxyDataFactory
pack-priv BiFunction<File, File, ServerKeyDatabase>
pack-priv File

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv SshdSessionFactory
build(KeyCache cache)

pack-priv SshdSessionFactoryBuilder.State
copy()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configFactoryback to summary
pack-priv SshdSessionFactoryBuilder.ConfigStoreFactory configFactory
configFileFinderback to summary
pack-priv Function<File, File> configFileFinder
connectorFactoryback to summary
pack-priv ConnectorFactory connectorFactory
connectorFactorySetback to summary
pack-priv boolean connectorFactorySet
defaultKeyFileFinderback to summary
pack-priv Function<File, List<Path>> defaultKeyFileFinder
defaultKeysProviderback to summary
pack-priv Function<File, Iterable<KeyPair>> defaultKeysProvider
homeDirectoryback to summary
pack-priv File homeDirectory
knownHostsFileFinderback to summary
pack-priv Function<File, List<Path>> knownHostsFileFinder
passphraseProviderFactoryback to summary
pack-priv Function<CredentialsProvider, KeyPasswordProvider> passphraseProviderFactory
preferredAuthenticationsback to summary
pack-priv String preferredAuthentications
proxyDataFactoryback to summary
pack-priv ProxyDataFactory proxyDataFactory
serverKeyDatabaseCreatorback to summary
pack-priv BiFunction<File, File, ServerKeyDatabase> serverKeyDatabaseCreator
sshDirectoryback to summary
pack-priv File sshDirectory

Constructor Detail

Stateback to summary
private State()

Method Detail

buildback to summary
pack-priv SshdSessionFactory build(KeyCache cache)
copyback to summary
pack-priv SshdSessionFactoryBuilder.State copy()
org.eclipse.jgit.transport.sshd back to summary

private Class SshdSessionFactoryBuilder.State.SessionFactory

extends SshdSessionFactory
Class Inheritance

Constructor Summary

AccessConstructor and Description
public
SessionFactory(KeyCache cache, ProxyDataFactory proxyDataFactory)

Method Summary

Modifier and TypeMethod and Description
protected KeyPasswordProvider
protected ServerKeyDatabase
createServerKeyDatabase(File
home directory to use for ~ replacement
homeDir
,
File
representing ~/.ssh/
sshDir
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.createServerKeyDatabase.

Creates a ServerKeyDatabase to verify server host keys.

protected SshConfigStore
createSshConfigStore(File
may be used for ~-replacements by the returned config store
homeDir
,
File
to use, or null if none
configFile
,
String
user name of the current user on the local OS
localUserName
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.createSshConfigStore.

Obtains a SshConfigStore, or null if no SSH config is to be used.

protected ConnectorFactory
protected List<Path>
getDefaultIdentities(File
the directory that represents ~/.ssh/
sshDir
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultIdentities.

Gets a list of default identities, i.e., private key files that shall always be tried for public key authentication.

protected Iterable<KeyPair>
getDefaultKeys(File
to look in for keys
sshDir
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKeys.

Determines the default keys.

protected List<Path>
getDefaultKnownHostsFiles(File
directory containing ssh configurations
sshDir
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKnownHostsFiles.

Gets the list of default user known hosts files.

protected String
protected File
getSshConfig(File
representing ~/.ssh/
sshDir
)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getSshConfig.

Determines the ssh config file.

Inherited from org.eclipse.jgit.transport.sshd.SshdSessionFactory:
closegetHomeDirectorygetKeyCachegetServerKeyDatabasegetSessiongetSshDirectorygetTypesetHomeDirectorysetSshDirectory

Constructor Detail

SessionFactoryback to summary
public SessionFactory(KeyCache cache, ProxyDataFactory proxyDataFactory)

Method Detail

createKeyPasswordProviderback to summary
protected KeyPasswordProvider createKeyPasswordProvider(CredentialsProvider provider)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.createKeyPasswordProvider.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.createKeyPasswordProvider.

Creates a KeyPasswordProvider for a new session.

Parameters
provider:CredentialsProvider

the CredentialsProvider to delegate to for user interactions

Returns:KeyPasswordProvider

a new KeyPasswordProvider, or null to use the global KeyPasswordProviderFactory

Annotations
@Override
createServerKeyDatabaseback to summary
protected ServerKeyDatabase createServerKeyDatabase(File homeDir, File sshDir)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.createServerKeyDatabase.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.createServerKeyDatabase.

Creates a ServerKeyDatabase to verify server host keys. The default implementation returns a ServerKeyDatabase that recognizes the two openssh standard files ~/.ssh/known_hosts and ~/.ssh/known_hosts2 as well as any files configured via the UserKnownHostsFile option in the ssh config file.

Parameters
homeDir:File

home directory to use for ~ replacement

sshDir:File

representing ~/.ssh/

Returns:ServerKeyDatabase

the ServerKeyDatabase

Annotations
@Override
createSshConfigStoreback to summary
protected SshConfigStore createSshConfigStore(File homeDir, File configFile, String localUserName)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.createSshConfigStore.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.createSshConfigStore.

Obtains a SshConfigStore, or null if no SSH config is to be used. The default implementation returns null if configFile == null and otherwise an OpenSSH-compatible store reading host entries from the given file.

Parameters
homeDir:File

may be used for ~-replacements by the returned config store

configFile:File

to use, or null if none

localUserName:String

user name of the current user on the local OS

Returns:SshConfigStore

A SshConfigStore, or null if none is to be used

Annotations
@Override
getConnectorFactoryback to summary
protected ConnectorFactory getConnectorFactory()

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getConnectorFactory.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getConnectorFactory.

Gets a ConnectorFactory. If this returns null, SSH agents are not supported.

The default implementation uses ConnectorFactory#getDefault()

Returns:ConnectorFactory

the factory, or null if no SSH agent support is desired

Annotations
@Override
getDefaultIdentitiesback to summary
protected List<Path> getDefaultIdentities(File sshDir)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultIdentities.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultIdentities.

Gets a list of default identities, i.e., private key files that shall always be tried for public key authentication. Typically those are ~/.ssh/id_dsa, ~/.ssh/id_rsa, and so on. The default implementation returns the files defined in SshConstants#DEFAULT_IDENTITIES.

Parameters
sshDir:File

the directory that represents ~/.ssh/

Returns:List<Path>

a possibly empty list of paths containing default identities (private keys)

Annotations
@Override
getDefaultKeysback to summary
protected Iterable<KeyPair> getDefaultKeys(File sshDir)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKeys.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKeys.

Determines the default keys. The default implementation will lazy load the default identity files.

Subclasses may override and return an Iterable of whatever keys are appropriate. If the returned iterable lazily loads keys, it should be an instance of AbstractResourceKeyPairProvider so that the session can later pass it the password provider wrapped as a FilePasswordProvider via AbstractResourceKeyPairProvider#setPasswordFinder(FilePasswordProvider) so that encrypted, password-protected keys can be loaded.

The default implementation uses exactly this mechanism; class CachingKeyPairProvider may serve as a model for a customized lazy-loading Iterable implementation

If the Iterable returned has the keys already pre-loaded or otherwise doesn't need to decrypt encrypted keys, it can be any Iterable, for instance a simple List.

Parameters
sshDir:File

to look in for keys

Returns:Iterable<KeyPair>

an Iterable over the default keys

Annotations
@Override
getDefaultKnownHostsFilesback to summary
protected List<Path> getDefaultKnownHostsFiles(File sshDir)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKnownHostsFiles.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultKnownHostsFiles.

Gets the list of default user known hosts files. The default returns ~/.ssh/known_hosts and ~/.ssh/known_hosts2. The ssh config UserKnownHostsFile overrides this default.

Parameters
sshDir:File

directory containing ssh configurations

Returns:List<Path>

the possibly empty list of default known host file paths.

Annotations
@Override
getDefaultPreferredAuthenticationsback to summary
protected String getDefaultPreferredAuthentications()

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultPreferredAuthentications.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getDefaultPreferredAuthentications.

Gets the list of default preferred authentication mechanisms. If null is returned the openssh default list will be in effect. If the ssh config defines PreferredAuthentications the value from the ssh config takes precedence.

Returns:String

a comma-separated list of mechanism names, or null if none

Annotations
@Override
getSshConfigback to summary
protected File getSshConfig(File sshDir)

Overrides org.eclipse.jgit.transport.sshd.SshdSessionFactory.getSshConfig.

Doc from org.eclipse.jgit.transport.sshd.SshdSessionFactory.getSshConfig.

Determines the ssh config file. The default implementation returns ~/.ssh/config. If the file does not exist and is created later it will be picked up. To not use a config file at all, return null.

Parameters
sshDir:File

representing ~/.ssh/

Returns:File

the file (need not exist), or null if no config file shall be used

Annotations
@Override