Configuring LDAP with AEM 6

LDAP (the Lightweight Directory Access Protocol) is used for accessing centralized directory services. This helps reduce the effort required to manage user accounts as they can be accessed by multiple applications. One such LDAP server is Active Directory. LDAP is often used to achieve Single Sign On which allows a user to access multiple applications after logging in once.

User accounts can be synchronized between the LDAP server and CRX, with LDAP account details being saved in the CRX repository. This allows the accounts to be assigned to CRX groups for allocating the required permissions and privileges.

CRX uses LDAP authentication to authenticate such users, with credentials being passed to the LDAP server for validation, which is required before allowing access to CRX. To improve performance, successfully validated credentials can be cached by CRX; with an expiry timeout to ensure that revalidation does occur after an appropriate period.

When an account is removed from the LDAP server validation is no longer granted and so access to CRX is denied. Details of LDAP accounts that are saved in CRX can also be purged from CRX.

Use of such accounts is transparent to your users, they see no difference between user and group accounts created from LDAP and those created solely in CRX.

 

In AEM 6, LDAP support comes with a new implementation that requires a different type of configuration than with previous versions.

All LDAP configurations are now available as OSGi configurations. They can be configured via the Web Management console at:
http://serveraddress:4502/system/console/configMgr

In order to have LDAP working with AEM, you need to create three OSGi configurations:

  1. An LDAP Identity Provider (IDP).
  2. A Sync Handler.
  3. An External Login Module.

Configuring The LDAP Identity Provider

The LDAP Identity Provider is used to define how users are retrieved from the LDAP server.  

It can be found in the management console under the Apache Jackrabbit Oak LDAP Identity Provider name.

The following configuration options are available for the LDAP Identity Provider:

LDAP Provider Name Name of this LDAP provider configuration.
LDAP Server Hostname
Hostname of the LDAP server
LDAP Server Port Port of the LDAP server
Use SSL Indicates if an SSL (LDAPs) connection should be used.
Use TLS Indicates if TLS should be started on connections.
Disable certificate checking Indicates if server certificate validation should be disabled.
Bind DN DN of the user for authentication. If this is left empty, an anonymous bind will be performed.
Bind Password Password of the user for authentication
Search timeout Time until a search times out
User base DN The DN for user searches
User object classes The list of object classes an user entry must contain.
User id attribute Name of the attribute that contains the user id.
User extra filter Extra LDAP filter to use when searching for users. The final filter is formatted like: '(&(<idAttr>=<userId>)(objectclass=<objectclass>)<extraFilter>)' (user.extraFilter)
User DN paths Controls if the DN should be used for calculating a portion of the intermediate path.
Group base DN The base DN for group searches.
Group object classes The list of object classes a group entry must contain.
Group name attribute Name of the attribute that contains the group name.
Group extra filter Extra LDAP filter to use when searching for groups. The final filter isformatted like: '(&(<nameAttr>=<groupName>)(objectclass=<objectclass>)<extraFilter>)'
Group DN paths Controls if the DN should be used for calculating a portion of the intermediate path.
Group member attribute Group attribute that contains the member(s) of a group.

Configuring The Synchronization Handler

The synchronization handler will define how the Indetity Provider users and groups will be synchronized with the repository.

It is located under the Apache Jackrabbit Oak Default Sync Handler name in the management console.

The following configurations options are available for the Synchronization Handler:

Sync Handler Name Name of the sync configuration.
User Expiration Time Duration until a synced user gets expired.
User auto membership List of groups that a synced user is added to automatically.
User property mapping List mapping definition of local properties from external ones.
User Path Prefix The path prefix used when creating new users.
User Membership Expiration Time after which membership expires.
User membership nesting depth Returns the maximum depth of group nesting when membership relations are synced. A value of 0 effectively disables group membership lookup. A value of 1 only adds the direct groups of a user. This value has no effect when syncing individual groups only when syncing a users membership ancestry.
Group Expiration Time Duration until a synced group expires.
Group auto membership List of groups that a synced group is added to automatically.
Group property mapping List mapping definition of local properties from external ones.
Group path prefix The path prefix used when creating new groups.

The external login module

The external login module is located under the Apache Jackrabbit Oak External Login Module under the management console.

Its job is to define which Identity Provider and Sync Handler to use, effectively binding the two modules.

The following configuration options are available:

JAAS Ranking Specifying the ranking (i.e. sort order) of this login module entry. The entries are sorted in a descending order (i.e. higher value ranked configurations come first).
JAAS Control Flag Property specifying whether or not a LoginModule is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL.Refer to the JAAS configuration documentation for more details around the meaning of these flags.
JAAS Realm The realm name (or application name) against which the LoginModule is be registered. If no realm name is provided then LoginModule is registered with a default realm as configured in the Felix JAAS configuration.
Identity Provider Name Name of the identity provider.
Sync Handler Name Name of the sync handler.

注意

If you plan on having more than one LDAP configuration with your AEM instance, separate Identity Providers and Synchronization Handlers need to be created for each configuration.

Configure LDAP over SSL

AEM 6 can be configured to authenticate with LDAP over SSL by following the below procedure:

  1. Check the Use SSL or Use TLS checkboxes when configuring the LDAP Identity Provider.

  2. Configure the Sync Handler and the External Login module according to your setup.

  3. Install the SSL certificates in your Java VM if needed. This can be done by using keytool:

    keytool -import -alias localCA -file <certificate location> -keystore <keystore location>

  4. Test the connection to the LDAP server.

Creating SSL certificates

Self signed certificates can be used when configuring AEM to authenticate with LDAP via SSL. Below is an example of a working procedure for generating certificates for use with AEM.

  1. Make sure you have a SSL library installed and working. This procedure will use OpenSSL as an example.

  2. Create a customized OpenSSL configuration (cnf) file. This can be done by copying the default openssl.cnf configuration file and customizing it. On UNIX systems, it is usually located at /usr/lib/ssl/openssl.cnf

  3. Proceed to creating the CA root key by running the below command in a terminal:

    openssl genpkey -algorithm [public key algorithm] -out certificatefile.key -pkeyopt [public key algorithm option]

     

  4. Next, create a new self signed certificate:

    openssl req -new -x509 -days [number of days for certification] -key certificatefile.key -out root-ca.crt -config CA/openssl.cnf

  5. Inspect the newly generated certificate to make sure everything is in order:

    openssl x509 -noout -text -in root-ca.crt

  6. Make sure that all folders specified in the certificate configuration (.cnf) file exist. If not, create them.

  7. Create a random seed, by running, for example:

    openssl rand -out private/.rand 8192

  8. Move the created .pem files to the locations configured in the .cnf file.

  9. Finally, add the certificate to the Java keystore.

Enabling debug logging

Debug logging can be enabled for both the LDAP Identity Provider and the External Login Module in order to troubleshoot connection issues.

In order to enable debug logging, you need to:

  1. Go to the Web Management Console.
  2. Find "Apache Sling Logging Logger Configuration" and create two loggers with the follwoing options:
  • Log level: Debug
  • Log File logs/ldap.log
  • Message Pattern: {0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}
  • Logger: org.apache.jackrabbit.oak.security.authentication.ldap
  • Log level: Debug
  • Log File: logs/external.log
  • Message Pattern: {0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}
  • Logger: org.apache.jackrabbit.oak.security.authentication.external

Known issues

If you plan on using LDAP over SSL, make sure the certificates you are using are created without the Netscape comment option. If this option is enabled, authentication will fail with a SSL Handshake error.

​