What is ldap-filter?
The ldap-filter npm package is used to construct and parse LDAP (Lightweight Directory Access Protocol) filters. It provides a simple and intuitive way to create complex LDAP queries programmatically.
What are ldap-filter's main functionalities?
Constructing LDAP Filters
This feature allows you to construct LDAP filters using various filter types such as AndFilter, EqualityFilter, and PresenceFilter. The code sample demonstrates creating a filter that matches entries with a common name of 'John Doe' and a presence of the 'mail' attribute.
const ldap = require('ldap-filter');
const filter = new ldap.AndFilter({
filters: [
new ldap.EqualityFilter({ attribute: 'cn', value: 'John Doe' }),
new ldap.PresenceFilter({ attribute: 'mail' })
]
});
console.log(filter.toString()); // Output: (&(cn=John Doe)(mail=*))
Parsing LDAP Filters
This feature allows you to parse LDAP filter strings into filter objects. The code sample demonstrates parsing an LDAP filter string into an object representation.
const ldap = require('ldap-filter');
const filterString = '(&(cn=John Doe)(mail=*))';
const filter = ldap.parse(filterString);
console.log(filter);
Combining Filters
This feature allows you to combine multiple filters using logical operators like AND, OR, and NOT. The code sample demonstrates combining two filters using the AND operator.
const ldap = require('ldap-filter');
const filter1 = new ldap.EqualityFilter({ attribute: 'cn', value: 'John Doe' });
const filter2 = new ldap.PresenceFilter({ attribute: 'mail' });
const combinedFilter = new ldap.AndFilter({ filters: [filter1, filter2] });
console.log(combinedFilter.toString()); // Output: (&(cn=John Doe)(mail=*))
Other packages similar to ldap-filter
ldapjs
ldapjs is a comprehensive library for interacting with LDAP servers. It includes functionality for creating and parsing LDAP filters, similar to ldap-filter, but also provides additional features for managing LDAP connections, performing searches, and handling LDAP entries.
ldapauth-fork
ldapauth-fork is a library focused on LDAP authentication. It includes some basic filter creation and parsing capabilities, but its primary purpose is to authenticate users against an LDAP server. It is less focused on the detailed construction and parsing of LDAP filters compared to ldap-filter.
activedirectory
activedirectory is a library for interacting with Active Directory, which includes LDAP functionality. It provides methods for querying and managing Active Directory entries, including filter creation and parsing. However, it is more specialized for Active Directory environments compared to the more general-purpose ldap-filter.