Class HostConfigEntry
- java.lang.Object
-
- org.apache.sshd.client.config.hosts.HostPatternsHolder
-
- org.apache.sshd.client.config.hosts.HostConfigEntry
-
- All Implemented Interfaces:
MutableUserHolder,UsernameHolder
public class HostConfigEntry extends HostPatternsHolder implements MutableUserHolder
Represents an entry in the client's configuration file as defined by the ssh_config configuration file format- See Also:
- OpenSSH Config File Examples
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHostConfigEntry.LazyDefaultConfigFileHolder
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCERTIFICATE_FILE_CONFIG_PROPstatic booleanDEFAULT_EXCLUSIVE_IDENTITIESstatic java.lang.StringEXCLUSIVE_IDENTITIES_CONFIG_PROPUse only the identities specified in the host entry (if any)protected java.lang.BooleanexclusiveIdentitesstatic java.util.NavigableSet<java.lang.String>EXPLICIT_PROPERTIESA case insensitiveNavigableSetof the properties that receive special handlingprotected java.lang.Stringhoststatic java.lang.StringHOST_CONFIG_PROPstatic java.lang.StringHOST_NAME_CONFIG_PROPprotected java.lang.StringhostNameprotected java.util.Collection<java.lang.String>identitiesstatic java.lang.StringIDENTITY_AGENTThe IdentityAgent configuration.static java.lang.StringIDENTITY_FILE_CONFIG_PROPstatic charLOCAL_HOME_MACROstatic charLOCAL_HOST_MACROstatic charLOCAL_USER_MACROstatic java.lang.StringMATCH_CONFIG_PROPstatic java.lang.StringMULTI_VALUE_SEPARATORSstatic charPATH_MACRO_CHARprotected intportstatic java.lang.StringPORT_CONFIG_PROPprotected java.util.Map<java.lang.String,java.lang.String>propertiesstatic java.lang.StringPROXY_JUMP_CONFIG_PROPprotected java.lang.StringproxyJumpstatic charREMOTE_HOST_MACROstatic charREMOTE_PORT_MACROstatic charREMOTE_USER_MACROstatic java.lang.StringSTD_CONFIG_FILENAMEStandard OpenSSH config file namestatic java.lang.StringUSER_CONFIG_PROPprotected java.lang.Stringusername-
Fields 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
Constructors Constructor Description HostConfigEntry()HostConfigEntry(java.lang.String pattern, java.lang.String host, int port, java.lang.String username)HostConfigEntry(java.lang.String pattern, java.lang.String host, int port, java.lang.String username, java.lang.String proxyJump)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIdentity(java.lang.String id)Adds a path to an identity filevoidaddIdentity(java.nio.file.Path path)<A extends java.lang.Appendable>
Aappend(A sb)static <A extends java.lang.Appendable>
AappendHostConfigEntries(A sb, java.util.Collection<? extends HostConfigEntry> entries)static <A extends java.lang.Appendable>
AappendNonEmptyPort(A sb, java.lang.String name, int port)static <A extends java.lang.Appendable>
AappendNonEmptyProperties(A sb, java.util.Map<java.lang.String,?> props)Appends the extra properties - while skipping theEXPLICIT_PROPERTIESonesstatic <A extends java.lang.Appendable>
AappendNonEmptyProperty(A sb, java.lang.String name, java.lang.Object value)static <A extends java.lang.Appendable>
AappendNonEmptyValues(A sb, java.lang.String name, java.lang.Object... values)static <A extends java.lang.Appendable>
AappendNonEmptyValues(A sb, java.lang.String name, java.util.Collection<?> values)java.lang.StringappendPropertyValue(java.lang.String name, java.lang.String value)Appends a value using a comma to an existing one.voidcollate(HostConfigEntry that)Merges that into this via underride.static java.util.List<HostConfigEntry>findMatchingEntries(java.lang.String host, java.util.Collection<? extends HostConfigEntry> entries)Locates all the matching entries for a give host name / addressstatic java.util.List<HostConfigEntry>findMatchingEntries(java.lang.String host, HostConfigEntry... entries)Locates all the matching entries for a give host name / addressstatic java.nio.file.PathgetDefaultHostConfigFile()java.lang.StringgetHost()java.lang.StringgetHostName()java.util.Collection<java.lang.String>getIdentities()intgetPort()java.util.Map<java.lang.String,java.lang.String>getProperties()java.lang.StringgetProperty(java.lang.String name)java.lang.StringgetProperty(java.lang.String name, java.lang.String defaultValue)java.lang.StringgetProxyJump()java.lang.StringgetUsername()booleanisIdentitiesOnly()static java.util.List<java.lang.String>parseConfigValue(java.lang.String value)Checks if this is a multi-value - allow space and commavoidprocessProperty(java.lang.String name, java.util.Collection<java.lang.String> valsList)static java.util.List<HostConfigEntry>readHostConfigEntries(java.io.BufferedReader rdr)Reads configuration entriesstatic java.util.List<HostConfigEntry>readHostConfigEntries(java.io.InputStream inStream, boolean okToClose)static java.util.List<HostConfigEntry>readHostConfigEntries(java.io.Reader rdr, boolean okToClose)static java.util.List<HostConfigEntry>readHostConfigEntries(java.net.URL url)static java.util.List<HostConfigEntry>readHostConfigEntries(java.nio.file.Path path, java.nio.file.OpenOption... options)java.lang.StringremoveProperty(java.lang.String name)static java.lang.StringresolveIdentityFilePath(java.lang.String id, java.lang.String host, int port, java.lang.String username)voidsetHost(java.lang.String host)voidsetHost(java.util.Collection<java.lang.String> patterns)voidsetHostName(java.lang.String hostName)voidsetIdentities(java.util.Collection<java.lang.String> identities)voidsetIdentitiesOnly(boolean identitiesOnly)voidsetPort(int port)voidsetProperties(java.util.Map<java.lang.String,java.lang.String> properties)java.lang.StringsetProperty(java.lang.String name, java.lang.String value)Sets / Replaces the property valuevoidsetProxyJump(java.lang.String proxyJump)voidsetUsername(java.lang.String username)static HostConfigEntryResolvertoHostConfigEntryResolver(java.util.Collection<? extends HostConfigEntry> entries)java.lang.StringtoString()static voidwriteHostConfigEntries(java.io.OutputStream outputStream, boolean okToClose, java.util.Collection<? extends HostConfigEntry> entries)static voidwriteHostConfigEntries(java.nio.file.Path path, java.util.Collection<? extends HostConfigEntry> entries, java.nio.file.OpenOption... options)-
Methods inherited from class org.apache.sshd.client.config.hosts.HostPatternsHolder
getPatterns, isHostMatch, isHostMatch, isHostMatch, isPortMatch, isSpecificHostPattern, isValidPatternChar, parsePatterns, parsePatterns, setPatterns, toPattern
-
-
-
-
Field Detail
-
STD_CONFIG_FILENAME
public static final java.lang.String STD_CONFIG_FILENAME
Standard OpenSSH config file name- See Also:
- Constant Field Values
-
HOST_CONFIG_PROP
public static final java.lang.String HOST_CONFIG_PROP
- See Also:
- Constant Field Values
-
MATCH_CONFIG_PROP
public static final java.lang.String MATCH_CONFIG_PROP
- See Also:
- Constant Field Values
-
HOST_NAME_CONFIG_PROP
public static final java.lang.String HOST_NAME_CONFIG_PROP
- See Also:
- Constant Field Values
-
PORT_CONFIG_PROP
public static final java.lang.String PORT_CONFIG_PROP
- See Also:
- Constant Field Values
-
USER_CONFIG_PROP
public static final java.lang.String USER_CONFIG_PROP
- See Also:
- Constant Field Values
-
PROXY_JUMP_CONFIG_PROP
public static final java.lang.String PROXY_JUMP_CONFIG_PROP
- See Also:
- Constant Field Values
-
IDENTITY_FILE_CONFIG_PROP
public static final java.lang.String IDENTITY_FILE_CONFIG_PROP
- See Also:
- Constant Field Values
-
CERTIFICATE_FILE_CONFIG_PROP
public static final java.lang.String CERTIFICATE_FILE_CONFIG_PROP
- See Also:
- Constant Field Values
-
EXCLUSIVE_IDENTITIES_CONFIG_PROP
public static final java.lang.String EXCLUSIVE_IDENTITIES_CONFIG_PROP
Use only the identities specified in the host entry (if any)- See Also:
- Constant Field Values
-
DEFAULT_EXCLUSIVE_IDENTITIES
public static final boolean DEFAULT_EXCLUSIVE_IDENTITIES
- See Also:
- Constant Field Values
-
IDENTITY_AGENT
public static final java.lang.String 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:
- Constant Field Values
-
EXPLICIT_PROPERTIES
public static final java.util.NavigableSet<java.lang.String> EXPLICIT_PROPERTIES
A case insensitiveNavigableSetof the properties that receive special handling
-
MULTI_VALUE_SEPARATORS
public static final java.lang.String MULTI_VALUE_SEPARATORS
- See Also:
- Constant Field Values
-
PATH_MACRO_CHAR
public static final char PATH_MACRO_CHAR
- See Also:
- Constant Field Values
-
LOCAL_HOME_MACRO
public static final char LOCAL_HOME_MACRO
- See Also:
- Constant Field Values
-
LOCAL_USER_MACRO
public static final char LOCAL_USER_MACRO
- See Also:
- Constant Field Values
-
LOCAL_HOST_MACRO
public static final char LOCAL_HOST_MACRO
- See Also:
- Constant Field Values
-
REMOTE_HOST_MACRO
public static final char REMOTE_HOST_MACRO
- See Also:
- Constant Field Values
-
REMOTE_USER_MACRO
public static final char REMOTE_USER_MACRO
- See Also:
- Constant Field Values
-
REMOTE_PORT_MACRO
public static final char REMOTE_PORT_MACRO
- See Also:
- Constant Field Values
-
host
protected java.lang.String host
-
hostName
protected java.lang.String hostName
-
port
protected int port
-
username
protected java.lang.String username
-
proxyJump
protected java.lang.String proxyJump
-
exclusiveIdentites
protected java.lang.Boolean exclusiveIdentites
-
identities
protected final java.util.Collection<java.lang.String> identities
-
properties
protected final java.util.Map<java.lang.String,java.lang.String> properties
-
-
Constructor Detail
-
HostConfigEntry
public HostConfigEntry()
-
HostConfigEntry
public HostConfigEntry(java.lang.String pattern, java.lang.String host, int port, java.lang.String username)
-
HostConfigEntry
public HostConfigEntry(java.lang.String pattern, java.lang.String host, int port, java.lang.String username, java.lang.String proxyJump)
-
-
Method Detail
-
collate
public void collate(HostConfigEntry that)
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
public java.lang.String getHost()
- Returns:
- The pattern(s) represented by this entry
-
setHost
public void setHost(java.lang.String host)
-
setHost
public void setHost(java.util.Collection<java.lang.String> patterns)
-
getHostName
public java.lang.String getHostName()
- Returns:
- The effective host name to connect to if the pattern matches
-
setHostName
public void setHostName(java.lang.String hostName)
-
getPort
public int getPort()
- Returns:
- A port override - if positive
-
setPort
public void setPort(int port)
-
getUsername
public java.lang.String getUsername()
- Specified by:
getUsernamein interfaceUsernameHolder- Returns:
- A username override - if not
null/empty
-
setUsername
public void setUsername(java.lang.String username)
- Specified by:
setUsernamein interfaceMutableUserHolder
-
getProxyJump
public java.lang.String getProxyJump()
- Returns:
- the host to use as a proxy
-
setProxyJump
public void setProxyJump(java.lang.String proxyJump)
-
getIdentities
public java.util.Collection<java.lang.String> getIdentities()
- Returns:
- The current identities file paths - may be
null/empty
-
addIdentity
public void addIdentity(java.nio.file.Path path)
- Parameters:
path- APathto a file that contains an identity key - nevernull
-
addIdentity
public void addIdentity(java.lang.String id)
Adds a path to an identity file- Parameters:
id- The identity path to add - nevernull
-
setIdentities
public void setIdentities(java.util.Collection<java.lang.String> identities)
-
isIdentitiesOnly
public boolean isIdentitiesOnly()
- Returns:
trueif must use only the identities in this entry
-
setIdentitiesOnly
public void setIdentitiesOnly(boolean identitiesOnly)
-
getProperties
public java.util.Map<java.lang.String,java.lang.String> 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
public java.lang.String getProperty(java.lang.String name)
- Parameters:
name- Property name - nevernull/empty- Returns:
- Property value or
nullif no such property - See Also:
getProperty(String, String)
-
getProperty
public java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)- 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
-
processProperty
public void processProperty(java.lang.String name, java.util.Collection<java.lang.String> valsList)- Parameters:
name- Property name - nevernull/emptyvalsList- The available values for the property- See Also:
HOST_NAME_CONFIG_PROP,PORT_CONFIG_PROP,USER_CONFIG_PROP,IDENTITY_FILE_CONFIG_PROP
-
appendPropertyValue
public java.lang.String appendPropertyValue(java.lang.String name, java.lang.String value)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
public java.lang.String setProperty(java.lang.String name, java.lang.String value)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
public java.lang.String removeProperty(java.lang.String name)
- Parameters:
name- Property name - nevernull/empty- Returns:
- The removed property value -
nullif no such property name
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
- 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
public <A extends java.lang.Appendable> A append(A sb) throws java.io.IOException- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
appendNonEmptyPort
public static <A extends java.lang.Appendable> A appendNonEmptyPort(A sb, java.lang.String name, int port) throws java.io.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:
java.io.IOException- If failed to append the requested data- See Also:
appendNonEmptyProperty(Appendable, String, Object)
-
appendNonEmptyProperties
public static <A extends java.lang.Appendable> A appendNonEmptyProperties(A sb, java.util.Map<java.lang.String,?> props) throws java.io.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:
java.io.IOException- If failed to append the requested data- See Also:
appendNonEmptyProperty(Appendable, String, Object)
-
appendNonEmptyProperty
public static <A extends java.lang.Appendable> A appendNonEmptyProperty(A sb, java.lang.String name, java.lang.Object value) throws java.io.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:
java.io.IOException- If failed to append the requested data- See Also:
appendNonEmptyValues(Appendable, String, Object...)
-
appendNonEmptyValues
public static <A extends java.lang.Appendable> A appendNonEmptyValues(A sb, java.lang.String name, java.lang.Object... values) throws java.io.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:
java.io.IOException- If failed to append the requested data- See Also:
appendNonEmptyValues(Appendable, String, Collection)
-
appendNonEmptyValues
public static <A extends java.lang.Appendable> A appendNonEmptyValues(A sb, java.lang.String name, java.util.Collection<?> values) throws java.io.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:
java.io.IOException- If failed to append the requested data
-
findMatchingEntries
public static java.util.List<HostConfigEntry> findMatchingEntries(java.lang.String host, 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:
HostPatternsHolder.isHostMatch(String, int)
-
findMatchingEntries
public static java.util.List<HostConfigEntry> findMatchingEntries(java.lang.String host, java.util.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:
HostPatternsHolder.isHostMatch(String, int)
-
toHostConfigEntryResolver
public static HostConfigEntryResolver toHostConfigEntryResolver(java.util.Collection<? extends HostConfigEntry> entries)
- Parameters:
entries- The entries - ignored ifnull/empty- Returns:
- A
HostConfigEntryResolverwrapper using the entries
-
readHostConfigEntries
public static java.util.List<HostConfigEntry> readHostConfigEntries(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
readHostConfigEntries
public static java.util.List<HostConfigEntry> readHostConfigEntries(java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
readHostConfigEntries
public static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.InputStream inStream, boolean okToClose) throws java.io.IOException
- Throws:
java.io.IOException
-
readHostConfigEntries
public static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.Reader rdr, boolean okToClose) throws java.io.IOException
- Throws:
java.io.IOException
-
readHostConfigEntries
public static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.BufferedReader rdr) throws java.io.IOException
Reads configuration entries- Parameters:
rdr- TheBufferedReaderto use- Returns:
- The
Listof readHostConfigEntry-ies - Throws:
java.io.IOException- If failed to parse the read configuration
-
writeHostConfigEntries
public static void writeHostConfigEntries(java.nio.file.Path path, java.util.Collection<? extends HostConfigEntry> entries, java.nio.file.OpenOption... options) throws java.io.IOException- Throws:
java.io.IOException
-
writeHostConfigEntries
public static void writeHostConfigEntries(java.io.OutputStream outputStream, boolean okToClose, java.util.Collection<? extends HostConfigEntry> entries) throws java.io.IOException- Throws:
java.io.IOException
-
appendHostConfigEntries
public static <A extends java.lang.Appendable> A appendHostConfigEntries(A sb, java.util.Collection<? extends HostConfigEntry> entries) throws java.io.IOException- Throws:
java.io.IOException
-
parseConfigValue
public static java.util.List<java.lang.String> parseConfigValue(java.lang.String value)
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 java.lang.String resolveIdentityFilePath(java.lang.String id, java.lang.String host, int port, java.lang.String username) throws java.io.IOException- Throws:
java.io.IOException
-
getDefaultHostConfigFile
public static java.nio.file.Path getDefaultHostConfigFile()
- Returns:
- The default
Pathlocation of the OpenSSH hosts entries configuration file
-
-