Package alpine.server.auth
Class LdapConnectionWrapper
java.lang.Object
alpine.server.auth.LdapConnectionWrapper
A convenience wrapper for LDAP connections and commons LDAP tasks.
- Since:
- 1.4.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseQuietly(DirContext object) Closes a DirContext object without throwing any exceptions.voidcloseQuietly(NamingEnumeration object) Closes a NamingEnumeration object without throwing any exceptions.Creates a DirContext with the applications configuration settings.createLdapContext(String userDn, String password) Asserts a users credentials.getAttribute(Attributes attributes, String attributeName) Retrieves an attribute by its name.getAttribute(DirContext ctx, String dn, String attributeName) Retrieves an attribute by its name for the specified dn.getAttribute(SearchResult result, String attributeName) Retrieves an attribute by its name for the specified search result.getGroups(DirContext dirContext) Retrieves a list of all the groups in the directory.getGroups(DirContext dirContext, LdapUser ldapUser) Retrieves a list of all groups the user is a member of.search(DirContext dirContext, String filter, String searchTerm) Retrieves a list of all the entries in the directory that match the specified filter and searchTermsearchForGroupName(DirContext dirContext, String groupName) Retrieves a list of all the groups in the directory that match the specified groupName.searchForSingleUsername(DirContext ctx, String username) Performs a search for the specified username.searchForUsername(DirContext ctx, String username) Performs a search for the specified username.searchForUserName(DirContext dirContext, String userName) Retrieves a list of all the users in the directory that match the specified userName.
-
Field Details
-
LDAP_ENABLED
public static final boolean LDAP_ENABLED -
LDAP_URL
-
BASE_DN
-
ATTRIBUTE_MAIL
-
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 Details
-
LdapConnectionWrapper
public LdapConnectionWrapper()
-
-
Method Details
-
createLdapContext
Asserts a users credentials. Returns an LdapContext if assertion is successful or an exception for any other reason.- Parameters:
userDn- the users DN to assertpassword- the password to assert- Returns:
- the LdapContext upon a successful connection
- Throws:
NamingException- when unable to establish a connection- Since:
- 1.4.0
-
createDirContext
Creates a DirContext with the applications configuration settings.- Returns:
- a DirContext
- Throws:
NamingException- if an exception is thrown- Since:
- 1.4.0
-
getGroups
Retrieves a list of all groups the user is a member of.- Parameters:
dirContext- a DirContextldapUser- 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
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 wrapssearch(DirContext, String, String).- Parameters:
dirContext- a DirContextgroupName- 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 wrapssearch(DirContext, String, String).- Parameters:
dirContext- a DirContextuserName- 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 DirContextfilter- a pre-defined ldap filter containing a {SEARCH_TERM} as a placeholdersearchTerm- 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
Performs a search for the specified username. Internally, this method queries on the attribute defined byConfig.AlpineKey.LDAP_ATTRIBUTE_NAME.- Parameters:
ctx- the DirContext to useusername- 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
Performs a search for the specified username. Internally, this method queries on the attribute defined byConfig.AlpineKey.LDAP_ATTRIBUTE_NAME.- Parameters:
ctx- the DirContext to useusername- 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
Retrieves an attribute by its name for the specified dn.- Parameters:
ctx- the DirContext to usedn- the distinguished name of the entry to obtain the attribute value forattributeName- 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
Retrieves an attribute by its name for the specified search result.- Parameters:
result- the search result of the entry to obtain the attribute value forattributeName- 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
Retrieves an attribute by its name.- Parameters:
attributes- the list of attributes to query onattributeName- 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
Closes a NamingEnumeration object without throwing any exceptions.- Parameters:
object- the NamingEnumeration object to close- Since:
- 1.4.0
-
closeQuietly
Closes a DirContext object without throwing any exceptions.- Parameters:
object- the DirContext object to close- Since:
- 1.4.0
-