Integration with LDAP repository
Mercury DB (HgDB) 3.0 authenticates users against an LDAP directory and a local repository of users, and it takes their groups and roles from them. The LDAP connection is defined in two separate places, because the OAuth service is a separate mechanism: it builds its own realm from its own configuration file and does not use the realm from server.xml. A change made in only one of them leaves the system inconsistent. This page describes both places and the role mapping.
Where the LDAP connection is defined
| Place | Used by | Keys |
|---|---|---|
conf/server.xml, the Realm element of the class pro.ibpm.mercury.gui.core.auth.TomcatLdapRealm | Logging in through a form (the web applications of the server) | Attributes of the element (see the table below) |
mercury/classes/mercury-ws-app/mercury-security-OAuth.properties, keys with the prefix tomcat.realm. | Issuing OAuth tokens (/rest/token), so all REST services | dsJndiName, connectionURL, userBase, userSearch, roleBase, roleName, roleSearch |
Change both places when you point the server at another LDAP directory. If only server.xml is changed, logging in through a form works, but requesting a token ends with the error invalid_grant (the log of the server contains Insufficient Access Rights or another error of the old directory). Restart the server after the change.
Example of the Realm element:
<Realm className="pro.ibpm.mercury.gui.core.auth.TomcatLdapRealm"
connectionURL="ldap://localhost:389"
userBase="ou=People,dc=sample,dc=example,dc=com" userSearch="(uid={0})"
userSubtree="true" roleBase="ou=Groups,dc=sample,dc=example,dc=com" roleName="cn"
roleSearch="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))"
roleSubtree="true" dsJndiName="jdbc/MercuryLdapDBPoSql" />
The same connection in the file of the OAuth service:
tomcat.realm.dsJndiName=jdbc/MercuryLdapDBPoSql
tomcat.realm.connectionURL=ldap://localhost:389
tomcat.realm.userBase=ou=People,dc=sample,dc=example,dc=com
tomcat.realm.userSearch=(uid={0})
tomcat.realm.roleBase=ou=Groups,dc=sample,dc=example,dc=com
tomcat.realm.roleName=cn
tomcat.realm.roleSearch=(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))
| Attribute | Description |
|---|---|
connectionURL | Address of the directory, for example ldap://host:389 or ldaps://host:636 |
userBase, userSearch | Where and how the user is searched for. {0} is the user name |
roleBase, roleSearch, roleName | Where and how the groups of the user are searched for. {0} in roleSearch is the DN of the user. roleName is the attribute with the name of the group |
dsJndiName | JNDI name of the data source with the local repository of users and the role mapping (see below) |
connectionName, connectionPassword | (optional) technical user that searches the directory |
The file of the OAuth service has no keys of the technical user, so the search in this realm is anonymous. The directory must allow the anonymous user to search the userBase and the roleBase (to read the attributes used in the search filters). The password of the technical user in the Realm element is stored encoded.
Groups and roles
A user has two separate lists:
- groups come from the directory: the groups found by
roleSearch(for users of the local repository the only group ismrc-user), - roles (for example
mrc-user,mrc-sysadmin,mrc-useradmin) come from the role mapping table of the local repository.
The role mapping table MRC_LDAP_INT_ROLES_MAP (in the database of the data source dsJndiName) has three columns: the name of the participant, its type and the role.
| Type | Meaning of the participant name |
|---|---|
U | User name. The role is assigned to the user directly. This works for users of the local repository and for users of the directory |
G | Name of a group of the directory. The role is assigned to every user who belongs to the group |
A user of the local repository (the table MRC_LDAP_INT_USERS) always gets the basic role mrc-user. A user of the directory gets the roles from the rows G for each of his groups and from the rows U for his name. A group of the directory has no effect until it has a row in the mapping table.
The roles and groups of the user are used when the context of a REST request is verified (see Permissions mechanism).
Access rights in the sample directory
The OpenLDAP image (scisoftware/openldap, the repository docker-openldap) sets the access rights by the branch of the directory:
| Accounts | Access |
|---|---|
ou=Technical (for example FrontendAccount, the technical user of the realm) | read of the whole tree, but not of the passwords: the attributes userPassword and sambaNTPassword are hidden from them. A technical account does not need them: the realm checks a password by a bind with the credentials of the user |
ou=Admins | write: these accounts manage the directory (instead of the root account cn=Manager) |
| the user himself | changes his own password and the attributes of his entry |
| anonymous | only the bind (authentication), no reading |
The rules are applied when the database of the directory is initialized. In an already running installation change the rule of the attributes userPassword and sambaNTPassword in the configuration of the directory (olcAccess of the database): replace by dn.children="ou=Technical,<suffix>" read with ... none. Some images keep the configuration database closed for online changes; then change it with slapmodify when slapd is stopped, after making a copy of slapd.d. The panel of authentication administration does not need the passwords either (it never reads userPassword).
Sample directory for tests
The mercury-docker repository contains the definition of a sample OpenLDAP server with the schemas used by the system (openldap directory). The script bin/openldap-dev-start.sh builds the image and starts the container. The sample entries are the groups mrc-admin and mrc-user and the users mrcmanager and mrcuser.
The entries of the groups in the sample directory (uniqueMember) point to the suffix dc=scisoftware,dc=pl. If the container uses another suffix (the default is dc=sample,dc=example,dc=com), correct the attribute uniqueMember of the groups. Otherwise the filter roleSearch does not find the groups of the user. Add the rows of the groups mrc-user and mrc-admin to the role mapping table too.