public class HostConfigEntry extends HostPatternsHolder implements MutableUserHolder
| Modifier and Type | Class and Description |
|---|---|
private static class |
HostConfigEntry.LazyDefaultConfigFileHolder |
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_EXCLUSIVE_IDENTITIES |
static java.lang.String |
EXCLUSIVE_IDENTITIES_CONFIG_PROP
Use only the identities specified in the host entry (if any)
|
private java.lang.Boolean |
exclusiveIdentites |
static java.util.NavigableSet<java.lang.String> |
EXPLICIT_PROPERTIES
A case insensitive
NavigableSet of the properties that receive special handling |
static char |
HOME_TILDE_CHAR |
private java.lang.String |
host |
static java.lang.String |
HOST_CONFIG_PROP |
static java.lang.String |
HOST_NAME_CONFIG_PROP |
private java.lang.String |
hostName |
private java.util.Collection<java.lang.String> |
identities |
static java.lang.String |
IDENTITY_FILE_CONFIG_PROP |
static char |
LOCAL_HOME_MACRO |
static char |
LOCAL_HOST_MACRO |
static char |
LOCAL_USER_MACRO |
static java.lang.String |
MULTI_VALUE_SEPARATORS |
static char |
PATH_MACRO_CHAR |
private int |
port |
static java.lang.String |
PORT_CONFIG_PROP |
private java.util.Map<java.lang.String,java.lang.String> |
properties |
static char |
REMOTE_HOST_MACRO |
static char |
REMOTE_PORT_MACRO |
static char |
REMOTE_USER_MACRO |
static java.lang.String |
STD_CONFIG_FILENAME
Standard OpenSSH config file name
|
static java.lang.String |
USER_CONFIG_PROP |
private java.lang.String |
username |
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 and Description |
|---|
HostConfigEntry() |
HostConfigEntry(java.lang.String pattern,
java.lang.String host,
int port,
java.lang.String username) |
| Modifier and Type | Method and Description |
|---|---|
void |
addIdentity(java.nio.file.Path path) |
void |
addIdentity(java.lang.String id)
Adds a path to an identity file
|
<A extends java.lang.Appendable> |
append(A sb) |
static <A extends java.lang.Appendable> |
appendHostConfigEntries(A sb,
java.util.Collection<? extends HostConfigEntry> entries) |
static <A extends java.lang.Appendable> |
appendNonEmptyPort(A sb,
java.lang.String name,
int port) |
static <A extends java.lang.Appendable> |
appendNonEmptyProperties(A sb,
java.util.Map<java.lang.String,?> props)
Appends the extra properties - while skipping the
EXPLICIT_PROPERTIES ones |
static <A extends java.lang.Appendable> |
appendNonEmptyProperty(A sb,
java.lang.String name,
java.lang.Object value) |
static <A extends java.lang.Appendable> |
appendNonEmptyValues(A sb,
java.lang.String name,
java.util.Collection<?> values) |
static <A extends java.lang.Appendable> |
appendNonEmptyValues(A sb,
java.lang.String name,
java.lang.Object... values) |
java.lang.String |
appendPropertyValue(java.lang.String name,
java.lang.String value)
Appends a value using a comma to an existing one.
|
static java.lang.StringBuilder |
appendUserHome(java.lang.StringBuilder sb) |
static java.lang.StringBuilder |
appendUserHome(java.lang.StringBuilder sb,
java.nio.file.Path userHome) |
static java.lang.StringBuilder |
appendUserHome(java.lang.StringBuilder sb,
java.lang.String userHome) |
static HostConfigEntry |
findBestMatch(java.util.Collection<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static HostConfigEntry |
findBestMatch(java.lang.Iterable<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static HostConfigEntry |
findBestMatch(java.util.Iterator<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static java.nio.file.Path |
getDefaultHostConfigFile() |
java.lang.String |
getHost() |
java.lang.String |
getHostName() |
java.util.Collection<java.lang.String> |
getIdentities() |
int |
getPort() |
java.util.Map<java.lang.String,java.lang.String> |
getProperties() |
java.lang.String |
getProperty(java.lang.String name) |
java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultValue) |
java.lang.String |
getUsername() |
boolean |
isIdentitiesOnly() |
static HostConfigEntry |
normalizeEntry(HostConfigEntry entry,
java.lang.String host,
int port,
java.lang.String username) |
static java.util.List<java.lang.String> |
parseConfigValue(java.lang.String value)
Checks if this is a multi-value - allow space and comma
|
boolean |
processGlobalValues(HostConfigEntry globalEntry)
Updates the values that are not already configured with those
from the global entry
|
void |
processProperty(java.lang.String name,
java.util.Collection<java.lang.String> valsList,
boolean ignoreAlreadyInitialized) |
static java.util.List<HostConfigEntry> |
readHostConfigEntries(java.io.BufferedReader rdr)
Reads configuration entries
|
static java.util.List<HostConfigEntry> |
readHostConfigEntries(java.io.InputStream inStream,
boolean okToClose) |
static java.util.List<HostConfigEntry> |
readHostConfigEntries(java.nio.file.Path path,
java.nio.file.OpenOption... options) |
static java.util.List<HostConfigEntry> |
readHostConfigEntries(java.io.Reader rdr,
boolean okToClose) |
static java.util.List<HostConfigEntry> |
readHostConfigEntries(java.net.URL url) |
java.lang.String |
removeProperty(java.lang.String name) |
java.lang.String |
resolveHostName(java.lang.String originalHost) |
static java.lang.String |
resolveHostName(java.lang.String originalName,
java.lang.String entryName)
Resolves the effective target host
|
static java.lang.String |
resolveIdentityFilePath(java.lang.String id,
java.lang.String host,
int port,
java.lang.String username) |
int |
resolvePort(int originalPort)
Resolves the effective port to use
|
static int |
resolvePort(int originalPort,
int entryPort)
Resolves the effective port to use
|
java.lang.String |
resolveUsername(java.lang.String originalUser)
Resolves the effective username
|
static java.lang.String |
resolveUsername(java.lang.String originalUser,
java.lang.String entryUser)
Resolves the effective username
|
void |
setHost(java.util.Collection<java.lang.String> patterns) |
void |
setHost(java.lang.String host) |
void |
setHostName(java.lang.String hostName) |
void |
setIdentities(java.util.Collection<java.lang.String> identities) |
void |
setIdentitiesOnly(boolean identitiesOnly) |
void |
setPort(int port) |
void |
setProperties(java.util.Map<java.lang.String,java.lang.String> properties) |
java.lang.String |
setProperty(java.lang.String name,
java.lang.String value)
Sets / Replaces the property value
|
void |
setUsername(java.lang.String username) |
static HostConfigEntryResolver |
toHostConfigEntryResolver(java.util.Collection<? extends HostConfigEntry> entries) |
java.lang.String |
toString() |
static java.util.List<HostConfigEntry> |
updateEntriesList(java.util.List<HostConfigEntry> entries,
HostConfigEntry curEntry) |
boolean |
updateGlobalHostName(java.lang.String name) |
boolean |
updateGlobalIdentities(java.util.Collection<java.lang.String> ids) |
boolean |
updateGlobalIdentityOnly(boolean identitiesOnly) |
boolean |
updateGlobalPort(int portValue) |
java.util.Map<java.lang.String,java.lang.String> |
updateGlobalProperties(java.util.Map<java.lang.String,java.lang.String> props)
Sets all the properties for which no current value exists in the entry
|
boolean |
updateGlobalUserName(java.lang.String user) |
static void |
writeHostConfigEntries(java.io.OutputStream outputStream,
boolean okToClose,
java.util.Collection<? extends HostConfigEntry> entries) |
static void |
writeHostConfigEntries(java.nio.file.Path path,
java.util.Collection<? extends HostConfigEntry> entries,
java.nio.file.OpenOption... options) |
findMatchingEntries, findMatchingEntries, getPatterns, isHostMatch, isHostMatch, isHostMatch, isSpecificHostPattern, isValidPatternChar, parsePatterns, parsePatterns, setPatterns, toPatternpublic static final java.lang.String STD_CONFIG_FILENAME
public static final java.lang.String HOST_CONFIG_PROP
public static final java.lang.String HOST_NAME_CONFIG_PROP
public static final java.lang.String PORT_CONFIG_PROP
public static final java.lang.String USER_CONFIG_PROP
public static final java.lang.String IDENTITY_FILE_CONFIG_PROP
public static final java.lang.String EXCLUSIVE_IDENTITIES_CONFIG_PROP
public static final boolean DEFAULT_EXCLUSIVE_IDENTITIES
public static final java.util.NavigableSet<java.lang.String> EXPLICIT_PROPERTIES
NavigableSet of the properties that receive special handlingpublic static final java.lang.String MULTI_VALUE_SEPARATORS
public static final char HOME_TILDE_CHAR
public static final char PATH_MACRO_CHAR
public static final char LOCAL_HOME_MACRO
public static final char LOCAL_USER_MACRO
public static final char LOCAL_HOST_MACRO
public static final char REMOTE_HOST_MACRO
public static final char REMOTE_USER_MACRO
public static final char REMOTE_PORT_MACRO
private java.lang.String host
private java.lang.String hostName
private int port
private java.lang.String username
private java.lang.Boolean exclusiveIdentites
private java.util.Collection<java.lang.String> identities
private java.util.Map<java.lang.String,java.lang.String> properties
public HostConfigEntry()
public HostConfigEntry(java.lang.String pattern,
java.lang.String host,
int port,
java.lang.String username)
public java.lang.String getHost()
public void setHost(java.lang.String host)
public void setHost(java.util.Collection<java.lang.String> patterns)
public java.lang.String getHostName()
public void setHostName(java.lang.String hostName)
public java.lang.String resolveHostName(java.lang.String originalHost)
public int getPort()
public void setPort(int port)
public int resolvePort(int originalPort)
originalPort - The original requested portresolvePort(int, int)public java.lang.String getUsername()
getUsername in interface UsernameHoldernull/emptypublic void setUsername(java.lang.String username)
setUsername in interface MutableUserHolderpublic java.lang.String resolveUsername(java.lang.String originalUser)
originalUser - The original requested usernamenull/empty
then it is used, otherwise the original one.resolveUsername(String)public java.util.Collection<java.lang.String> getIdentities()
null/emptypublic void addIdentity(java.nio.file.Path path)
path - A Path to a file that contains an identity key
- never nullpublic void addIdentity(java.lang.String id)
id - The identity path to add - never nullpublic void setIdentities(java.util.Collection<java.lang.String> identities)
public boolean isIdentitiesOnly()
true if must use only the identities in this entrypublic void setIdentitiesOnly(boolean identitiesOnly)
public java.util.Map<java.lang.String,java.lang.String> getProperties()
Map of extra properties that have been read - may be
null/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 valuespublic java.lang.String getProperty(java.lang.String name)
name - Property name - never null/emptynull if no such propertygetProperty(String, String)public java.lang.String getProperty(java.lang.String name,
java.lang.String defaultValue)
name - Property name - never null/emptydefaultValue - Default value to return if no such propertypublic boolean processGlobalValues(HostConfigEntry globalEntry)
globalEntry - The global entry - ignored if null or
same reference as this entrytrue if anything updatedpublic java.util.Map<java.lang.String,java.lang.String> updateGlobalProperties(java.util.Map<java.lang.String,java.lang.String> props)
props - The global properties - ignored if null/emptyMap of the updated propertiespublic boolean updateGlobalIdentities(java.util.Collection<java.lang.String> ids)
ids - Global identities - ignored if null/empty or already
have configured identitiestrue if updated identitiespublic boolean updateGlobalUserName(java.lang.String user)
user - The global user name - ignored if null/empty or
already have a configured usertrue if updated the usernamepublic boolean updateGlobalHostName(java.lang.String name)
name - The global host name - ignored if null/empty or
already have a configured target hosttrue if updated the target hostpublic boolean updateGlobalPort(int portValue)
portValue - The global port value - ignored if not positive
or already have a configured porttrue if updated the port valuepublic boolean updateGlobalIdentityOnly(boolean identitiesOnly)
identitiesOnly - Whether to use only the identities in this entry.
Ignored if already settrue if updated the option valuepublic void processProperty(java.lang.String name,
java.util.Collection<java.lang.String> valsList,
boolean ignoreAlreadyInitialized)
name - Property name - never null/emptyvalsList - The available values for the propertyignoreAlreadyInitialized - If false and one of the "known"
properties is encountered then throws an exceptionjava.lang.IllegalArgumentException - If an existing value is overwritten and
ignoreAlreadyInitialized is false (except for IDENTITY_FILE_CONFIG_PROP
which is cumulativeHOST_NAME_CONFIG_PROP,
PORT_CONFIG_PROP,
USER_CONFIG_PROP,
IDENTITY_FILE_CONFIG_PROPpublic java.lang.String appendPropertyValue(java.lang.String name,
java.lang.String value)
setProperty(String, String).name - Property name - never null/emptyvalue - The value to be appended - ignored if null/emptynull if no previous valuepublic java.lang.String setProperty(java.lang.String name,
java.lang.String value)
name - Property name - never null/emptyvalue - Property value - if null/empty then
removeProperty(String) is callednull if no such namepublic java.lang.String removeProperty(java.lang.String name)
name - Property name - never null/emptynull if no such property namepublic void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
properties - The properties to set - if null then an empty
map is effectively set. Note: it is highly recommended to use a
case insensitive key mapper.public <A extends java.lang.Appendable> A append(A sb)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic static <A extends java.lang.Appendable> A appendNonEmptyPort(A sb,
java.lang.String name,
int port)
throws java.io.IOException
A - The Appendable typesb - The target appendername - The property name - never null/emptyport - The port value - ignored if non-positivejava.io.IOException - If failed to append the requested dataappendNonEmptyProperty(Appendable, String, Object)public static <A extends java.lang.Appendable> A appendNonEmptyProperties(A sb,
java.util.Map<java.lang.String,?> props)
throws java.io.IOException
EXPLICIT_PROPERTIES onesA - The Appendable typesb - The target appenderprops - The Map of properties - ignored if null/emptyjava.io.IOException - If failed to append the requested dataappendNonEmptyProperty(Appendable, String, Object)public static <A extends java.lang.Appendable> A appendNonEmptyProperty(A sb,
java.lang.String name,
java.lang.Object value)
throws java.io.IOException
A - The Appendable typesb - The target appendername - The property name - never null/emptyvalue - The property value - ignored if null. 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.java.io.IOException - If failed to append the requested dataappendNonEmptyValues(Appendable, String, Object...)public static <A extends java.lang.Appendable> A appendNonEmptyValues(A sb,
java.lang.String name,
java.lang.Object... values)
throws java.io.IOException
A - The Appendable typesb - The target appendername - The property name - never null/emptyvalues - The values to be added - one per line - ignored if null/emptyjava.io.IOException - If failed to append the requested dataappendNonEmptyValues(Appendable, String, Collection)public static <A extends java.lang.Appendable> A appendNonEmptyValues(A sb,
java.lang.String name,
java.util.Collection<?> values)
throws java.io.IOException
A - The Appendable typesb - The target appendername - The property name - never null/emptyvalues - The values to be added - one per line - ignored if null/emptyjava.io.IOException - If failed to append the requested datapublic static HostConfigEntryResolver toHostConfigEntryResolver(java.util.Collection<? extends HostConfigEntry> entries)
entries - The entries - ignored if null/emptyHostConfigEntryResolver wrapper using the entriespublic static HostConfigEntry normalizeEntry(HostConfigEntry entry, java.lang.String host, int port, java.lang.String username) throws java.io.IOException
entry - The original entry - ignored if nullhost - The original host name / addressport - The original portusername - The original user namejava.io.IOException - If failed to normalize the entryresolveHostName(String),
resolvePort(int),
resolveUsername(String),
resolveIdentityFilePath(String, String, int, String)public static java.lang.String resolveHostName(java.lang.String originalName,
java.lang.String entryName)
originalName - The original requested hostentryName - The configured hostnull/empty
then it is used, otherwise the original one.public static java.lang.String resolveUsername(java.lang.String originalUser,
java.lang.String entryUser)
originalUser - The original requested usernameentryUser - The configured host entry usernamenull/empty
then it is used, otherwise the original one.public static int resolvePort(int originalPort,
int entryPort)
originalPort - The original requested portentryPort - The configured host entry portpublic static java.util.List<HostConfigEntry> readHostConfigEntries(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<HostConfigEntry> readHostConfigEntries(java.net.URL url) throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.InputStream inStream, boolean okToClose) throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.Reader rdr, boolean okToClose) throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<HostConfigEntry> readHostConfigEntries(java.io.BufferedReader rdr) throws java.io.IOException
rdr - The BufferedReader to useList of read HostConfigEntry-iesjava.io.IOException - If failed to parse the read configurationpublic static HostConfigEntry findBestMatch(java.util.Collection<? extends HostConfigEntry> matches)
matches - The available matches - ignored if null/emptynull if no matches or no best match foundfindBestMatch(Iterator)public static HostConfigEntry findBestMatch(java.lang.Iterable<? extends HostConfigEntry> matches)
matches - The available matches - ignored if null/emptynull if no matches or no best match foundfindBestMatch(Iterator)public static HostConfigEntry findBestMatch(java.util.Iterator<? extends HostConfigEntry> matches)
matches - The available matches - ignored if null/emptynull if no matches or no best match foundHostPatternsHolder.isSpecificHostPattern(String)public static java.util.List<HostConfigEntry> updateEntriesList(java.util.List<HostConfigEntry> entries, HostConfigEntry curEntry)
public static void writeHostConfigEntries(java.nio.file.Path path,
java.util.Collection<? extends HostConfigEntry> entries,
java.nio.file.OpenOption... options)
throws java.io.IOException
java.io.IOExceptionpublic static void writeHostConfigEntries(java.io.OutputStream outputStream,
boolean okToClose,
java.util.Collection<? extends HostConfigEntry> entries)
throws java.io.IOException
java.io.IOExceptionpublic static <A extends java.lang.Appendable> A appendHostConfigEntries(A sb,
java.util.Collection<? extends HostConfigEntry> entries)
throws java.io.IOException
java.io.IOExceptionpublic static java.util.List<java.lang.String> parseConfigValue(java.lang.String value)
value - The value - ignored if null/empty (after trimming)List of the encountered valuespublic static java.lang.String resolveIdentityFilePath(java.lang.String id,
java.lang.String host,
int port,
java.lang.String username)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.StringBuilder appendUserHome(java.lang.StringBuilder sb)
public static java.lang.StringBuilder appendUserHome(java.lang.StringBuilder sb,
java.nio.file.Path userHome)
public static java.lang.StringBuilder appendUserHome(java.lang.StringBuilder sb,
java.lang.String userHome)
public static java.nio.file.Path getDefaultHostConfigFile()
Path location of the OpenSSH hosts entries configuration file