Class DefaultAuthorizedKeysAuthenticator

  • All Implemented Interfaces:
    UsernameHolder, PublickeyAuthenticator

    public class DefaultAuthorizedKeysAuthenticator
    extends AuthorizedKeysAuthenticator
    implements UsernameHolder
    Monitors the ~/.ssh/authorized_keys file of the user currently running the server, re-loading it if necessary. It also (optionally) enforces the same permissions regime as OpenSSH does for the file permissions. By default also compares the current username with the authenticated one.
    • Field Detail

      • strict

        private final boolean strict
      • user

        private final java.lang.String user
    • Constructor Detail

      • DefaultAuthorizedKeysAuthenticator

        public DefaultAuthorizedKeysAuthenticator​(boolean strict)
        Parameters:
        strict - If true then makes sure that the containing folder has 0700 access and the file 0600. Note: for Windows it does not check these permissions
      • DefaultAuthorizedKeysAuthenticator

        public DefaultAuthorizedKeysAuthenticator​(java.lang.String user,
                                                  boolean strict)
      • DefaultAuthorizedKeysAuthenticator

        public DefaultAuthorizedKeysAuthenticator​(java.nio.file.Path path,
                                                  boolean strict,
                                                  java.nio.file.LinkOption... options)
      • DefaultAuthorizedKeysAuthenticator

        public DefaultAuthorizedKeysAuthenticator​(java.lang.String user,
                                                  java.nio.file.Path path,
                                                  boolean strict,
                                                  java.nio.file.LinkOption... options)
    • Method Detail

      • getUsername

        public final java.lang.String getUsername()
        Specified by:
        getUsername in interface UsernameHolder
        Returns:
        The attached username - may be null/empty if holder not yet initialized
      • isStrict

        public final boolean isStrict()
      • validateFilePath

        protected java.nio.file.Path validateFilePath​(java.nio.file.Path path,
                                                      java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms,
                                                      java.util.Collection<java.nio.file.attribute.PosixFilePermission> excluded)
                                               throws java.io.IOException
        Parameters:
        path - The Path to be validated
        perms - The current PosixFilePermissions
        excluded - The permissions not allowed to exist
        Returns:
        The original path
        Throws:
        java.io.IOException - If an excluded permission appears in the current ones