Skip to content

informat.ldap LDAP Operations

Overview

Use the informat.ldap object to connect to an LDAP (Lightweight Directory Access Protocol) directory server and perform search operations.

connect

Create an LDAP Connection Connects to the LDAP server using the specified information. Throws an exception if the connection fails or if username/password authentication fails. The connect method can be used to verify if a user's username and password are valid. After successful connection, you can use the returned LdapConnection object to perform query, modify, add, and other operations. Note that you need to call the close method of LdapConnection to close the connection after completing operations.

javascript
informat.ldap.connect(info);
ParameterTypeDescription
infoLdapConnectionInfoInformation for connecting to LDAP server

Return Value

Returns a LdapConnection object

Example

js
let connection = null;
try {
  connection = informat.ldap.connect({
    providerURL: "LDAP://1.13.173.190:389",
    securityPrincipal: "user",
    securityCredentials: "pwd",
  });
} catch (e) {
  // Failed to connect to LDAP server or authentication failed
  console.error("Connection failed:", e);
} finally {
  if (connection != null) {
    connection.close();
  }
}

LdapConnection

close

Close the LDAP Connection

javascript
connection.close();

Search for Entries Matching Criteria Returns entries with the base node as basedn and matching the criteria specified by filter.

javascript
connection.search(basedn, filter, control);
ParameterTypeDescription
basednStringComplete path of the root node, e.g., cn=users,dc=informat,dc=cn
filterStringSearch criteria
controlLdapSearchControlSearch control

Return Value

Type: Array<LdapSearchResult>

Example

js
// Query 10 entries under the cn=Users,dc=informat,dc=cn directory, returning only id, name, age attributes.
const result = connect.search("cn=Users,dc=informat,dc=cn", "name=*", {
  searchScope: "SUBTREE", // Search scope, default is SUBTREE. SUBTREE returns all matching entries, ONELEVEL returns entries at the same level, OBJECT returns only the matching object
  countLimit: 10, // Optional. Maximum number of entries to return
  returningAttributes: ["id", "name", "age"], // Optional. List of attributes to return
});
// Output all entry names and their attributes
result.forEach((r) => {
  console.log(r.name);
  r.attributes.forEach((ra) => {
    console.log(ra.id + " = " + ra.values[0]);
  });
});

list

Enumerate Names Bound in a Naming Context Enumerates the names bound in a naming context and the class names of the objects bound to them.

javascript
connection.list(name);
ParameterTypeDescription
nameStringName

Return Value

Type: Array<LdapListResult> Returns a list of bound objects

getAttributes

Query Attributes of a Specified Node

javascript
connection.getAttributes(dn);
ParameterTypeDescription
dnStringPath of the node to query attributes for

Return Value

Type: Array<LdapSearchResultAttribute> Returns a list of node attributes

addAttribute

Add Attributes to a Specified Node

javascript
connection.addAttribute(dn, attributes);
ParameterTypeDescription
dnStringPath of the node to modify attributes
attributesArray<LdapModifyAttribute>List of attributes

updateAttribute

Update Attributes of a Specified Node

javascript
connection.updateAttribute(dn, attributes);
ParameterTypeDescription
dnStringPath of the node to modify attributes
attributesArray<LdapModifyAttribute>List of attributes

deleteAttribute

Delete Attributes of a Specified Node

javascript
connection.deleteAttribute(dn, attributes);
ParameterTypeDescription
dnStringPath of the node to modify attributes
attributesArray<LdapModifyAttribute>List of attributes

decodeSID

Decode SID of an Account in Windows AD Domain

javascript
connection.decodeSID(sidAttribute);
ParameterTypeDescription
sidAttributeObjectSID attribute value

Return Value

Type: String Returns the decoded SID value