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 StringUnmodifiable set of OpenSSH config file keys that can be specified multiple times building up a list.static final Stringstatic final Stringstatic final booleanstatic final StringUse only the identities specified in the host entry (if any)static final Stringstatic final Stringstatic final Stringprotected Stringstatic final StringThe IdentityAgent configuration.static final StringA modifiable map of config key aliases, mapping aliases to a canonical name.Unmodifiable set of OpenSSH config file keys that take a whitespace-separated list of values.static final Stringstatic final charstatic final charstatic final charstatic final Stringstatic final Stringstatic final charstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final charstatic final charstatic final charstatic final Stringstatic final Stringstatic final StringStandard OpenSSH config file namestatic final Stringstatic final String -
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) Writes a string representation with each property on a line to the givenAppendable, usingSystem.lineSeparator()to end each line.static <A extends Appendable>
AappendHostConfigEntries(A sb, Collection<? extends HostConfigEntry> entries) Writes all given entries to the givenAppendable.static <A extends Appendable>
AappendNonEmptyProperties(A sb, Map<String, List<String>> props) Appends the properties.static <A extends Appendable>
AappendNonEmptyProperty(A sb, String name, List<String> value) static <A extends Appendable>
AappendValue(A sb, String value) voidclear()voidcollate(HostConfigEntry that) Merges that into this via underride.static List<HostConfigEntry> findMatchingEntries(String host, Collection<? extends HostConfigEntry> entries) Locates all the matching entries for a give host name / addressstatic List<HostConfigEntry> findMatchingEntries(String host, HostConfigEntry... entries) Locates all the matching entries for a give host name / addressstatic PathgetHost()intgetPort()Retrieves the rawMapof properties.getProperty(String name) Retrieves the single value of a property.getProperty(String name, String defaultValue) Retrieves the single value of a property.Retrieves all the values of a property.booleanparseConfigValue(String value) Parses a host config value in a list of whitespace-separated elements, handling OpenSSH-style quoting.Splits the argument into a list of whitespace-separated elements.static intparseToken(String argument, int from, int to, List<String> result) Parses a token up to the next whitespace not inside a string quoted by single or double quotes.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) Removes a property.static StringresolveIdentityFilePath(String id, String host, int port, String username) voidvoidsetHost(Collection<String> patterns) voidsetHostName(String hostName) voidsetIdentities(Collection<String> identities) voidsetIdentitiesOnly(boolean identitiesOnly) voidsetPort(int port) voidsetProperty(String name, String value) Sets or replaces the property value.voidsetProperty(String name, List<String> value) Sets or replaces the property value.voidsetProxyJump(String proxyJump) voidsetUsername(String username) static HostConfigEntryResolvertoHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) toString()static voidwriteHostConfigEntries(OutputStream outputStream, boolean okToClose, Collection<? extends HostConfigEntry> entries) static voidwriteHostConfigEntries(Path path, Collection<? extends HostConfigEntry> entries, OpenOption... options) Methods inherited from class HostPatternsHolder
getPatterns, isHostMatch, isHostMatch, isHostMatch, isPortMatch, isSpecificHostPattern, isValidPatternChar, parsePatterns, parsePatterns, setPatterns, toPattern
-
Field Details
-
STD_CONFIG_FILENAME
-
HOST_CONFIG_PROP
- See Also:
-
MATCH_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:
-
CERTIFICATE_FILE_CONFIG_PROP
- See Also:
-
LOCAL_FORWARD_CONFIG_PROP
- See Also:
-
REMOTE_FORWARD_CONFIG_PROP
- See Also:
-
SEND_ENV_CONFIG_PROP
- See Also:
-
SET_ENV_CONFIG_PROP
- See Also:
-
PUBKEY_ACCEPTED_ALGORITHMS_CONFIG_PROP
- See Also:
-
ADD_KEYS_TO_AGENT_CONFIG_PROP
- See Also:
-
CANONICAL_DOMAINS_CONFIG_PROP
- See Also:
-
GLOBAL_KNOWN_HOSTS_CONFIG_PROP
- See Also:
-
USER_KNOWN_HOSTS_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:
-
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:
-
ADDITIVE_KEYS
-
LIST_KEYS
-
KEY_ALIASES
-
hostPatterns
-
properties
-
-
Constructor Details
-
HostConfigEntry
public HostConfigEntry() -
HostConfigEntry
-
HostConfigEntry
-
-
Method Details
-
collate
Merges that into this via underride. That is, any value present in this entry takes precedence over the given entry. Only this object is modified. The given entry remains unchanged.- Parameters:
that- The HostConfigEntry to merge.
-
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
-
getPort
public int getPort()- Returns:
- A port override - if positive
-
setPort
public void setPort(int port) -
getUsername
- Specified by:
getUsernamein interfaceUsernameHolder- Returns:
- A username override - if not
null/empty
-
setUsername
- Specified by:
setUsernamein interfaceMutableUserHolder
-
getProxyJump
- Returns:
- the host to use as a proxy
-
setProxyJump
-
getIdentities
- Returns:
- The current identities file paths; may be empty
-
addIdentity
-
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
-
clear
public void clear() -
getValues
Retrieves all the values of a property. If the property anadditiveorlist-valuedproperty, the result may contain more than one value.- Parameters:
name- of the property to get the values of; must not benullor empty- Returns:
- the values, as an unmodifiable list, may be
null
-
getProperty
Retrieves the single value of a property. If called for anadditiveorlist-valuedkey that has several values, only the first one is returned.- Parameters:
name- of the property to get the values of; must not benullor empty- Returns:
- the property value or
nullif not set - See Also:
-
getProperty
Retrieves the single value of a property. If called for anadditiveorlist-valuedkey that has several values, only the first one is returned. If the property is not set, returns the givendefaultValue.- Parameters:
name- of the property to get the values of; must not benullor emptydefaultValue- value to return if not set, may benull- Returns:
- the property value or
defaultValueif not set
-
setProperty
Sets or replaces the property value. If thevalueisnullor empty, the property is removed. Otherwise, if it's aadditiveproperty, the new value is added to any previously added values. Otherwise, the existing value is replaced by the new value.- Parameters:
name- of the property to set the value; must not benullor emptyvalue- to set; ifnullor empty, the property is removed
-
setProperty
Sets or replaces the property value. If thevalueisnullor empty, the property is removed. Otherwise, the existing value is replaced by the new value.- Parameters:
name- of the property to set the value; must not benullor emptyvalue- to set; ifnullor empty, the property is removed
-
removeProperty
-
append
Writes a string representation with each property on a line to the givenAppendable, usingSystem.lineSeparator()to end each line.- Type Parameters:
A- TheAppendabletype- Parameters:
sb- TheAppendableto write to- Returns:
sb- Throws:
IOException
-
toString
-
appendNonEmptyProperties
public static <A extends Appendable> A appendNonEmptyProperties(A sb, Map<String, List<String>> props) throws IOException Appends the properties.- Type Parameters:
A- TheAppendabletype- Parameters:
sb- The target appenderprops- TheMapof properties - ignored ifnull/empty- Returns:
- the target appender
- Throws:
IOException
-
appendNonEmptyProperty
public static <A extends Appendable> A appendNonEmptyProperty(A sb, String name, List<String> 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
-
appendValue
- Throws:
IOException
-
findMatchingEntries
Locates all the matching entries for a give host name / address- Parameters:
host- The host name / address - ignored ifnull/emptyentries- TheHostConfigEntry-ies to scan - ignored ifnull/empty- Returns:
- A
Listof all the matching entries - See Also:
-
findMatchingEntries
public static List<HostConfigEntry> findMatchingEntries(String host, Collection<? extends HostConfigEntry> entries) Locates all the matching entries for a give host name / address- Parameters:
host- The host name / address - ignored ifnull/emptyentries- TheHostConfigEntry-ies to scan - ignored ifnull/empty- Returns:
- A
Listof all the matching entries - See Also:
-
toHostConfigEntryResolver
public static HostConfigEntryResolver toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) - Parameters:
entries- The entries - ignored ifnull/empty- Returns:
- A
HostConfigEntryResolverwrapper using the entries
-
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
-
parseList
Splits the argument into a list of whitespace-separated elements. Elements containing whitespace must be quoted and will be de-quoted. Backslash-escapes are handled for quotes and blanks.- Parameters:
argument- argument part of the configuration line as read from the config file- Returns:
- a
Listof elements, possibly empty and possibly containing empty elements, but not containingnull
-
parseToken
Parses a token up to the next whitespace not inside a string quoted by single or double quotes. Inside a string, quotes can be escaped by backslash characters. Outside of a string, "\ " can be used to include a space in a token; inside a string "\ " is taken literally as '\' followed by ' '.- Parameters:
argument- to parse the token out offrom- index at the beginning of the tokento- index one after the last character to look atresult- a list collecting tokens to which the parsed token is added- Returns:
- the index after the token
-
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 Writes all given entries to the givenAppendable.- Type Parameters:
A- TheAppendabletype- Parameters:
sb- TheAppendableto write toentries- the entries to write- Returns:
sb- Throws:
IOException
-
parseConfigValue
-
resolveIdentityFilePath
public static String resolveIdentityFilePath(String id, String host, int port, String username) throws IOException - Throws:
IOException
-
getDefaultHostConfigFile
-