Set up LDAP login
LDAP (Lightweight Directory Access Protocol) is a central directory of users, such as Microsoft Active Directory or OpenLDAP. When you connect ERPNext to LDAP, users sign in with their directory user name and password. ERPNext creates the user on the first login.
INFO
LDAP Settings is part of the Frappe Framework, so it is available on every ERPNext site. The ldap3 Python package that it needs is installed with the framework.
Prerequisites
- The System Manager role.
- A read-only LDAP user that can look up other users, and its password.
- The search paths for users and groups in your directory, for example
ou=users,dc=example,dc=com.
Connect ERPNext to the LDAP server
Open LDAP Settings.
In Directory Server, select Active Directory, OpenLDAP, or Custom.
Enter the server details:
- LDAP Server Url:
ldap://yourserver:portorldaps://yourserver:port. - Base Distinguished Name (DN): the distinguished name of the read-only lookup user.
- Password for Base DN: the password of that user.
- LDAP Server Url:
Enter the search paths:
- LDAP search path for Users, for example
ou=users,dc=example,dc=com. - LDAP search path for Groups, for example
ou=groups,dc=example,dc=com.
- LDAP search path for Users, for example
In LDAP Search String, enter the filter that matches the login name. Enclose it in parentheses and use
{0}for the name that the user types:- Active Directory:
(sAMAccountName={0}) - OpenLDAP:
(uid={0})
- Active Directory:
Map the LDAP attributes to the user fields:
Field Active Directory OpenLDAP LDAP Email Field mailmailLDAP Username Field sAMAccountNameuidLDAP First Name Field givenNamegivenNameYou can also map LDAP Middle Name Field, LDAP Last Name Field, LDAP Phone Field, and LDAP Mobile Field.
In Default User Type, select the user type for new users. For a System User, also select the Default User Role.
Optional: select Do Not Create New User to let only existing ERPNext users sign in through LDAP.
Select Enabled, and save. ERPNext connects to the server to test the settings. If the test fails, ERPNext does not enable LDAP and shows the error.
The login page now shows a Login Via LDAP option.
Connect securely
In the LDAP Security section:
- SSL/TLS Mode: select StartTLS to encrypt the connection with StartTLS.
- Require Trusted Certificate: select Yes if the certificate of the LDAP server must be trusted by the ERPNext server. Select No to use StartTLS with a self-signed certificate. ERPNext ignores this setting when StartTLS is off.
- To use a client certificate, enter the absolute paths on the ERPNext server in Path to private Key File, Path to Server Certificate, and Path to CA Certs File.
Map LDAP groups to roles
You can give roles to users based on their LDAP groups. For example, members of the accounting group get the Accounts User role.
- In the LDAP Group Mappings table, add one row for each group. Enter the LDAP Group and select the User Role.
- For a Custom directory server, also fill in LDAP Group Member attribute (for example
member) and Group Object Class (for examplegroup).
WARNING
ERPNext checks the mapped roles at every login. It adds and removes mapped roles on the user to match the LDAP groups.
Troubleshooting
| Message | Cause | Fix |
|---|---|---|
| LDAP Search String must be enclosed in '()' and needs to contian the user placeholder | The search string has no parentheses or no {0} | Enter the string in the form (uid={0}) |
| Ensure the user and group search paths are correct. | A search path does not exist in the directory | Check LDAP search path for Users and LDAP search path for Groups |
| Custom LDAP Directoy Selected, please ensure 'LDAP Group Member attribute' and 'Group Object Class' are entered | Directory Server is Custom and these fields are empty | Fill in both fields |
| StartTLS is not supported | The LDAP server does not accept StartTLS | Set SSL/TLS Mode to Off, or enable StartTLS on the server |