edu.northwestern.at.utils.net.ldap
Class LdapQueryAttributes

java.lang.Object
  extended by edu.northwestern.at.utils.net.ldap.LdapQueryAttributes

public class LdapQueryAttributes
extends java.lang.Object

Returns LDAP attributes for a search query involving one or more attributes.


Method Summary
static java.util.Map attributesToMap(javax.naming.directory.Attributes attributes)
          Convert LDAP attributes to map.
static javax.naming.directory.Attributes getAttributes(java.lang.String userName, java.lang.String ldapURL, java.lang.String ldapPrincipal)
          Retrieve attributes for an LDAP principal from an LDAP server.
static java.util.List getAttributes(java.lang.String userName, java.lang.String password, java.lang.String ldapURL, java.lang.String ldapPrincipal, javax.naming.directory.Attributes ldapSearchAttributes, java.lang.String keystore, boolean useSSL, boolean acceptAnyCert)
          Retrieve attributes from an LDAP server.
static java.util.Map[] getAttributesMap(javax.naming.directory.Attributes ldapSearchAttributes, java.lang.String ldapURL, java.lang.String ldapPrincipal)
          Retrieve attributes from an LDAP server as a map.
static java.util.Map[] getAttributesMap(java.lang.String userName, java.lang.String ldapURL, java.lang.String ldapPrincipal)
          Retrieve attributes for an LDAP principal from an LDAP server as a map.
static java.util.Map[] getAttributesMap(java.lang.String userName, java.lang.String password, java.lang.String ldapURL, java.lang.String ldapPrincipal, javax.naming.directory.Attributes ldapSearchAttributes, java.lang.String keystore, boolean useSSL, boolean acceptAnyCert)
          Retrieve attributes for an LDAP principal from an LDAP server as a map.
protected static boolean urlSpecifiesLDAPS(java.lang.String ldapURL)
          Check if specified URL specifies LDAPS protocol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributes

public static java.util.List getAttributes(java.lang.String userName,
                                           java.lang.String password,
                                           java.lang.String ldapURL,
                                           java.lang.String ldapPrincipal,
                                           javax.naming.directory.Attributes ldapSearchAttributes,
                                           java.lang.String keystore,
                                           boolean useSSL,
                                           boolean acceptAnyCert)
                                    throws javax.naming.NamingException
Retrieve attributes from an LDAP server.

Parameters:
userName - The user name.
password - The user password.
ldapURL - The LDAP service URL.
ldapPrincipal - The LDAP principal string.
ldapSearchAttributes - The LDAP search attributes. May be null.
keystore - The path to the SSL keystore if a non-standard certificate is used. Set to the empty string if not needed.
useSSL - True to use SSL connection.
acceptAnyCert - True to accept any certificate as valid. The keystore is ignored.
Returns:
List of Attributes entries. Each entry consists of key/value pairs for one matching object in the LDAP directory. May be empty if no attributes match or the input is invalid.
Throws:
javax.naming.NamingException - If query fails. If exception is not thrown, query succeeded, but may return empty attributes.

getAttributes

public static javax.naming.directory.Attributes getAttributes(java.lang.String userName,
                                                              java.lang.String ldapURL,
                                                              java.lang.String ldapPrincipal)
                                                       throws javax.naming.NamingException
Retrieve attributes for an LDAP principal from an LDAP server.

Parameters:
userName - The user name.
ldapURL - The LDAP service URL.
ldapPrincipal - The LDAP principal string.
Returns:
Attribute collection of key/value pairs corresponding to the bind string. May be empty if query returns no results.
Throws:
javax.naming.NamingException - if authentication fails. If exception is not thrown, authentication succeeded.

attributesToMap

public static java.util.Map attributesToMap(javax.naming.directory.Attributes attributes)
                                     throws javax.naming.NamingException
Convert LDAP attributes to map.

Parameters:
attributes - The LDAP attributes.
Returns:
Map with attribute names as keys and attribute values as values.
Throws:
javax.naming.NamingException - if not thrown, mapping succeeded.

getAttributesMap

public static java.util.Map[] getAttributesMap(java.lang.String userName,
                                               java.lang.String password,
                                               java.lang.String ldapURL,
                                               java.lang.String ldapPrincipal,
                                               javax.naming.directory.Attributes ldapSearchAttributes,
                                               java.lang.String keystore,
                                               boolean useSSL,
                                               boolean acceptAnyCert)
                                        throws javax.naming.NamingException
Retrieve attributes for an LDAP principal from an LDAP server as a map.

Parameters:
userName - The user name.
password - The user password.
ldapURL - The LDAP service URL.
ldapPrincipal - The LDAP principal string.
keystore - The path to the SSL keystore if a non-standard certificate is used. Set to the empty string if not needed.
useSSL - True to use SSL connection.
acceptAnyCert - True to accept any certificate as valid. The keystore is ignored.
Returns:
Array of Maps, one for each LDAP object's attribute key/value pairs. May be length 0 if query returns no results.
Throws:
javax.naming.NamingException - if authentication fails. If exception is not thrown, authentication succeeded.

getAttributesMap

public static java.util.Map[] getAttributesMap(java.lang.String userName,
                                               java.lang.String ldapURL,
                                               java.lang.String ldapPrincipal)
                                        throws javax.naming.NamingException
Retrieve attributes for an LDAP principal from an LDAP server as a map.

Parameters:
userName - The user name.
ldapURL - The LDAP service URL.
ldapPrincipal - The LDAP principal string.
Returns:
Map of key/value pairs corresponding to the bind string. May be empty if query returns no results.
Throws:
javax.naming.NamingException - if authentication fails. If exception is not thrown, authentication succeeded.

getAttributesMap

public static java.util.Map[] getAttributesMap(javax.naming.directory.Attributes ldapSearchAttributes,
                                               java.lang.String ldapURL,
                                               java.lang.String ldapPrincipal)
                                        throws javax.naming.NamingException
Retrieve attributes from an LDAP server as a map.

Parameters:
ldapSearchAttributes - The LDAP search attributes.
ldapURL - The LDAP service URL.
ldapPrincipal - The LDAP principal string.
Returns:
Map of key/value pairs for the FIRST matching entry in the LDAP directory.
Throws:
javax.naming.NamingException - if LDAP lookup fails.

urlSpecifiesLDAPS

protected static boolean urlSpecifiesLDAPS(java.lang.String ldapURL)
Check if specified URL specifies LDAPS protocol.

Parameters:
ldapURL - The LDAP URL.
Returns:
true if URL specifies "ldaps://" protocol.