Class LdapPublickeyAuthenticator

  • All Implemented Interfaces:
    org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator

    public class LdapPublickeyAuthenticator
    extends LdapAuthenticator
    implements org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
    Uses LDAP to retrieve a user's registered public key and compare it with the provided one. The default search pattern attempts to retrieve the user's SSH public key value which is assumed to be in OpenSSH format. The default assumes that the value resides in the DEFAULT_PUBKEY_ATTR_NAME attribute and can be either a single or a multi-valued one
    • Field Detail

      • DEFAULT_SEARCH_FILTER_PATTERN

        public static final java.lang.String DEFAULT_SEARCH_FILTER_PATTERN
        See Also:
        Constant Field Values
      • DEFAULT_PUBKEY_ATTR_NAME

        public static final java.lang.String DEFAULT_PUBKEY_ATTR_NAME
        See Also:
        Constant Field Values
      • keyAttributeName

        private java.lang.String keyAttributeName
    • Constructor Detail

      • LdapPublickeyAuthenticator

        public LdapPublickeyAuthenticator()
    • Method Detail

      • getKeyAttributeName

        public java.lang.String getKeyAttributeName()
        Returns:
        The LDAP attribute name containing the public key - assumed by default to be in OpenSSH format
      • setKeyAttributeName

        public void setKeyAttributeName​(java.lang.String keyAttributeName)
      • authenticate

        public boolean authenticate​(java.lang.String username,
                                    java.security.PublicKey key,
                                    org.apache.sshd.server.session.ServerSession session)
        Specified by:
        authenticate in interface org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
      • authenticate

        protected boolean authenticate​(java.lang.String username,
                                       java.security.PublicKey expected,
                                       org.apache.sshd.server.session.ServerSession session,
                                       java.util.Map<java.lang.String,​?> attrs)
                                throws java.security.GeneralSecurityException,
                                       java.io.IOException
        Parameters:
        username - The SSH username attempting to authenticate
        expected - The provided PublicKey
        session - The ServerSession
        attrs - The extracted LDAP attributes Map
        Returns:
        true whether to accept the presented public key
        Throws:
        java.security.GeneralSecurityException - If failed to recover the public key(s)
        java.io.IOException - If failed to parse the public key(s) data
        See Also:
        recoverPublicKeys(String, PublicKey, ServerSession, Map, Object), authenticate(String, PublicKey, ServerSession, Map, Collection)
      • authenticate

        protected boolean authenticate​(java.lang.String username,
                                       java.security.PublicKey expected,
                                       org.apache.sshd.server.session.ServerSession session,
                                       java.util.Map<java.lang.String,​?> attrs,
                                       java.util.Collection<? extends java.security.PublicKey> keys)
        Parameters:
        username - The SSH username attempting to authenticate
        expected - The provided PublicKey
        session - The ServerSession
        attrs - The extracted LDAP attributes Map
        keys - The Collection of recovered PublicKeys - may be null/empty
        Returns:
        true whether to accept the presented public key
      • recoverPublicKeys

        protected java.util.List<java.security.PublicKey> recoverPublicKeys​(java.lang.String username,
                                                                            java.security.PublicKey expected,
                                                                            org.apache.sshd.server.session.ServerSession session,
                                                                            java.util.Map<java.lang.String,​?> attrs,
                                                                            java.lang.Object keyData)
                                                                     throws java.security.GeneralSecurityException,
                                                                            java.io.IOException
        Parameters:
        username - The SSH username attempting to authenticate
        expected - The provided PublicKey
        session - The ServerSession
        attrs - The extracted LDAP attributes Map
        keyData - The value of the getKeyAttributeName() attribute - may be null, a single object or a collection of such (if multi-valued attribute)
        Returns:
        A List of the recovered PublicKeys - may be null/empty
        Throws:
        java.security.GeneralSecurityException - If failed to recover the public key(s)
        java.io.IOException - If failed to parse the public key(s) data
        See Also:
        parsePublicKeyValue(String, PublicKey, ServerSession, Map, Object)
      • parsePublicKeyValue

        protected java.security.PublicKey parsePublicKeyValue​(java.lang.String username,
                                                              java.security.PublicKey expected,
                                                              org.apache.sshd.server.session.ServerSession session,
                                                              java.util.Map<java.lang.String,​?> attrs,
                                                              java.lang.Object keyData)
                                                       throws java.security.GeneralSecurityException,
                                                              java.io.IOException
        Parameters:
        username - The SSH username attempting to authenticate
        expected - The provided PublicKey
        session - The ServerSession
        attrs - The extracted LDAP attributes Map
        keyData - One of the values (if multi-valued attribute) - may be null
        Returns:
        The extracted PublicKey or null if none available
        Throws:
        java.security.GeneralSecurityException - If failed to recover the public key
        java.io.IOException - If failed to parse the public key data