Class AuthorizedKeyEntry
- java.lang.Object
-
- org.apache.sshd.common.config.keys.PublicKeyEntry
-
- org.apache.sshd.common.config.keys.AuthorizedKeyEntry
-
- All Implemented Interfaces:
Serializable
,KeyTypeIndicator
public class AuthorizedKeyEntry extends PublicKeyEntry
Represents an entry in the user'sauthorized_keys
file according to the OpenSSH format. Note:equals/hashCode
check only the key type and data - the comment and/or login options are not considered part of equality- Author:
- Apache MINA SSHD Project
- See Also:
- sshd(8) - AUTHORIZED_KEYS_FILE_FORMAT, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static char
BOOLEAN_OPTION_NEGATION_INDICATOR
-
Fields inherited from class org.apache.sshd.common.config.keys.PublicKeyEntry
COMMENT_CHAR, STD_KEYFILE_FOLDER_NAME
-
-
Constructor Summary
Constructors Constructor Description AuthorizedKeyEntry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AbstractMap.SimpleImmutableEntry<String,String>
addLoginOption(Map<String,String> optsMap, String option)
Parses and adds a new option to the options map.PublicKey
appendPublicKey(SessionContext session, Appendable sb, PublicKeyEntryResolver fallbackResolver)
boolean
equals(Object obj)
String
getComment()
Map<String,String>
getLoginOptions()
int
hashCode()
static AuthorizedKeyEntry
parseAuthorizedKeyEntry(String value)
static AuthorizedKeyEntry
parseAuthorizedKeyEntry(String value, PublicKeyEntryDataResolver resolver)
static NavigableMap<String,String>
parseLoginOptions(String options)
Parses login options line according to sshd(8) - AUTHORIZED_KEYS_FILE_FORMAT guidelines.static List<AuthorizedKeyEntry>
readAuthorizedKeys(BufferedReader rdr)
static List<AuthorizedKeyEntry>
readAuthorizedKeys(InputStream in, boolean okToClose)
Reads read the contents of anauthorized_keys
filestatic List<AuthorizedKeyEntry>
readAuthorizedKeys(Reader rdr, boolean okToClose)
Reads read the contents of anauthorized_keys
filestatic List<AuthorizedKeyEntry>
readAuthorizedKeys(URL url)
Reads read the contents of anauthorized_keys
filestatic List<AuthorizedKeyEntry>
readAuthorizedKeys(Path path, OpenOption... options)
Reads read the contents of anauthorized_keys
filestatic AbstractMap.SimpleImmutableEntry<String,String>
resolveEntryComponents(String entryLine)
Parses a single line from anauthorized_keys
file that is known to contain login options and separates it to the options and the rest of the line.PublicKey
resolvePublicKey(SessionContext session, PublicKeyEntryResolver fallbackResolver)
void
setComment(String value)
void
setLoginOptions(Map<String,String> value)
String
toString()
-
Methods inherited from class org.apache.sshd.common.config.keys.PublicKeyEntry
appendPublicKeyEntry, appendPublicKeyEntry, getDefaultKeysFolderPath, getKeyData, getKeyDataEntryResolver, getKeyDataResolver, getKeyType, getRegisteredKeyDataEntryResolvers, isEquivalent, parsePublicKeyEntry, parsePublicKeyEntry, parsePublicKeyEntry, parsePublicKeyEntry, registerKeyDataEntryResolver, resolveKeyDataEntryResolver, resolvePublicKey, resolvePublicKeyEntries, resolvePublicKeyEntryDataResolver, setKeyData, setKeyDataResolver, setKeyType, toString, toString, unregisterKeyDataEntryResolver
-
-
-
-
Field Detail
-
BOOLEAN_OPTION_NEGATION_INDICATOR
public static final char BOOLEAN_OPTION_NEGATION_INDICATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getComment
public String getComment()
-
setComment
public void setComment(String value)
-
resolvePublicKey
public PublicKey resolvePublicKey(SessionContext session, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).fallbackResolver
- ThePublicKeyEntryResolver
to consult if none of the built-in ones can be used. Ifnull
and no built-in resolver can be used then anInvalidKeySpecException
is thrown.- Returns:
- The resolved
PublicKey
- ornull
if could not be resolved. Note: may be called only after key type and data bytes have been set or exception(s) may be thrown - Throws:
IOException
- If failed to decode the keyGeneralSecurityException
- If failed to generate the key- See Also:
PublicKeyEntry.resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
-
appendPublicKey
public PublicKey appendPublicKey(SessionContext session, Appendable sb, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
- Overrides:
appendPublicKey
in classPublicKeyEntry
- Parameters:
session
- TheSessionContext
for invoking this command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).sb
- TheAppendable
instance to encode the data intofallbackResolver
- ThePublicKeyEntryResolver
to consult if none of the built-in ones can be used. Ifnull
and no built-in resolver can be used then anInvalidKeySpecException
is thrown.- Returns:
- The
PublicKey
ornull
if could not resolve it - Throws:
IOException
- If failed to decode/encode the keyGeneralSecurityException
- If failed to generate the key- See Also:
PublicKeyEntry.resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classPublicKeyEntry
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classPublicKeyEntry
-
toString
public String toString()
- Overrides:
toString
in classPublicKeyEntry
-
readAuthorizedKeys
public static List<AuthorizedKeyEntry> readAuthorizedKeys(URL url) throws IOException
Reads read the contents of anauthorized_keys
file- Parameters:
url
- TheURL
to read from- Returns:
- A
List
of all theAuthorizedKeyEntry
-ies found there - Throws:
IOException
- If failed to read or parse the entries- See Also:
readAuthorizedKeys(InputStream, boolean)
-
readAuthorizedKeys
public static List<AuthorizedKeyEntry> readAuthorizedKeys(Path path, OpenOption... options) throws IOException
Reads read the contents of anauthorized_keys
file- Parameters:
path
-Path
to read fromoptions
- TheOpenOption
s to use - if unspecified then appropriate defaults assumed- Returns:
- A
List
of all theAuthorizedKeyEntry
-ies found there - Throws:
IOException
- If failed to read or parse the entries- See Also:
readAuthorizedKeys(InputStream, boolean)
,Files.newInputStream(Path, OpenOption...)
-
readAuthorizedKeys
public static List<AuthorizedKeyEntry> readAuthorizedKeys(InputStream in, boolean okToClose) throws IOException
Reads read the contents of anauthorized_keys
file- Parameters:
in
- TheInputStream
to use to read the contents of anauthorized_keys
fileokToClose
-true
if method may close the input regardless success or failure- Returns:
- A
List
of all theAuthorizedKeyEntry
-ies found there - Throws:
IOException
- If failed to read or parse the entries- See Also:
readAuthorizedKeys(Reader, boolean)
-
readAuthorizedKeys
public static List<AuthorizedKeyEntry> readAuthorizedKeys(Reader rdr, boolean okToClose) throws IOException
Reads read the contents of anauthorized_keys
file- Parameters:
rdr
- TheReader
to use to read the contents of anauthorized_keys
fileokToClose
-true
if method may close the input regardless success or failure- Returns:
- A
List
of all theAuthorizedKeyEntry
-ies found there - Throws:
IOException
- If failed to read or parse the entries- See Also:
readAuthorizedKeys(BufferedReader)
-
readAuthorizedKeys
public static List<AuthorizedKeyEntry> readAuthorizedKeys(BufferedReader rdr) throws IOException
- Parameters:
rdr
- TheBufferedReader
to use to read the contents of anauthorized_keys
file- Returns:
- A
List
of all theAuthorizedKeyEntry
-ies found there - Throws:
IOException
- If failed to read or parse the entries- See Also:
parseAuthorizedKeyEntry(String)
-
parseAuthorizedKeyEntry
public static AuthorizedKeyEntry parseAuthorizedKeyEntry(String value) throws IllegalArgumentException
- Parameters:
value
- Original line from anauthorized_keys
file- Returns:
AuthorizedKeyEntry
ornull
if the line isnull
/empty or a comment line- Throws:
IllegalArgumentException
- If failed to parse/decode the line- See Also:
parseAuthorizedKeyEntry(String, PublicKeyEntryDataResolver)
-
parseAuthorizedKeyEntry
public static AuthorizedKeyEntry parseAuthorizedKeyEntry(String value, PublicKeyEntryDataResolver resolver) throws IllegalArgumentException
- Parameters:
value
- Original line from anauthorized_keys
fileresolver
- ThePublicKeyEntryDataResolver
to use - ifnull
one will be automatically resolved from the key type- Returns:
AuthorizedKeyEntry
ornull
if the line isnull
/empty or a comment line- Throws:
IllegalArgumentException
- If failed to parse/decode the line
-
resolveEntryComponents
public static AbstractMap.SimpleImmutableEntry<String,String> resolveEntryComponents(String entryLine)
Parses a single line from anauthorized_keys
file that is known to contain login options and separates it to the options and the rest of the line.- Parameters:
entryLine
- The line to be parsed- Returns:
- A
AbstractMap.SimpleImmutableEntry
representing the parsed data where key=login options part and value=rest of the data -null
if no data in line or line starts with comment character - See Also:
- sshd(8) - AUTHORIZED_KEYS_FILE_FORMAT
-
parseLoginOptions
public static NavigableMap<String,String> parseLoginOptions(String options)
Parses login options line according to sshd(8) - AUTHORIZED_KEYS_FILE_FORMAT guidelines. Note:
- Options that have a value are automatically stripped of any surrounding double quotes./
-
Options that have no value are marked as
true/false
- according to theBOOLEAN_OPTION_NEGATION_INDICATOR
. - Options that appear multiple times are simply concatenated using comma as separator.
- Parameters:
options
- The options line to parse - ignored ifnull
/empty/blank- Returns:
- A
NavigableMap
where key=case insensitive option name and value=the parsed value. - See Also:
addLoginOption
-
addLoginOption
public static AbstractMap.SimpleImmutableEntry<String,String> addLoginOption(Map<String,String> optsMap, String option)
Parses and adds a new option to the options map. If a valued option is re-specified then its value(s) are concatenated using comma as separator.- Parameters:
optsMap
- Options map to add tooption
- The option data to parse - ignored ifnull
/empty/blank- Returns:
- The updated entry -
null
if no option updated in the map - Throws:
IllegalStateException
- If a boolean option is re-specified
-
-