Class ClientIdentity
- java.lang.Object
-
- org.apache.sshd.client.config.keys.ClientIdentity
-
public final class ClientIdentity extends java.lang.ObjectProvides keys loading capability from the user's keys folder - e.g.,id_rsa- See Also:
SecurityUtils.getKeyPairResourceParser()
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringID_FILE_PREFIXstatic java.lang.StringID_FILE_SUFFIXstatic java.util.function.Function<java.lang.String,java.lang.String>ID_GENERATOR
-
Constructor Summary
Constructors Modifier Constructor Description privateClientIdentity()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetIdentityFileName(java.lang.String type)static java.lang.StringgetIdentityFileName(NamedResource r)static java.lang.StringgetIdentityType(java.lang.String name)static java.util.Map<java.lang.String,java.security.KeyPair>loadDefaultIdentities(boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options)static java.util.Map<java.lang.String,java.security.KeyPair>loadDefaultIdentities(java.nio.file.Path dir, boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options)static KeyPairProviderloadDefaultKeyPairProvider(boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)static KeyPairProviderloadDefaultKeyPairProvider(java.nio.file.Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)static java.util.Map<java.lang.String,java.security.KeyPair>loadIdentities(SessionContext session, java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,java.lang.String> idGenerator, FilePasswordProvider provider, java.nio.file.LinkOption... options)Scans a folder and loads all available identity filesstatic java.util.Map<java.lang.String,java.nio.file.Path>scanIdentitiesFolder(java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,java.lang.String> idGenerator, java.nio.file.LinkOption... options)Scans a folder for possible identity files
-
-
-
Field Detail
-
ID_FILE_PREFIX
public static final java.lang.String ID_FILE_PREFIX
- See Also:
- Constant Field Values
-
ID_FILE_SUFFIX
public static final java.lang.String ID_FILE_SUFFIX
- See Also:
- Constant Field Values
-
ID_GENERATOR
public static final java.util.function.Function<java.lang.String,java.lang.String> ID_GENERATOR
-
-
Method Detail
-
getIdentityType
public static java.lang.String getIdentityType(java.lang.String name)
- Parameters:
name- The file name - ignored ifnull/empty- Returns:
- The identity type -
nullif cannot determine it - e.g., does not start with theID_FILE_PREFIX
-
getIdentityFileName
public static java.lang.String getIdentityFileName(NamedResource r)
-
getIdentityFileName
public static java.lang.String getIdentityFileName(java.lang.String type)
- Parameters:
type- The identity type - e.g.,rsa- ignored ifnull/empty- Returns:
- The matching file name for the identity -
nullif no name - See Also:
ID_FILE_PREFIX,ID_FILE_SUFFIX,IdentityUtils.getIdentityFileName(String, String, String)
-
loadDefaultKeyPairProvider
public static KeyPairProvider loadDefaultKeyPairProvider(boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Parameters:
strict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
KeyPairfor the identities -nullif no identities available (e.g., after filtering unsupported ones or strict permissions) - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
PublicKeyEntry.getDefaultKeysFolderPath(),loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
-
loadDefaultKeyPairProvider
public static KeyPairProvider loadDefaultKeyPairProvider(java.nio.file.Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException
- Parameters:
dir- The folder to scan for the built-in identitiesstrict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
KeyPairfor the identities -nullif no identities available (e.g., after filtering unsupported ones or strict permissions) - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...),IdentityUtils.createKeyPairProvider(Map, boolean)
-
loadDefaultIdentities
public static java.util.Map<java.lang.String,java.security.KeyPair> loadDefaultIdentities(boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException- Parameters:
strict- Iftruethen files that do not have the required access rights are excluded from considerationprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
Mapof the found files where key=identity type (case insensitive), value=theKeyPairof the identity - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
PublicKeyEntry.getDefaultKeysFolderPath(),loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
-
loadDefaultIdentities
public static java.util.Map<java.lang.String,java.security.KeyPair> loadDefaultIdentities(java.nio.file.Path dir, boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException- Parameters:
dir- The folder to scan for the built-in identitiesstrict- Iftruethen files that do not have the required access rights are excluded from considerationprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
Mapof the found files where key=identity type (case insensitive), value=theKeyPairof the identity - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys- See Also:
BuiltinIdentities
-
loadIdentities
public static java.util.Map<java.lang.String,java.security.KeyPair> loadIdentities(SessionContext session, java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,java.lang.String> idGenerator, FilePasswordProvider provider, java.nio.file.LinkOption... options) throws java.io.IOException, java.security.GeneralSecurityException
Scans a folder and loads all available identity files- Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).dir- ThePathof the folder to scan - ignored if not existsstrict- Iftruethen files that do not have the required access rights are excluded from considerationtypes- The identity types - ignored ifnull/emptyidGenerator- AFunctionto derive the file name holding the specified typeprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
Mapof the found files where key=identity type (case insensitive), value=theKeyPairof the identity - Throws:
java.io.IOException- If failed to access the file systemjava.security.GeneralSecurityException- If failed to load the keys
-
scanIdentitiesFolder
public static java.util.Map<java.lang.String,java.nio.file.Path> scanIdentitiesFolder(java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,java.lang.String> idGenerator, java.nio.file.LinkOption... options) throws java.io.IOExceptionScans a folder for possible identity files- Parameters:
dir- ThePathof the folder to scan - ignored if not existsstrict- Iftruethen files that do not have the required access rights are excluded from considerationtypes- The identity types - ignored ifnull/emptyidGenerator- AFunctionto derive the file name holding the specified typeoptions- TheLinkOptions to apply when checking for existence- Returns:
- A
Mapof the found files where key=identity type (case insensitive), value=thePathof the file holding the key - Throws:
java.io.IOException- If failed to access the file system- See Also:
KeyUtils.validateStrictKeyFilePermissions(Path, LinkOption...)
-
-