Class AuthorizedKeyEntry

    • Field Detail

      • BOOLEAN_OPTION_NEGATION_INDICATOR

        public static final char BOOLEAN_OPTION_NEGATION_INDICATOR
        See Also:
        Constant Field Values
      • comment

        private java.lang.String comment
      • loginOptions

        private java.util.Map<java.lang.String,​java.lang.String> loginOptions
    • Constructor Detail

      • AuthorizedKeyEntry

        public AuthorizedKeyEntry()
    • Method Detail

      • getComment

        public java.lang.String getComment()
      • setComment

        public void setComment​(java.lang.String value)
      • getLoginOptions

        public java.util.Map<java.lang.String,​java.lang.String> getLoginOptions()
      • setLoginOptions

        public void setLoginOptions​(java.util.Map<java.lang.String,​java.lang.String> value)
      • resolvePublicKey

        public java.security.PublicKey resolvePublicKey​(SessionContext session,
                                                        PublicKeyEntryResolver fallbackResolver)
                                                 throws java.io.IOException,
                                                        java.security.GeneralSecurityException
        Parameters:
        session - 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 - 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:
        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
        Throws:
        java.io.IOException - If failed to decode the key
        java.security.GeneralSecurityException - If failed to generate the key
        See Also:
        PublicKeyEntry.resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
      • appendPublicKey

        public java.security.PublicKey appendPublicKey​(SessionContext session,
                                                       java.lang.Appendable sb,
                                                       PublicKeyEntryResolver fallbackResolver)
                                                throws java.io.IOException,
                                                       java.security.GeneralSecurityException
        Overrides:
        appendPublicKey in class PublicKeyEntry
        Parameters:
        session - The SessionContext for invoking this command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        sb - The Appendable instance to encode the data into
        fallbackResolver - 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:
        The PublicKey or null if could not resolve it
        Throws:
        java.io.IOException - If failed to decode/encode the key
        java.security.GeneralSecurityException - If failed to generate the key
        See Also:
        PublicKeyEntry.resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class PublicKeyEntry
      • readAuthorizedKeys

        public static java.util.List<AuthorizedKeyEntry> readAuthorizedKeys​(java.net.URL url)
                                                                     throws java.io.IOException
        Reads read the contents of an authorized_keys file
        Parameters:
        url - The URL to read from
        Returns:
        A List of all the AuthorizedKeyEntry-ies found there
        Throws:
        java.io.IOException - If failed to read or parse the entries
        See Also:
        readAuthorizedKeys(InputStream, boolean)
      • readAuthorizedKeys

        public static java.util.List<AuthorizedKeyEntry> readAuthorizedKeys​(java.nio.file.Path path,
                                                                            java.nio.file.OpenOption... options)
                                                                     throws java.io.IOException
        Reads read the contents of an authorized_keys file
        Parameters:
        path - Path to read from
        options - The OpenOptions to use - if unspecified then appropriate defaults assumed
        Returns:
        A List of all the AuthorizedKeyEntry-ies found there
        Throws:
        java.io.IOException - If failed to read or parse the entries
        See Also:
        readAuthorizedKeys(InputStream, boolean), Files.newInputStream(Path, OpenOption...)
      • readAuthorizedKeys

        public static java.util.List<AuthorizedKeyEntry> readAuthorizedKeys​(java.io.InputStream in,
                                                                            boolean okToClose)
                                                                     throws java.io.IOException
        Reads read the contents of an authorized_keys file
        Parameters:
        in - The InputStream to use to read the contents of an authorized_keys file
        okToClose - true if method may close the input regardless success or failure
        Returns:
        A List of all the AuthorizedKeyEntry-ies found there
        Throws:
        java.io.IOException - If failed to read or parse the entries
        See Also:
        readAuthorizedKeys(Reader, boolean)
      • readAuthorizedKeys

        public static java.util.List<AuthorizedKeyEntry> readAuthorizedKeys​(java.io.Reader rdr,
                                                                            boolean okToClose)
                                                                     throws java.io.IOException
        Reads read the contents of an authorized_keys file
        Parameters:
        rdr - The Reader to use to read the contents of an authorized_keys file
        okToClose - true if method may close the input regardless success or failure
        Returns:
        A List of all the AuthorizedKeyEntry-ies found there
        Throws:
        java.io.IOException - If failed to read or parse the entries
        See Also:
        readAuthorizedKeys(BufferedReader)
      • readAuthorizedKeys

        public static java.util.List<AuthorizedKeyEntry> readAuthorizedKeys​(java.io.BufferedReader rdr)
                                                                     throws java.io.IOException
        Parameters:
        rdr - The BufferedReader to use to read the contents of an authorized_keys file
        Returns:
        A List of all the AuthorizedKeyEntry-ies found there
        Throws:
        java.io.IOException - If failed to read or parse the entries
        See Also:
        parseAuthorizedKeyEntry(String)
      • parseAuthorizedKeyEntry

        public static AuthorizedKeyEntry parseAuthorizedKeyEntry​(java.lang.String value,
                                                                 PublicKeyEntryDataResolver resolver)
                                                          throws java.lang.IllegalArgumentException
        Parameters:
        value - Original line from an authorized_keys file
        resolver - The PublicKeyEntryDataResolver to use - if null one will be automatically resolved from the key type
        Returns:
        AuthorizedKeyEntry or null if the line is null/empty or a comment line
        Throws:
        java.lang.IllegalArgumentException - If failed to parse/decode the line
      • resolveEntryComponents

        public static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,​java.lang.String> resolveEntryComponents​(java.lang.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 - 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 java.util.NavigableMap<java.lang.String,​java.lang.String> parseLoginOptions​(java.lang.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 - The options line to parse - ignored if null/empty/blank
        Returns:
        A NavigableMap where key=case insensitive option name and value=the parsed value.
        See Also:
        addLoginOption
      • addLoginOption

        public static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,​java.lang.String> addLoginOption​(java.util.Map<java.lang.String,​java.lang.String> optsMap,
                                                                                                                         java.lang.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 to
        option - The option data to parse - ignored if null/empty/blank
        Returns:
        The updated entry - null if no option updated in the map
        Throws:
        java.lang.IllegalStateException - If a boolean option is re-specified