LDAP API
The Ldap
object can be used to retrieve LDAP group membership and attributes for a specified user. It can be instantiated as follows:
// With base group and user DNs defined
let ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'ou=groups,dc=example,dc=com', 'ou=people,dc=example,dc=com', 'userPrincipalName={0}');
// Without base group and user DNs define
let ldapRoot = 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).Optional inputs are:
groupBaseDn
– The base DN to use when searching for a group.userBaseDn
– The base DN to use when searching for and/or binding a user.The result is an Ldap
object which can be used to look up users in the LDAP server.
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:
LdapUser
object from which details about the user can be retrieved.Example:
let ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'ou=groups,dc=example,dc=com', 'ou=people,dc=example,dc=com', 'userPrincipalName={0}');
let user = ldap.searchByUsername('jdoe');
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:
Example:
let ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'ou=groups,dc=example,dc=com', 'ou=people,dc=example,dc=com', 'userPrincipalName={0}');
let user = ldap.searchByUsername('jdoe');
let givenNameValues = user.getStringAttributes('givenName');
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:
true
if the user is a member of the LDAP user group and false otherwise.Example:
let ldap = LdapFactory.create('ldap://example.com:389', 'cn=administrator', 'MyAdminPassword', 'ou=groups,dc=example,dc=com', 'ou=people,dc=example,dc=com', 'userPrincipalName={0}');
let user = ldap.searchByUsername('jdoe');
let isSmileCDRUser = user.isMemberOfGroup('cn=Smile CDR Users,ou=groups,dc=example,dc=com');