Top Description Fields Constructors Methods
org.apache.sshd.common.config.keys

public Class AuthorizedKeyEntry

extends PublicKeyEntry
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .Reader, .StreamCorruptedException, java.net.URL, java.nio.charset.StandardCharsets, java.nio.file.Files, .OpenOption, .Path, java.security.GeneralSecurityException, .PublicKey, java.security.spec.InvalidKeySpecException, java.util.AbstractMap.SimpleImmutableEntry, .ArrayList, .Collections, .List, .Map, .NavigableMap, .TreeMap, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.util.GenericUtils, .MapEntryUtils, .ValidateUtils, org.apache.sshd.common.util.io.input.NoCloseInputStream, .NoCloseReader

Represents an entry in the user's authorized_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

Field Summary

Modifier and TypeField and Description
public static final char
private String
private Map<String, String>
private static final long
Inherited from org.apache.sshd.common.config.keys.PublicKeyEntry:
COMMENT_CHARPUBKEY_FILE_SUFFIXSTD_KEYFILE_FOLDER_NAME

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static AbstractMap.SimpleImmutableEntry<String, String>

Returns:

The updated entry - null if no option updated in the map
addLoginOption
(Map<String, String>
Options map to add to
optsMap
,
String
The option data to parse - ignored if null/empty/blank
option
)

Parses and adds a new option to the options map.

public PublicKey
appendPublicKey(SessionContext
The SessionContext for invoking this command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
Appendable
The Appendable instance to encode the data into
sb
,
PublicKeyEntryResolver
The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.
fallbackResolver
)

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.equals.

Indicates whether some other object is "equal to" this one.

public String
public Map<String, String>
public int
hashCode()

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.hashCode.

Returns a hash code value for this object.

public static AuthorizedKeyEntry

Returns:

AuthorizedKeyEntry or null if the line is null/empty or a comment line
parseAuthorizedKeyEntry
(String
Original line from an authorized_keys file
value
)

public static AuthorizedKeyEntry

Returns:

AuthorizedKeyEntry or null if the line is null/empty or a comment line
parseAuthorizedKeyEntry
(String
Original line from an authorized_keys file
value
,
PublicKeyEntryDataResolver
The PublicKeyEntryDataResolver to use - if null one will be automatically resolved from the key type
resolver
)

public static NavigableMap<String, String>

Returns:

