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.
informat.ldap.connect(info);| Parameter | Type | Description |
|---|---|---|
| info | LdapConnectionInfo | Information for connecting to LDAP server |
Return Value
Returns a LdapConnection object
Example
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
connection.close();search
Search for Entries Matching Criteria Returns entries with the base node as basedn and matching the criteria specified by filter.
connection.search(basedn, filter, control);| Parameter | Type | Description |
|---|---|---|
| basedn | String | Complete path of the root node, e.g., cn=users,dc=informat,dc=cn |
| filter | String | Search criteria |
| control | LdapSearchControl | Search control |
Return Value
Type: Array<LdapSearchResult>
Example
// 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.
connection.list(name);| Parameter | Type | Description |
|---|---|---|
| name | String | Name |
Return Value
Type: Array<LdapListResult> Returns a list of bound objects
getAttributes
Query Attributes of a Specified Node
connection.getAttributes(dn);| Parameter | Type | Description |
|---|---|---|
| dn | String | Path 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
connection.addAttribute(dn, attributes);| Parameter | Type | Description |
|---|---|---|
| dn | String | Path of the node to modify attributes |
| attributes | Array<LdapModifyAttribute> | List of attributes |
updateAttribute
Update Attributes of a Specified Node
connection.updateAttribute(dn, attributes);| Parameter | Type | Description |
|---|---|---|
| dn | String | Path of the node to modify attributes |
| attributes | Array<LdapModifyAttribute> | List of attributes |
deleteAttribute
Delete Attributes of a Specified Node
connection.deleteAttribute(dn, attributes);| Parameter | Type | Description |
|---|---|---|
| dn | String | Path of the node to modify attributes |
| attributes | Array<LdapModifyAttribute> | List of attributes |
decodeSID
Decode SID of an Account in Windows AD Domain
connection.decodeSID(sidAttribute);| Parameter | Type | Description |
|---|---|---|
| sidAttribute | Object | SID attribute value |
Return Value
Type: String Returns the decoded SID value

