Json2Ldap offers new LDAP utility functions

Json2Ldap iconJson2Ldap, the LDAP gateway for accessing directory servers from web devices and browser applications, now offers a new set of utility functions. These are related to distinct name (DN) processing and search filters. This new functionality is available in the latest Json2Ldap 1.8, which was released on 17 March.

Here I’ll give you a brief overview of what these functions do and how you may use them. Note that these are quite simple JSON-RPC requests that don’t require a connection to the back-end directory. They are “static” and you can use them without any prior LDAP connection set up.

DN functions

A set of functions related to distinct name (DN) processing.

  • ldap.util.isValidDN Allows checking of DN validity. Use to validate DNs input by users or read from configuration files.
  • ldap.util.normalizeDN Quick function for normalising a DN string. It removes all redundant whitespace and converts all characters to lower case (assuming the RDN component values are case-insensitive). Use if you intend to use the DN as a key in a hash map or if you want to store it in a normalised form.
  • ldap.util.compareDNs Compares two DNs for equality, taking account of multi-valued RDNs if any.  Use it to make sure two DNs are equal.

Here is an example JSON-RPC 2.0 request to validate a DN string:

{ "method"  : "ldap.util.isValidDN",
  "params"  : { "DN" : "cn=Alice Wonderland,ou=people,dc=example,dc=com" },
  "id"      : 1,
  "jsonrpc" : "2.0" }

And the corresponding JSON-RPC 2.0 response:

{ "result"  : true,
  "id"      : 1,
  "jsonrpc" : "2.0" }

Search filters

At present there is only one utility function related to search filter. I plan to add another one in the next Json2Ldap version, to validate search filters.

  • ldap.util.encodeFilterValue Encodes a search filter assertion value. Use it to escape special characters when you process user input into search templates like (!(uid=%u)(mail=%u)).

Example JSON-RPC 2.0 request:

{ "method"  : "ldap.util.encodeFilterValue",
  "params"  : { "value" : "a*b*c" },
  "id"      : 1,
  "jsonrpc" : "2.0" }

The corresponding JSON-RPC 2.0 response. Note how the asterisk chars (which normally constitute a wild-card) were escaped.

{ "result"  : "a\2ab\2ac",
  "id"      : 1,
  "jsonrpc" : "2.0" }

The complete web API documentation of Json2Ldap is available here.