A NavigableMap where key=case insensitive option name and value=the parsed value.
parseLoginOptions
(String
The options line to parse - ignored if null/empty/blank
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 the BOOLEAN_OPTION_NEGATION_INDICATOR.
  • Options that appear multiple times are simply concatenated using comma as separator.
public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there
readAuthorizedKeys
(URL
The URL to read from
url
)

Reads read the contents of an authorized_keys file

public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there
readAuthorizedKeys
(Path
Path to read from
path
,
OpenOption...
The OpenOptions to use - if unspecified then appropriate defaults assumed
options
)

Reads read the contents of an authorized_keys file

public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there
readAuthorizedKeys
(InputStream
The InputStream to use to read the contents of an authorized_keys file
in
,
boolean
true if method may close the input regardless success or failure
okToClose
)

Reads read the contents of an authorized_keys file

public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there
readAuthorizedKeys
(Reader
The Reader to use to read the contents of an authorized_keys file
rdr
,
boolean
true if method may close the input regardless success or failure
okToClose
)

Reads read the contents of an authorized_keys file

public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there
readAuthorizedKeys
(BufferedReader
The BufferedReader to use to read the contents of an authorized_keys file
rdr
)

public static AbstractMap.SimpleImmutableEntry<String, String>

Returns:

A 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
resolveEntryComponents
(String
The line to be parsed
entryLine
)

Parses a single line from an authorized_keys file that is known to contain login options and separates it to the options and the rest of the line.

public PublicKey

Returns:

The resolved PublicKey - or null 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

resolvePublicKey
(SessionContext
The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
PublicKeyEntryResolver
The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.
fallbackResolver
)

public void
public void
public String
toString()

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.toString.

Returns a string representation of the object.

Inherited from org.apache.sshd.common.config.keys.PublicKeyEntry:
appendPublicKeyEntryappendPublicKeyEntrygetDefaultKeysFolderPathgetKeyDatagetKeyDataEntryResolvergetKeyDataResolvergetKeyTypegetRegisteredKeyDataEntryResolversisEquivalentparsePublicKeyEntryparsePublicKeyEntryparsePublicKeyEntryparsePublicKeyEntryregisterKeyDataEntryResolverresolveKeyDataEntryResolverresolvePublicKeyresolvePublicKeyEntriesresolvePublicKeyEntryDataResolversetKeyDatasetKeyDataResolversetKeyTypetoStringtoStringunregisterKeyDataEntryResolver

Field Detail

BOOLEAN_OPTION_NEGATION_INDICATORback to summary
public static final char BOOLEAN_OPTION_NEGATION_INDICATOR
commentback to summary
private String comment
loginOptionsback to summary
private Map<String, String> loginOptions
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.sshd.common.config.keys.PublicKeyEntry.serialVersionUID.

Constructor Detail

AuthorizedKeyEntryback to summary
public AuthorizedKeyEntry()

Method Detail

addLoginOptionback to summary
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:Map<String, String>

Options map to add to

option:String

The option data to parse - ignored if null/empty/blank

Returns:AbstractMap.SimpleImmutableEntry<String, String>

The updated entry - null if no option updated in the map

Exceptions
IllegalStateException:
If a boolean option is re-specified
appendPublicKeyback to summary
public PublicKey appendPublicKey(SessionContext session, Appendable sb, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

Parameters
session:SessionContext

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

The SessionContext for invoking this command - may be null if not invoked within a session context (e.g., offline tool or session unknown).

sb:Appendable

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

The Appendable instance to encode the data into

fallbackResolver:PublicKeyEntryResolver

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.

Returns:PublicKey

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

The PublicKey or null if could not resolve it

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

If failed to decode/encode the key

GeneralSecurityException:

Doc from org.apache.sshd.common.config.keys.PublicKeyEntry.appendPublicKey.

If failed to generate the key

equalsback to summary
public boolean equals(Object obj)

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCommentback to summary
public String getComment()
getLoginOptionsback to summary
public Map<String, String> getLoginOptions()
hashCodeback to summary
public int hashCode()

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
parseAuthorizedKeyEntryback to summary
public static AuthorizedKeyEntry parseAuthorizedKeyEntry(String value) throws IllegalArgumentException
Parameters
value:String

Original line from an authorized_keys file

Returns:AuthorizedKeyEntry

AuthorizedKeyEntry or null if the line is null/empty or a comment line

Exceptions
IllegalArgumentException:
If failed to parse/decode the line
See Also
parseAuthorizedKeyEntry(String, PublicKeyEntryDataResolver)
parseAuthorizedKeyEntryback to summary
public static AuthorizedKeyEntry parseAuthorizedKeyEntry(String value, PublicKeyEntryDataResolver resolver) throws IllegalArgumentException
Parameters
value:String

Original line from an authorized_keys file

resolver:PublicKeyEntryDataResolver

The PublicKeyEntryDataResolver to use - if null one will be automatically resolved from the key type

Returns:AuthorizedKeyEntry

AuthorizedKeyEntry or null if the line is null/empty or a comment line

Exceptions
IllegalArgumentException:
If failed to parse/decode the line
parseLoginOptionsback to summary
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 the BOOLEAN_OPTION_NEGATION_INDICATOR.
  • Options that appear multiple times are simply concatenated using comma as separator.
Parameters
options:String

The options line to parse - ignored if null/empty/blank

Returns:NavigableMap<String, String>

A NavigableMap where key=case insensitive option name and value=the parsed value.

See Also
addLoginOption
readAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readAuthorizedKeys(URL url) throws IOException

Reads read the contents of an authorized_keys file

Parameters
url:URL

The URL to read from

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there

Exceptions
IOException:
If failed to read or parse the entries
See Also
readAuthorizedKeys(InputStream, boolean)
readAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readAuthorizedKeys(Path path, OpenOption... options) throws IOException

Reads read the contents of an authorized_keys file

Parameters
path:Path

Path to read from

options:OpenOption[]

The OpenOptions to use - if unspecified then appropriate defaults assumed

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there

Exceptions
IOException:
If failed to read or parse the entries
See Also
readAuthorizedKeys(InputStream, boolean), Files#newInputStream(Path, OpenOption...)
readAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readAuthorizedKeys(InputStream in, boolean okToClose) throws IOException

Reads read the contents of an authorized_keys file

Parameters
in:InputStream

The InputStream to use to read the contents of an authorized_keys file

okToClose:boolean

true if method may close the input regardless success or failure

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there

Exceptions
IOException:
If failed to read or parse the entries
See Also
readAuthorizedKeys(Reader, boolean)
readAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readAuthorizedKeys(Reader rdr, boolean okToClose) throws IOException

Reads read the contents of an authorized_keys file

Parameters
rdr:Reader

The Reader to use to read the contents of an authorized_keys file

okToClose:boolean

true if method may close the input regardless success or failure

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there

Exceptions
IOException:
If failed to read or parse the entries
See Also
readAuthorizedKeys(BufferedReader)
readAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readAuthorizedKeys(BufferedReader rdr) throws IOException
Parameters
rdr:BufferedReader

The BufferedReader to use to read the contents of an authorized_keys file

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there

Exceptions
IOException:
If failed to read or parse the entries
See Also
parseAuthorizedKeyEntry(String)
resolveEntryComponentsback to summary
public static AbstractMap.SimpleImmutableEntry<String, String> resolveEntryComponents(String entryLine)

Parses a single line from an authorized_keys file that is known to contain login options and separates it to the options and the rest of the line.

Parameters
entryLine:String

The line to be parsed

Returns:AbstractMap.SimpleImmutableEntry<String, String>

A 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
resolvePublicKeyback to summary
public PublicKey resolvePublicKey(SessionContext session, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
Parameters
session:SessionContext

The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).

fallbackResolver:PublicKeyEntryResolver

The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.

Returns:PublicKey

The resolved PublicKey - or null 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

Exceptions
IOException:
If failed to decode the key
GeneralSecurityException:
If failed to generate the key
See Also
PublicKeyEntry#resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
setCommentback to summary
public void setComment(String value)
setLoginOptionsback to summary
public void setLoginOptions(Map<String, String> value)
toStringback to summary
public String toString()

Overrides org.apache.sshd.common.config.keys.PublicKeyEntry.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override