Package alpine.auth
Class LdapConnectionWrapper
- java.lang.Object
-
- alpine.auth.LdapConnectionWrapper
-
public class LdapConnectionWrapper extends Object
A convenience wrapper for LDAP connections and commons LDAP tasks.- Since:
- 1.4.0
-
-
Field Summary
Fields Modifier and Type Field Description static StringATTRIBUTE_MAILstatic StringATTRIBUTE_NAMEstatic StringBASE_DNstatic booleanLDAP_CONFIGUREDstatic booleanLDAP_ENABLEDstatic StringLDAP_URLstatic booleanTEAM_SYNCHRONIZATIONstatic booleanUSER_PROVISIONING
-
Constructor Summary
Constructors Constructor Description LdapConnectionWrapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseQuietly(DirContext object)Closes a DirContext object without throwing any exceptions.voidcloseQuietly(NamingEnumeration object)Closes a NamingEnumeration object without throwing any exceptions.DirContextcreateDirContext()Creates a DirContext with the applications configuration settings.LdapContextcreateLdapContext(String userDn, String password)Asserts a users credentials.StringgetAttribute(Attributes attributes, String attributeName)Retrieves an attribute by its name.StringgetAttribute(DirContext ctx, String dn, String attributeName)Retrieves an attribute by its name for the specified dn.StringgetAttribute(SearchResult result, String attributeName)Retrieves an attribute by its name for the specified search result.List<String>getGroups(DirContext dirContext)Retrieves a list of all the groups in the directory.List<String>getGroups(DirContext dirContext, LdapUser ldapUser)Retrieves a list of all groups the user is a member of.List<String>search(DirContext dirContext, String filter, String searchTerm)Retrieves a list of all the entries in the directory that match the specified filter and searchTermList<String>searchForGroupName(DirContext dirContext, String groupName)Retrieves a list of all the groups in the directory that match the specified groupName.SearchResultsearchForSingleUsername(DirContext ctx, String username)Performs a search for the specified username.List<SearchResult>searchForUsername(DirContext ctx, String username)Performs a search for the specified username.List<String>searchForUserName(DirContext dirContext, String userName)Retrieves a list of all the users in the directory that match the specified userName.
-
-
-
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
-
-
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 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
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 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
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 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
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 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
public SearchResult searchForSingleUsername(DirContext ctx, String username) throws NamingException
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
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 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
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 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
public String getAttribute(Attributes attributes, String attributeName) throws NamingException
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
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
-
-