On this page:

21.8LDAP API

 

The Ldap object can be used to retrieve LDAP group membership and attributes for a specified user. It can be instantiated as follows:

var ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'userPrincipalName={0}');

Required inputs are:

  • url – The URL to connect to the LDAP server.
  • user – The system user distinguished name (DN).
  • password – The system user password.
  • userQuery – The LDAP query parameter to use when searching for a user (i.e. the username field in LDAP).

The result is an Ldap object which can be used to look up users in the LDAP server.

21.8.1Method: searchByUsername(username)

 

Queries the LDAP server for a specified user identified by the provided username value.

Inputs:

  • username – The LDAP query identifier value for the user.

Outputs:

  • Returns an LdapUser object from which details about the user can be retrieved.

Example:

var ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'userPrincipalName={0}');
var user = ldap.searchLdapByUsername('jdoe');

21.8.2Method: getStringAttributes(attributeName)

 

Retrieves values, if any, for a named attribute of an LDAP user.

Inputs:

  • attributeName – the name of the LDAP attribute to retrieve for the user.

Outputs:

  • Returns an array of attribute values for the LDAP user attribute.

Example:

var ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'userPrincipalName={0}');
var user = ldap.searchLdapByUsername('jdoe');
var givenNameValues = user.getStringAttributes('givenName');

21.8.3Method: isMemberOfGroup(groupDn)

 

Used to determine whether a user is a member of a designated LDAP group.

Inputs:

  • groupDn – the Distinguished Name (dn) identifying the LDAP user group.

Outputs:

  • Returns true if the user is a member of the LDAP user group and false otherwise.

Example:

var ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'userPrincipalName={0}');
var user = ldap.searchLdapByUsername('jdoe');
var isSmileCDRUser = user.isMemberOfGroup('cn=Smile CDR Users,ou=groups,dc=example,dc=com');