Package alpine.auth

Class LdapConnectionWrapper


  • public class LdapConnectionWrapper
    extends Object
    A convenience wrapper for LDAP connections and commons LDAP tasks.
    Since:
    1.4.0
    • Field Detail

      • LDAP_ENABLED

        public static final boolean LDAP_ENABLED
      • LDAP_URL

        public static final String LDAP_URL
      • BASE_DN

        public static final String BASE_DN
      • ATTRIBUTE_MAIL

        public static final String ATTRIBUTE_MAIL
      • ATTRIBUTE_NAME

        public static final String ATTRIBUTE_NAME
      • USER_PROVISIONING

        public static final boolean USER_PROVISIONING
      • TEAM_SYNCHRONIZATION

        public static final boolean TEAM_SYNCHRONIZATION
      • LDAP_CONFIGURED

        public static final boolean LDAP_CONFIGURED
    • Constructor Detail

      • LdapConnectionWrapper

        public LdapConnectionWrapper()
    • Method Detail

      • createLdapContext

        public LdapContext createLdapContext​(String userDn,
                                             String password)
                                      throws NamingException
        Asserts a users credentials. Returns an LdapContext if assertion is successful or an exception for any other reason.
        Parameters:
        userDn - the users DN to assert
        password - the password to assert
        Returns:
        the LdapContext upon a successful connection
        Throws:
        NamingException - when unable to establish a connection
        Since:
        1.4.0
      • createDirContext

        public DirContext createDirContext()
                                    throws NamingException
        Creates a DirContext with the applications configuration settings.
        Returns:
        a DirContext
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • getGroups

        public List<String> getGroups​(DirContext dirContext,
                                      LdapUser ldapUser)
                               throws NamingException
        Retrieves a list of all groups the user is a member of.
        Parameters:
        dirContext - a DirContext
        ldapUser - the LdapUser to retrieve group membership for
        Returns:
        A list of Strings representing the fully qualified DN of each group
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • getGroups

        public List<String> getGroups​(DirContext dirContext)
                               throws NamingException
        Retrieves a list of all the groups in the directory.
        Parameters:
        dirContext - a DirContext
        Returns:
        A list of Strings representing the fully qualified DN of each group
        Throws:
        NamingException - if an exception if thrown
        Since:
        1.4.0
      • searchForGroupName

        public List<String> searchForGroupName​(DirContext dirContext,
                                               String groupName)
                                        throws NamingException
        Retrieves a list of all the groups in the directory that match the specified groupName. This is a convenience method which wraps search(DirContext, String, String).
        Parameters:
        dirContext - a DirContext
        groupName - the name (or partial name) of the group to to search for
        Returns:
        A list of Strings representing the fully qualified DN of each group
        Throws:
        NamingException - if an exception if thrown
        Since:
        1.5.0
      • searchForUserName

        public List<String> searchForUserName​(DirContext dirContext,
                                              String userName)
                                       throws NamingException
        Retrieves a list of all the users in the directory that match the specified userName. This is a convenience method which wraps search(DirContext, String, String).
        Parameters:
        dirContext - a DirContext
        userName - the name (or partial name) of the user to to search for
        Returns:
        A list of Strings representing the fully qualified DN of each username
        Throws:
        NamingException - if an exception if thrown
        Since:
        1.5.0
      • search

        public List<String> search​(DirContext dirContext,
                                   String filter,
                                   String searchTerm)
                            throws NamingException
        Retrieves a list of all the entries in the directory that match the specified filter and searchTerm
        Parameters:
        dirContext - a DirContext
        filter - a pre-defined ldap filter containing a {SEARCH_TERM} as a placeholder
        searchTerm - the search term to query on
        Returns:
        A list of Strings representing the fully qualified DN of each group
        Throws:
        NamingException - if an exception if thrown
        Since:
        1.5.0
      • searchForUsername

        public List<SearchResult> searchForUsername​(DirContext ctx,
                                                    String username)
                                             throws NamingException
        Performs a search for the specified username. Internally, this method queries on the attribute defined by Config.AlpineKey.LDAP_ATTRIBUTE_NAME.
        Parameters:
        ctx - the DirContext to use
        username - the username to query on
        Returns:
        a list of SearchResult objects. If the username is found, the list should typically only contain one result.
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • searchForSingleUsername

        public SearchResult searchForSingleUsername​(DirContext ctx,
                                                    String username)
                                             throws NamingException
        Performs a search for the specified username. Internally, this method queries on the attribute defined by Config.AlpineKey.LDAP_ATTRIBUTE_NAME.
        Parameters:
        ctx - the DirContext to use
        username - the username to query on
        Returns:
        a list of SearchResult objects. If the username is found, the list should typically only contain one result.
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • getAttribute

        public String getAttribute​(DirContext ctx,
                                   String dn,
                                   String attributeName)
                            throws NamingException
        Retrieves an attribute by its name for the specified dn.
        Parameters:
        ctx - the DirContext to use
        dn - the distinguished name of the entry to obtain the attribute value for
        attributeName - the name of the attribute to return
        Returns:
        the value of the attribute, or null if not found
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • getAttribute

        public String getAttribute​(SearchResult result,
                                   String attributeName)
                            throws NamingException
        Retrieves an attribute by its name for the specified search result.
        Parameters:
        result - the search result of the entry to obtain the attribute value for
        attributeName - the name of the attribute to return
        Returns:
        the value of the attribute, or null if not found
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • getAttribute

        public String getAttribute​(Attributes attributes,
                                   String attributeName)
                            throws NamingException
        Retrieves an attribute by its name.
        Parameters:
        attributes - the list of attributes to query on
        attributeName - the name of the attribute to return
        Returns:
        the value of the attribute, or null if not found
        Throws:
        NamingException - if an exception is thrown
        Since:
        1.4.0
      • closeQuietly

        public void closeQuietly​(NamingEnumeration object)
        Closes a NamingEnumeration object without throwing any exceptions.
        Parameters:
        object - the NamingEnumeration object to close
        Since:
        1.4.0
      • closeQuietly

        public void closeQuietly​(DirContext object)
        Closes a DirContext object without throwing any exceptions.
        Parameters:
        object - the DirContext object to close
        Since:
        1.4.0