Class HostConfigEntry
java.lang.Object
org.apache.sshd.client.config.hosts.HostPatternsHolder
org.apache.sshd.client.config.hosts.HostConfigEntry
- All Implemented Interfaces:
MutableUserHolder,UsernameHolder
Represents an entry in the client's configuration file as defined by the
ssh_config configuration file format
- Author:
- Apache MINA SSHD Project
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final StringUse only the identities specified in the host entry (if any)static final NavigableSet<String>A case insensitiveNavigableSetof the properties that receive special handlingstatic final Stringstatic final Stringstatic final StringThe IdentityAgent configuration.static final Stringstatic final charstatic final charstatic final charstatic final Stringstatic final charstatic final Stringstatic final Stringstatic final charstatic final charstatic final charstatic final StringStandard OpenSSH config file namestatic final StringFields inherited from class org.apache.sshd.client.config.hosts.HostPatternsHolder
ALL_HOSTS_PATTERN, NEGATION_CHAR_PATTERN, NON_STANDARD_PORT_PATTERN_ENCLOSURE_END_DELIM, NON_STANDARD_PORT_PATTERN_ENCLOSURE_START_DELIM, PATTERN_CHARS, PORT_VALUE_DELIMITER, SINGLE_CHAR_PATTERN, WILDCARD_PATTERN -
Constructor Summary
ConstructorsConstructorDescriptionHostConfigEntry(String pattern, String host, int port, String username) HostConfigEntry(String pattern, String host, int port, String username, String proxyJump) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIdentity(String id) Adds a path to an identity filevoidaddIdentity(Path path) <A extends Appendable>
Aappend(A sb) static <A extends Appendable>
AappendHostConfigEntries(A sb, Collection<? extends HostConfigEntry> entries) static <A extends Appendable>
AappendNonEmptyPort(A sb, String name, int port) static <A extends Appendable>
AappendNonEmptyProperties(A sb, Map<String, ?> props) Appends the extra properties - while skipping theEXPLICIT_PROPERTIESonesstatic <A extends Appendable>
AappendNonEmptyProperty(A sb, String name, Object value) static <A extends Appendable>
AappendNonEmptyValues(A sb, String name, Object... values) static <A extends Appendable>
AappendNonEmptyValues(A sb, String name, Collection<?> values) appendPropertyValue(String name, String value) Appends a value using a comma to an existing one.static HostConfigEntryfindBestMatch(Iterable<? extends HostConfigEntry> matches) Finds the best match out of the given ones.static HostConfigEntryfindBestMatch(Collection<? extends HostConfigEntry> matches) Finds the best match out of the given ones.static HostConfigEntryfindBestMatch(Iterator<? extends HostConfigEntry> matches) Finds the best match out of the given ones.static PathgetHost()intgetPort()getProperty(String name) getProperty(String name, String defaultValue) booleanstatic HostConfigEntrynormalizeEntry(HostConfigEntry entry, String host, int port, String username, String proxyJump) parseConfigValue(String value) Checks if this is a multi-value - allow space and commabooleanprocessGlobalValues(HostConfigEntry globalEntry) Updates the values that are not already configured with those from the global entryvoidprocessProperty(String name, Collection<String> valsList, boolean ignoreAlreadyInitialized) static List<HostConfigEntry>Reads configuration entriesstatic List<HostConfigEntry>readHostConfigEntries(InputStream inStream, boolean okToClose) static List<HostConfigEntry>readHostConfigEntries(Reader rdr, boolean okToClose) static List<HostConfigEntry>readHostConfigEntries(URL url) static List<HostConfigEntry>readHostConfigEntries(Path path, OpenOption... options) removeProperty(String name) resolveHostName(String originalHost) static StringresolveHostName(String originalName, String entryName) Resolves the effective target hoststatic StringresolveIdentityFilePath(String id, String host, int port, String username) intresolvePort(int originalPort) Resolves the effective port to usestatic intresolvePort(int originalPort, int entryPort) Resolves the effective port to useresolveProxyJump(String originalProxyJump) Resolves the effective proxyJumpstatic StringresolveProxyJump(String originalProxyJump, String entryProxyJump) Resolves the effective proxyJumpresolveUsername(String originalUser) Resolves the effective usernamestatic StringresolveUsername(String originalUser, String entryUser) Resolves the effective usernamevoidvoidsetHost(Collection<String> patterns) voidsetHostName(String hostName) voidsetIdentities(Collection<String> identities) voidsetIdentitiesOnly(boolean identitiesOnly) voidsetPort(int port) voidsetProperties(Map<String, String> properties) setProperty(String name, String value) Sets / Replaces the property valuevoidsetProxyJump(String proxyJump) voidsetUsername(String username) static HostConfigEntryResolvertoHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) toString()static List<HostConfigEntry>updateEntriesList(List<HostConfigEntry> entries, HostConfigEntry curEntry) booleanupdateGlobalHostName(String name) booleanbooleanupdateGlobalIdentityOnly(boolean identitiesOnly) booleanupdateGlobalPort(int portValue) updateGlobalProperties(Map<String, String> props) Sets all the properties for which no current value exists in the entrybooleanupdateGlobalUserName(String user) static voidwriteHostConfigEntries(OutputStream outputStream, boolean okToClose, Collection<? extends HostConfigEntry> entries) static voidwriteHostConfigEntries(Path path, Collection<? extends HostConfigEntry> entries, OpenOption... options) Methods inherited from class org.apache.sshd.client.config.hosts.HostPatternsHolder
findMatchingEntries, findMatchingEntries, getPatterns, isHostMatch, isHostMatch, isHostMatch, isPortMatch, isSpecificHostPattern, isValidPatternChar, parsePatterns, parsePatterns, setPatterns, toPattern
-
Field Details
-
STD_CONFIG_FILENAME
Standard OpenSSH config file name- See Also:
-
HOST_CONFIG_PROP
- See Also:
-
HOST_NAME_CONFIG_PROP
- See Also:
-
PORT_CONFIG_PROP
- See Also:
-
USER_CONFIG_PROP
- See Also:
-
PROXY_JUMP_CONFIG_PROP
- See Also:
-
IDENTITY_FILE_CONFIG_PROP
- See Also:
-
EXCLUSIVE_IDENTITIES_CONFIG_PROP
Use only the identities specified in the host entry (if any)- See Also:
-
DEFAULT_EXCLUSIVE_IDENTITIES
public static final boolean DEFAULT_EXCLUSIVE_IDENTITIES- See Also:
-
IDENTITY_AGENT
The IdentityAgent configuration. If not set in theHostConfigEntry, the value of thispropertyisnull, which means that a default SSH agent is to be used, if it is running. Other values defined by OpenSSH are:- none
- No SHH agent is to be used at all, even if one is running.
- SSH_AUTH_SOCK
- The SSH agent listening on the Unix domain socket given by the environment variable
SSH_AUTH_SOCKshall be used. If the environment variable is not set, no SSH agent is used. - other
- For OpenSSH, the value shall resolve to the file name of a Unix domain socket to use to connect to an SSH agent.
- See Also:
-
EXPLICIT_PROPERTIES
A case insensitiveNavigableSetof the properties that receive special handling -
MULTI_VALUE_SEPARATORS
- See Also:
-
PATH_MACRO_CHAR
public static final char PATH_MACRO_CHAR- See Also:
-
LOCAL_HOME_MACRO
public static final char LOCAL_HOME_MACRO- See Also:
-
LOCAL_USER_MACRO
public static final char LOCAL_USER_MACRO- See Also:
-
LOCAL_HOST_MACRO
public static final char LOCAL_HOST_MACRO- See Also:
-
REMOTE_HOST_MACRO
public static final char REMOTE_HOST_MACRO- See Also:
-
REMOTE_USER_MACRO
public static final char REMOTE_USER_MACRO- See Also:
-
REMOTE_PORT_MACRO
public static final char REMOTE_PORT_MACRO- See Also:
-
-
Constructor Details
-
HostConfigEntry
public HostConfigEntry() -
HostConfigEntry
-
HostConfigEntry
-
-
Method Details
-
getHost
- Returns:
- The pattern(s) represented by this entry
-
setHost
-
setHost
-
getHostName
- Returns:
- The effective host name to connect to if the pattern matches
-
setHostName
-
resolveHostName
-
getPort
public int getPort()- Returns:
- A port override - if positive
-
setPort
public void setPort(int port) -
resolvePort
public int resolvePort(int originalPort) Resolves the effective port to use- Parameters:
originalPort- The original requested port- Returns:
- If the host entry port is positive, then it is used, otherwise the original requested port
- See Also:
-
getUsername
- Specified by:
getUsernamein interfaceUsernameHolder- Returns:
- A username override - if not
null/empty
-
setUsername
- Specified by:
setUsernamein interfaceMutableUserHolder
-
resolveUsername
Resolves the effective username- Parameters:
originalUser- The original requested username- Returns:
- If the configured host entry username is not
null/empty then it is used, otherwise the original one. - See Also:
-
getProxyJump
- Returns:
- the host to use as a proxy
-
setProxyJump
-
resolveProxyJump
Resolves the effective proxyJump- Parameters:
originalProxyJump- The original requested proxyJump- Returns:
- If the configured host entry proxyJump is not
null/empty then it is used, otherwise the original one. - See Also:
-
getIdentities
- Returns:
- The current identities file paths - may be
null/empty
-
addIdentity
- Parameters:
path- APathto a file that contains an identity key - nevernull
-
addIdentity
Adds a path to an identity file- Parameters:
id- The identity path to add - nevernull
-
setIdentities
-
isIdentitiesOnly
public boolean isIdentitiesOnly()- Returns:
trueif must use only the identities in this entry
-
setIdentitiesOnly
public void setIdentitiesOnly(boolean identitiesOnly) -
getProperties
- Returns:
- A
Mapof extra properties that have been read - may benull/empty, or even contain some values that have been parsed and set as members of the entry (e.g., host, port, etc.). Note: multi-valued keys use a comma-separated list of values
-
getProperty
- Parameters:
name- Property name - nevernull/empty- Returns:
- Property value or
nullif no such property - See Also:
-
getProperty
- Parameters:
name- Property name - nevernull/emptydefaultValue- Default value to return if no such property- Returns:
- The property value or the default one if no such property
-
processGlobalValues
Updates the values that are not already configured with those from the global entry- Parameters:
globalEntry- The global entry - ignored ifnullor same reference as this entry- Returns:
trueif anything updated
-
updateGlobalProperties
Sets all the properties for which no current value exists in the entry- Parameters:
props- The global properties - ignored ifnull/empty- Returns:
- A
Mapof the updated properties
-
updateGlobalIdentities
- Parameters:
ids- Global identities - ignored ifnull/empty or already have configured identities- Returns:
trueif updated identities
-
updateGlobalUserName
- Parameters:
user- The global user name - ignored ifnull/empty or already have a configured user- Returns:
trueif updated the username
-
updateGlobalHostName
- Parameters:
name- The global host name - ignored ifnull/empty or already have a configured target host- Returns:
trueif updated the target host
-
updateGlobalPort
public boolean updateGlobalPort(int portValue) - Parameters:
portValue- The global port value - ignored if not positive or already have a configured port- Returns:
trueif updated the port value
-
updateGlobalIdentityOnly
public boolean updateGlobalIdentityOnly(boolean identitiesOnly) - Parameters:
identitiesOnly- Whether to use only the identities in this entry. Ignored if already set- Returns:
trueif updated the option value
-
processProperty
public void processProperty(String name, Collection<String> valsList, boolean ignoreAlreadyInitialized) - Parameters:
name- Property name - nevernull/emptyvalsList- The available values for the propertyignoreAlreadyInitialized- Iffalseand one of the "known" properties is encountered then throws an exception- Throws:
IllegalArgumentException- If an existing value is overwritten and ignoreAlreadyInitialized isfalse(except forIDENTITY_FILE_CONFIG_PROPwhich is cumulative- See Also:
-
appendPropertyValue
Appends a value using a comma to an existing one. If no previous value then same as callingsetProperty(String, String).- Parameters:
name- Property name - nevernull/emptyvalue- The value to be appended - ignored ifnull/empty- Returns:
- The value before appending -
nullif no previous value
-
setProperty
Sets / Replaces the property value- Parameters:
name- Property name - nevernull/emptyvalue- Property value - ifnull/empty thenremoveProperty(String)is called- Returns:
- The previous property value -
nullif no such name
-
removeProperty
- Parameters:
name- Property name - nevernull/empty- Returns:
- The removed property value -
nullif no such property name
-
setProperties
- Parameters:
properties- The properties to set - ifnullthen an empty map is effectively set. Note: it is highly recommended to use a case insensitive key mapper.
-
append
- Throws:
IOException
-
toString
-
appendNonEmptyPort
public static <A extends Appendable> A appendNonEmptyPort(A sb, String name, int port) throws IOException - Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appendername- The property name - nevernull/emptyport- The port value - ignored if non-positive- Returns:
- The target appender after having appended (or not) the value
- Throws:
IOException- If failed to append the requested data- See Also:
-
appendNonEmptyProperties
public static <A extends Appendable> A appendNonEmptyProperties(A sb, Map<String, ?> props) throws IOExceptionAppends the extra properties - while skipping theEXPLICIT_PROPERTIESones- Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appenderprops- TheMapof properties - ignored ifnull/empty- Returns:
- The target appender after having appended (or not) the value
- Throws:
IOException- If failed to append the requested data- See Also:
-
appendNonEmptyProperty
public static <A extends Appendable> A appendNonEmptyProperty(A sb, String name, Object value) throws IOException - Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appendername- The property name - nevernull/emptyvalue- The property value - ignored ifnull. Note: if the string representation of the value contains any commas, they are assumed to indicate a multi-valued property which is broken down to individual lines - one per value.- Returns:
- The target appender after having appended (or not) the value
- Throws:
IOException- If failed to append the requested data- See Also:
-
appendNonEmptyValues
public static <A extends Appendable> A appendNonEmptyValues(A sb, String name, Object... values) throws IOException - Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appendername- The property name - nevernull/emptyvalues- The values to be added - one per line - ignored ifnull/empty- Returns:
- The target appender after having appended (or not) the value
- Throws:
IOException- If failed to append the requested data- See Also:
-
appendNonEmptyValues
public static <A extends Appendable> A appendNonEmptyValues(A sb, String name, Collection<?> values) throws IOException - Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appendername- The property name - nevernull/emptyvalues- The values to be added - one per line - ignored ifnull/empty- Returns:
- The target appender after having appended (or not) the value
- Throws:
IOException- If failed to append the requested data
-
toHostConfigEntryResolver
public static HostConfigEntryResolver toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) - Parameters:
entries- The entries - ignored ifnull/empty- Returns:
- A
HostConfigEntryResolverwrapper using the entries
-
normalizeEntry
public static HostConfigEntry normalizeEntry(HostConfigEntry entry, String host, int port, String username, String proxyJump) throws IOException - Parameters:
entry- The original entry - ignored ifnullhost- The original host name / addressport- The original portusername- The original user nameproxyJump- And optional proxy jump setting- Returns:
- A cloned entry whose values are resolved - including expanding macros in the identities files
- Throws:
IOException- If failed to normalize the entry- See Also:
-
resolveHostName
Resolves the effective target host- Parameters:
originalName- The original requested hostentryName- The configured host- Returns:
- If the configured host entry is not
null/empty then it is used, otherwise the original one.
-
resolveUsername
Resolves the effective username- Parameters:
originalUser- The original requested usernameentryUser- The configured host entry username- Returns:
- If the configured host entry username is not
null/empty then it is used, otherwise the original one.
-
resolvePort
public static int resolvePort(int originalPort, int entryPort) Resolves the effective port to use- Parameters:
originalPort- The original requested portentryPort- The configured host entry port- Returns:
- If the host entry port is positive, then it is used, otherwise the original requested port
-
resolveProxyJump
Resolves the effective proxyJump- Parameters:
originalProxyJump- The original requested proxyJumpentryProxyJump- The configured host entry proxyJump- Returns:
- If the configured host entry proxyJump is not
null/empty then it is used, otherwise the original one.
-
readHostConfigEntries
public static List<HostConfigEntry> readHostConfigEntries(Path path, OpenOption... options) throws IOException - Throws:
IOException
-
readHostConfigEntries
- Throws:
IOException
-
readHostConfigEntries
public static List<HostConfigEntry> readHostConfigEntries(InputStream inStream, boolean okToClose) throws IOException - Throws:
IOException
-
readHostConfigEntries
public static List<HostConfigEntry> readHostConfigEntries(Reader rdr, boolean okToClose) throws IOException - Throws:
IOException
-
readHostConfigEntries
Reads configuration entries- Parameters:
rdr- TheBufferedReaderto use- Returns:
- The
Listof readHostConfigEntry-ies - Throws:
IOException- If failed to parse the read configuration
-
findBestMatch
Finds the best match out of the given ones.- Parameters:
matches- The available matches - ignored ifnull/empty- Returns:
- The best match or
nullif no matches or no best match found - See Also:
-
findBestMatch
Finds the best match out of the given ones.- Parameters:
matches- The available matches - ignored ifnull/empty- Returns:
- The best match or
nullif no matches or no best match found - See Also:
-
findBestMatch
Finds the best match out of the given ones. The best match is defined as one whose pattern is as specific as possible (if more than one match is available). I.e., a non-global match is preferred over global one, and a match with no wildcards is preferred over one with such a pattern.- Parameters:
matches- The available matches - ignored ifnull/empty- Returns:
- The best match or
nullif no matches or no best match found - See Also:
-
updateEntriesList
public static List<HostConfigEntry> updateEntriesList(List<HostConfigEntry> entries, HostConfigEntry curEntry) -
writeHostConfigEntries
public static void writeHostConfigEntries(Path path, Collection<? extends HostConfigEntry> entries, OpenOption... options) throws IOException - Throws:
IOException
-
writeHostConfigEntries
public static void writeHostConfigEntries(OutputStream outputStream, boolean okToClose, Collection<? extends HostConfigEntry> entries) throws IOException - Throws:
IOException
-
appendHostConfigEntries
public static <A extends Appendable> A appendHostConfigEntries(A sb, Collection<? extends HostConfigEntry> entries) throws IOException - Throws:
IOException
-
parseConfigValue
Checks if this is a multi-value - allow space and comma- Parameters:
value- The value - ignored ifnull/empty (after trimming)- Returns:
- A
Listof the encountered values
-
resolveIdentityFilePath
public static String resolveIdentityFilePath(String id, String host, int port, String username) throws IOException - Throws:
IOException
-
getDefaultHostConfigFile
- Returns:
- The default
Pathlocation of the OpenSSH hosts entries configuration file
-