Here is a simple LDAP schema for storing Secure Remote Password (SRP-6a) authentication credentials. It defines an object class srp6Account which can be attached to any directory entry to enable SRP-6a authentication for it. The SRP salt and verifier are stored in a text attribute called srp6Verifier.
attributeTypes: ( 18.104.22.168.4.1.31487.3.1
DESC 'Stores SRP6 salt and verifier, in hex and delimited by semicolon'
USAGE userApplications )
objectClasses: ( 22.214.171.124.4.1.31487.3.2
DESC 'Account with SRP-6a authentication support'
MAY srp6Verifier )
The following format is suitable for storing the Secure Remote Password credentials:
An LDAP directory is a type of hierarchical NoSQL storage. A quick way to explain the essence of LDAP is by drawing a comparison to a computer file system which people are familiar with.
A file system consists of files in a tree-like structure.
An LDAP directory consists of entries in a tree-like structure.
A file in a file system is an arbitrary blob of text or binary data.
A directory entry is a collection of attributes, or name / value pairs. Attributes may be text or binary. They may be mandatory or optional, single or multi-valued.
A file in a file system has a name, e.g. “tax-report-2010.xml”. The file name must be unique within the containing folder.
An entry in a directory branch has a relative distinguished name (RDN), e.g. “cn=Alice Wonderland”. The RDN comes from an existing name/value pair in the entry that was chosen to become the entry’s name (or title). RDNs must also be unique within the containing directory branch.
A file in a file system is uniquely identified by its path, e.g. “/home/vladimir/taxes/tax-report-2010.xml”.
An entry in a directory is identified by its distinguished name (DN), which is formed by the chain of RDNs leading all the way to the directory root, e.g. “cn=Alice Wonderland, ou=people, dc=wonderland, dc=net”.
Here is a truncated example directory entry of a user, in LDIF (LDIF stands for LDAP data interchange format).
The distinguished name (DN) is in bold, the name/value pair serving as RDN is slanted.
dn: uid=alice,ou=people,dc=wonderland,dc=netuid: alice
cn: Alice Wonderland
mobile: +1 010 154 3228
If you like this analogy explanation of LDAP you’re welcome to use it in your own presentations 🙂
Yesterday’s 2.0 release of Json2Ldap brings a lot of new good things. Some of them are hidden, representing various little stubs under the hood that will enable cool new features to be added in future (patience, you’ll find out in due time!). On the outside, the most noticeable addition is the arrival of plain SASL authentication support. This LDAP authentication method offers two key advantages over the traditional simple bind. Here I’ll explain what these are and how you could apply them.
Simpler authentication with username instead of DN
The traditional ldap.simpleBind method authenticates users with their distinguished name (DN) and password. Using DNs for web app login, however, is a bit cumbersome. Why? Because you first have to establish a search connection (bound as some service user) in order to resolve the user’s DN from the entered username or email address, typically with a filter like "|(uid=%u)(mail=%u)", and only then you can make the actual ldap.simpleBind request.
ldap.plainBind spares us these preliminary steps by taking care of the underlying user DN resolution. With it you can just pass the user’s name / email + password and be authenticated. The only snag is that the LDAP directory may require some configuration before that, to allow plain SASL binds and to know which user record attributes will serve as “username”.
Here is an example plain SASL auth included in the ldap.connect request:
Proxied authorisation / switching the current user
Proxied authorisation is similar to the sudo command on Unix systems. It allows you to authenticate to the directory with the credentials of one user and then perform all subsequent operations as another user. This is the other significant feature of plain SASL bind.
In situations when a web app has to modify user data on behalf of another user. In the above example the JSON call authenticates as “myWebApp” but then requests the resulting connection to receive the identity (and privileges) of user “alice”.
Proxied authorisation can also be used to create custom external login procedures, for example based on OAuth 2.0 tokens. Here a helper app upon establishing the identity of the user through some other external mean authenticates to the directory as itself but then through the targetDN / targetUsername parameter requests the connection to take on the identity of the target user.
Note that enabling proxied authorisation for a particular service account requires the underlying LDAP directory to be explicitly configured for that. Check out the docs of your particular directory server for detailed instructions.
Which directory servers support PLAIN SASL bind (RFC 4616)?
OpenDJ / OpenDS
389 Directory Server
UnboundID in-memory DS
IBM Tivoli Directory Server
Directory servers without PLAIN SASL bind support:
Person entries in a LDAP directory may contain photos. These are typically stored in a jpegPhoto attribute, defined in the standard inetOrgPerson schema. In this article I’ll show you how to display such JPEG images in the browser using Json2Ldap and a cool new HTML feature called data URIs.
When Json2Ldap returns a directory entry it inspects the value of each attribute. If it is text, it passes it unmodified (save for escaping the special JSON chars). If the content is binary data, it encodes it into a Base64 string.
In the pre HTML 5 days you would have had to produce a physical JPEG URL from the received Base64 string, for example as by uploading it to a web server and then linking to it.
Fortunately, work-arounds such as this are no longer necessary. The solution is called Data URIs, a feature which was originally specified in 1998 and is now finally implemented by the latest crop of HTML 5 browsers.
How do data URIs work?
They provide an option for image data to be “in-lined” within the HTML page, instead only being able to link to it.
Here is a standard img element where the src attribute is a typical URL pointing to a file on the web server:
And here is an img with a data URI, where the image content is pasted directly into the src attribute. So when a data URI aware browser reads it, it will fetch the JPEG data from the in-lined Base64 string:
I don’t know why it took over 10 years to implement support for data URIs in browsers, but this is now a powerful technique for Ajax apps to render images on the web page which content was received through a XHR call.
Data URIs can naturally be applied to Ajax apps that interface to an LDAP directory through Json2Ldap. Rendering jpegPhoto attributes is then as simple as setting the src attribute of the desired image element to a data URI and then appending the Base64 content to it:
// We're using jQuery and the user directory entry
// resides in the 'user' variable
$("#user-photo").attr("src", "data:image/jpeg;base64," + user.jpegPhoto);
While data URIs are supported by all major browsers today, some may impose a limit on the content size. IE 8 for example has a limit of 32 KB. So this technique may not work well for large images. For avatars and photos in user profiles, where 10 to 20KB are sufficient, it is going to be just fine.
If you’re making an LDAP search against a large directory you may potentially get a huge result set that you may rather wish to consume in chunks or “pages”. You may need this if you have a UI where results should be displayed, say, in portions of 10 or 20 at a time; also, if the LDAP server is configured with a max limit (typically in the order of 1000) on the number of entries a client may receive in a single search response.
To handle search results paging two LDAP extensions come to the rescue:
The Virtual List View control. It is the more featureful of the two as it allows clients to request an arbitrary “view” into the result set, by specifying a target offset, entry count, and even a “before” and “after” entry count. It is defined in an IETF Internet Draft, which for some reason still unknown to me hasn’t made it to standard status yet (as opposed to the Simple Paged Results control).
Note that the Virtual List View requires the results of the request to be sorted by a specified key on the server side using the Server Side Sort control (defined in RFC 2891). With the Simple Paged Results control sorting is optional.
The following screenshot, from the Json2Ldap online demo, shows an web app widget that uses the Simple Paged Result control.
Here is a list of the directory servers that support the Virtual List View (VLV) control, in alphabetical order:
389 Directory Server
IBM Tivoli Directory Server (since version 6.2)
Microsoft Active Directory (since Windows Server 2003)
Directory servers that don’t support the VLV control:
Oracle Internet Directory
The VLV control is perhaps not as widely supported by the various directory server vendors as the Simple Paged Results, but if you have an application that has to be able page up and down through the search results, it is indispensable.
Support for VLV in Json2Ldap from NimbusDS is planned for the next 1.10 release.
AuthService can be used in any situation where you have to authenticate user credentials (login) over the web against an LDAP-compatible directory such as Microsoft Active Directory, Novell eDirectory or OpenLDAP.
You’re a SaaS provider and want to provide your corporate customers with a method for authenticating users against their internal directory.
Your company has applications in the cloud and wish them to use the corporate directory for user login.
You’re designing an Ajax app and want to authenticate users with a single JSON XHR. No redirection and page reloading, please!
How does it work?
AuthService is a nimble web service that sits in front of an LDAP directory and receives JSON-RPC request from web clients. It resolves the supplied usernames to valid directory entry entries (DNs) and translates between the binary LDAP protocol and HTTP/JSON.
The JSON request and response messages, what do they look like?
AuthService communicates with simple JSON messages. These follow the standard JSON-RPC 2.0 protocol.
Can you retrieve a user’s details from the directory?
Yes! In addition to checking the user’s credentials you can also configure AuthService to return a selected set of user’s directory entry attributes on auth success. This is done via the authService.userAttributes configuration setting.
Here is a sample list of attributes that can typically be retrieved:
Given name, surname, full name.
Office, home and mobile phone numbers.
Organisational details such as manager, department and authorisations / permissions.
Here is an example of such a JSON user auth response that returns selected user details:
Which directory servers is AuthService compatible with?
AuthService works with any LDAP v3 compatible directory. This includes Microsoft Active Directory, Novell eDirectory, IBM’s and Oracle’s directory services, the open source OpenLDAP, OpenDJ and ApacheDS servers.
What about installation?
AuthService is delivered as a standard Java servlet application, packaged as a WAR file and ready for immediate installation into any Java web server, such as the popular free Apache Tomcat or Jetty servers. The WAR file weighs a nimble 2.5 megabytes.
Whether the subject of the presented X.509 client certificate must match an authorised distinct name (DN).
What about price and support?
AuthService licenses come at a super affordable price. For immediate purchase and download check out the NimbusDS online shop. Attractive discounts are available if you with to distribute the software as part of your own product or SaaS offerings, for 100, thousand or even more copies.
NimbusDS, which operates out of London, UK and Bulgaria, also offers excellent integration and consulting services, with emphasis on LDAP directory design, meeting organisational objectives, web and cloud directory applications.
The complete Nimbus Directory Services product line received a speed boost in June. The latest versions of Json2Ldap, JsonSSO and AuthService now feature a greatly improved JSON parser which speeds up decoding of incoming requests by impressive 380 per cent!
LDAP – compatible directories such as MS AD and OpenDJ are an excellent tool for bringing order and organising things. Businesses that make extensive use of web services may benefit from having all of them nicely listed and configured in a central location. A directory server can serve this purpose well, and with a gateway such as Json2Ldap, this can be done over the web too.
Basic web service listing
At a basic level, the directory may just list the available web services with their key usage details, such as their name, protocol and the URLs where web clients can access them.
The example below shows one such case where the services are listed under a directory branch named ou=Services,dc=NimbusDS,dc=com. Each entry is a webService class which supports attributes for storing a service’s name, URL, protocol and other detail. Directories allow their schema to be freely extended, so you can define your own class for your web services and the properties you wish to store.
The web services entries can be administered from the console or with LDAP GUI tools such as the excellent Apache Directory Studio.
Web service lookup
If you have a Json2Ldap instance installed the service listings may be queried by web clients, for example to dynamically look up the URL for a particular web service.
Here is a Json2Ldap ldap.getEntry request to obtain the URL of a TransactionCenter service:
The administration of web services can be further centralised by storing their configuration variables in their own directory entries instead. In effect, this means projecting all configurations from your directory server. The web services would then only need to know the LDAP URL of the directory server and be provided with the appropriate credentials (username/password pair or X.509 certificate) to connect and authenticate to it.
If done on a consistent basis, having all configurations in a single place may greatly improve the manageability of your services and simplify the work of your IT administrators.
To accomplish this each web service must be provided with a set of credentials for accessing its configuration variables. ACLs may be judiciously used to limit read access to these attributes to the web service only and allow only the authorised administrator to edit them.
For the actual configuration variables, the LDAP protocol provides fair flexibility and allows storage of virtually arbitrary key/value pairs. As with the basic details example above, you can create your own schema for storing the configuration parameters of your particular web services.
Below is one such example for the TransactionCenter payment web service configuration. The directory entry contains attributes for configuring the back-end database connection as well as various variables pertaining to the web service itself.
In a future article I’ll share a few useful ideas how SaaS providers can utilise a central LDAP directory for managing subscriber accounts and multi-tenant app configurations.
Online employee directory: Presents a list of company employees where by clicking on a person’s name additional details are displayed.
Resolving group membership: An important organisational feature of directories is the ability to specify groups for things like departments, permissions and mailing lists. This app lists the available groups and resolves the associated members.
User authentication: Ajax form to authenticate a user’s UID and password against their LDAP directory account.
As for the directory web service, I set up a Json2Ldap instance at CloudBees, together with an embedded in-memory LDAP directory that represents a typical corporate DIT consisting of a user base and several groups. You can view a screenshot of the directory tree to get an idea of its user and group structure. In a deployed state Json2Ldap with the in-memory directory take up 40 MB of memory which fit nicely into the free PaaS plan of CloudBees (256 MB).
The directory behind Json2Ldap can of course be any other LDAP v3 compatible server, such as Microsoft Active Directory, Novell eDirectory, OpenLDAP, OpenDJ, etc. So there’s complete flexibility here, also in terms of schema, as Json2Ldap is schema-agnostic.
How about Ajax responsiveness?
Measurements with the JSON-RPC Shell show that JSON calls to the Json2Ldap service at CloudBees are typically completed in about 150 ms. I don’t have a basis for comparison with other cloud vendors here, but I suppose responsiveness impacted by the relative datacentre location (e.g. EU vs USA) and the efficiency of the PaaS abstraction layers of CloudBees. Their PaaS is actually running on top of Amazon’s cloud infrastructure, so there may be quite many layers involved. When I compare the response time to a Json2Ldap service on the local intranet, the JSON calls here take about 15 ms to complete, which is an order of magnitude quicker. For the actual demo apps the 150 ms response time however is okay and doesn’t affect responsiveness in a noticeable way. You can of course try it out for yourself.
The next planned cloud demos will cover the other NimbusDS software products – JsonSSO and AuthService.
This is a simple utility method that takes just one parameter – the filter string. Note that an LDAP connection is not required for this operation, so no CID (connection identifier) needs to be passed.