Configuring a Read-Only LDAP User Store¶
User management functionality is provided by default in WSO2 API Manager and it can be configured in the
<API-M_HOME>/repository/conf/deployment.toml
file. The instructions given below explains how to configure a read only LDAP
as the primary user store for WSO2 API Manager.
Tip
To get a high-level understanding of the primary user stores available in WSO2 API Manager, see Configuring primary User Stores.
Info
Default User Store: The primary user store that is configured by default in the deployment.toml
file of API Manager is a JDBC user store, which reads/writes into the internal database of the product server. By default, the internal database is H2. This database is used by the Authorization Manager (for user authentication information) as well as the User Store Manager (for defining users and roles).
Note that the RDBMS used in the default configuration can remain as the database used for storing Authorization information.
Follow the given steps to configure a read-only LDAP/AD as the primary user store:
- Step 1 - Set up the read-only LDAP/AD user store manager
- Step 2 - Update the system administrator
- Step 3 - Start the IS server
- Step 4 - Start the APIM server
Step 1 - Set up the read-only LDAP/AD user store manager¶
-
Add the configurations below in to the
<API-M_HOME>/repository/conf/deployment.toml
file.
Descriptions on connection properties of[user_store] class= "org.wso2.carbon.user.core.ldap.UniqueIDReadOnlyLDAPUserStoreManager" type = "read_only_ldap_unique_id" connection_url = "ldap://localhost:10389" connection_name = "uid=admin,ou=system" connection_password = "admin"
[user_store]
is given below:Property Id Primary User Store Property Secondary User Store Property Description ConnectionURL connection_url Connection URL Connection URL to the user store server. In the case of default LDAP in Carbon, the port is specified in the carbon.xml file, and a reference to that port is included in this configuration.
Sample values:
ldap://10.100.1.100:389
ldaps://10.100.1.102:639
For Active Directory, the connection URL should have the following format:ConnectionURL="ldap://<AD host-ip>:<AD_listen_port>"
If you are connecting over LDAPs (secured LDAP)
you need to import the certificate of user store to theclient-truststore.jks
of the WSO2 product. For information on how to add certificates to the truststore and how keystores are configured and used in a system, see Using Asymmetric Encryption.
If LDAP connection pooling is used, see enable connection pooling for LDAPS connections.
performance tuning LDAPs pooling.ConnectionName connection_name Connection Name The username used to connect to the user store and perform various operations. This user does not need to be an administrator in the user store or have an administrator role in the WSO2 product that you are using, but this user MUST have permissions to read the user list and users' attributes and to perform search operations on the user store. The value you specify is used as the DN (Distinguish Name) attribute of the user who has sufficient permissions to perform operations on users and roles in LDAP
This property is mandatory.
Sample values: uid=admin,ou=systemConnectionPassword connection_password Connection Password Password for the ConnectionName user. -
Add the
[user_store.properties]
configuration element in thedeployment.toml
file as follows:[user_store.properties] TenantManager="org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager" ConnectionURL="ldap://localhost:10390" ConnectionName="uid=admin,ou=system" ConnectionPassword="admin" AnonymousBind="false" UserNameAttribute="uid" UserNameSearchFilter="(&(objectClass=person)(uid=?))" ReadGroups="true" GroupSearchBase="ou=system,CN=Users,DC=wso2,DC=test" GroupNameAttribute="cn" GroupNameSearchFilter="(&(objectClass=groupOfNames)(cn=?))" GroupNameListFilter="(objectClass=groupOfNames)" MembershipAttribute="member" BackLinksEnabled="false" UsernameJavaRegEx="[a-zA-Z0-9._\\-|//]{3,30}$" PasswordJavaRegEx="^[\\S]{5,30}$" SCIMEnabled="true" PasswordHashMethod="PLAIN_TEXT" MultiAttributeSeparator="," MaxUserNameListLength="100" MaxRoleNameListLength="100" UserRolesCacheEnabled="true" LDAPConnectionTimeout=5000 ReplaceEscapeCharactersAtUserLogin="true" ConnectionRetryDelay="120000" GroupSearchFilter="(objectClass=groupOfNames)" UserEntryObjectClass="identityPerson" IsBulkImportSupported="true" defaultRealmName="WSO2.ORG" EmptyRolesAllowed="true" UserSearchBase="ou=Users,dc=wso2,dc=org" ConnectionPoolingEnabled="false" StartTLSEnabled="false" WriteGroups="true" RolenameJavaRegEx="[a-zA-Z0-9._\\-|//]{3,30}$" GroupEntryObjectClass="groupOfNames" EnableMaxUserLimitForSCIM="false" PasswordJavaRegExViolationErrorMsg="Password length should be within 5 to 30 characters" PasswordJavaScriptRegEx="^[\\S]{5,30}$" UsernameJavaRegExViolationErrorMsg="Username pattern policy violated" UserNameListFilter="(objectClass=person)" UsernameJavaScriptRegEx="^[\\S]{3,30}$" kdcEnabled="false"
-
Set the
ReadGroups
property totrue
, if it should be allowed to read roles from this user store.- When this property is
true
, you must also specify values for theGroupSearchBase
,GroupSearchFilter
andGroupNameAttribute
properties. - If the
ReadGroups
property is set tofalse
, only users can be read from the user store. You can set the configuration to read roles from the user store by reading the user/role mapping based on a membership (user list) or backlink attribute as shown below.
- When this property is
-
To read the user/role mapping based on a membership (This is used by the
ApacheDirectory
server andOpenLDAP)
:-
Enable the
ReadGroups
property.ReadGroups = "true"
-
Set the
GroupSearchBase
property to the directory name where the Roles are stored. That is, the roles you create using the management console of your product will be stored in this directory location. Also, when LDAP searches for groups, it will start from this location of the directory. For example:GroupSearchBase = "ou=system,CN=Users,DC=wso2,DC=test"
-
Set the
GroupSearchFilter
andGroupNameAttributes
. For example:GroupSearchFilter = "(objectClass=groupOfNames)" GroupNameAttribute = "cn"
-
Set the
MembershipAttribute
property as shown below:MembershipAttribute = "member"
-
-
To read roles based on a backlink attribute, use the configuration given below:
ReadGroups = "false" GroupSearchBase = "ou=system" GroupSearchFilter = "(objectClass=groupOfNames)" GroupNameAttribute = "cn" MembershipAttribute = "member" BackLinksEnabled = "true" MembershipOfAttribute = "memberOf"
-
-
For Active Directory, you can use
Referral="follow
to enable referrals within the user store.The AD user store may be partitioned into multiple domains. However, according to the use store configurations in the
deployment.toml
file, you are only connecting to one of the domains. Therefore, when a request for an object is received to the user store, theReferral="follow"
property ensures that all the domains in the directory will be searched to locate the requested object.
Note
Note that these configurations will be automatically populated to the user-mgt.xml
file. You can verify whether your configured properties are populated correctly using this file.
The configuration for the LDAP/AD user store configuration in read-only mode in the user-mgt.xml
file looks as follows for the above configurations:
<UserManager>
<Realm>
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager">
<Property name="IsBulkImportSupported">true</Property>
<Property name="MaxUserNameListLength">100</Property>
<Property name="defaultRealmName">WSO2.ORG</Property>
<Property name="MultiAttributeSeparator">,</Property>
<Property name="EmptyRolesAllowed">true</Property>
<Property name="ConnectionPassword">admin</Property>
<Property name="UserNameUniqueAcrossTenants">false</Property>
<Property name="StoreSaltedPassword">true</Property>
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager</Property>
<Property name="UserSearchBase">ou=Users,dc=wso2,dc=org</Property>
<Property name="GroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property>
<Property name="ConnectionPoolingEnabled">false</Property>
<Property name="StartTLSEnabled">false</Property>
<Property name="CaseInsensitiveUsername">true</Property>
<Property name="UserNameSearchFilter">(&(objectClass=person)(uid=?))</Property>
<Property name="LDAPConnectionTimeout">5000</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="UsernameJavaRegEx">[a-zA-Z0-9._\-|//]{3,30}$</Property>
<Property name="WriteGroups">true</Property>
<Property name="AnonymousBind">false</Property>
<Property name="ConnectionName">uid=admin,ou=system</Property>
<Property name="ConnectionURL">ldap://localhost:10390</Property>
<Property name="RolenameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="GroupSearchFilter">(objectClass=groupOfNames)</Property>
<Property name="RolenameJavaRegEx">[a-zA-Z0-9._\-|//]{3,30}$</Property>
<Property name="GroupEntryObjectClass">groupOfNames</Property>
<Property name="PasswordJavaRegEx">^[\S]{5,30}$</Property>
<Property name="EnableMaxUserLimitForSCIM">false</Property>
<Property name="PasswordHashMethod">PLAIN_TEXT</Property>
<Property name="GroupSearchBase">ou=system,CN=Users,DC=wso2,DC=test</Property>
<Property name="ReadGroups">true</Property>
<Property name="ReplaceEscapeCharactersAtUserLogin">true</Property>
<Property name="ConnectionRetryDelay">120000</Property>
<Property name="MembershipAttribute">member</Property>
<Property name="UserEntryObjectClass">identityPerson</Property>
<Property name="PasswordJavaRegExViolationErrorMsg">Password length should be within 5 to 30 characters</Property>
<Property name="MaxRoleNameListLength">100</Property>
<Property name="PasswordJavaScriptRegEx">^[\S]{5,30}$</Property>
<Property name="BackLinksEnabled">false</Property>
<Property name="UsernameJavaRegExViolationErrorMsg">Username pattern policy violated</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="SCIMEnabled">true</Property>
<Property name="PasswordDigest">SHA-256</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="UsernameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="ReadOnly">false</Property>
<Property name="kdcEnabled">false</Property>
</UserStoreManager>
</Realm>
</UserManager>
Apart from above properties WSO2 API Manager also supports advanced LDAP configurations. For descriptions on each of the advanced properties used in the <API-M_HOME>/repository/conf/deployment.toml
file , see Properties used in Read-only LDAP user store managers.
Step 2 - Update the system administrator¶
The admin user is the super tenant that will be able to manage all other users, roles, and permissions in the system by using the management console of the product. Therefore, the user that should have admin permissions is required to be stored in the user store when you start the system for the first time. Since the LDAP user store can be written to, you have the option of creating a new admin user in the user store when you start the system for the first time. Alternatively, you can also use a user ID that already exists in the LDAP. For information about the system administrator user, see Configuring the System Administrator.
These two alternative configurations can be done as explained below.
-
If the user store is read-only, find a valid user that already resides in the user store. For example, if the username of
admin
is in the user store with admin permissions, update the[super_admin]
section of your configuration as shown below. You do not need to update the password element as it is already set in the user store.[super_admin] username = "admin" password = "admin" create_admin_account = false
-
If you are creating a new admin user in the user store when you start the system, you can add the super tenant user to the user store. Add the following configuration to the
deployment.toml
as shown below.[super_admin] username = "admin" password = "admin" create_admin_account = true
Step 3 - Start the IS server¶
-
Navigate to
<IS_HOME>/repository/conf/deployment.toml
and change the port offset to 1. This is to prevent any port conflicts with API Manager because the default port of the product is 0.offset=1
-
Start your IS server.
sh wso2server.sh
Note
Default LDAP server port of WSO2 IS is 10389. Based on your offset number provide the correct connection URL in <API-M_HOME>/repository/conf/deployment.toml
.
For example if you specify the offset of 1 in WSO2 IS your connection URL should be ldap://{connection_ip}:10390
.
Step 4 - Start the API-M server¶
Start your APIM server and try to log in as the admin user you specified in Step 2 .
sh wso2server.sh
Properties used in a Read-only LDAP user store manager¶
Any of the following properties can be configured for the PRIMARY
user store by adding them as follows to
the <API-M_HOME>/repository/conf/deployment.toml
file.
[user_store]
<Property-Name> = <Property-Value>
Example:
[user_store]
read_groups = true
Note
In the table given below, the Primary User Store Property
column has the PRIMARY
userstore properties that can be configured in the deployment.toml
file. The Secondary User Store Property
column has the properties that can be configured for a secondary user store through the Management Console.
Property Id | Primary User Store Property | Secondary User Store Property | Description |
---|---|---|---|
UserEntryObjectClass | user_entry_object_class | User Entry Object Class | Object class used to construct user entries. Default: identityPerson |
UserNameAttribute | user_name_attribute | Username Attribute | The attribute used for uniquely identifying a user entry. Users can be authenticated using their email address, UID, etc. The name of the attribute is considered as the username.
Default: uid |
UserNameSearchFilter | user_name_search_filter | User Search Filter | Filtering criteria used to search for a particular user entry. Default : (&(objectClass=person)(uid=?)) |
UserNameListFilter | user_name_list_filter | User List Filter | Filtering criteria for searching user entries in the user store. This query or filter is used when doing search operations on users with different search attributes. Default: (objectClass=person) In this case, the search operation only provides the objects created from the person object class. |
UserDNPattern | user_dn_pattern | User DN Pattern | The pattern for the user's DN, which can be defined to improve the search. When there are many user entries in the LDAP user store, defining a UserDNPattern provides more impact on performances as the LDAP does not have to travel through the entire tree to find users.
Sample values: uid={0},ou=Users,dc=wso2,dc=org |
DisplayNameAttribute | display_name_attribute | Display name attribute | This is an optional property. The Display Name Attribute is the name by which users will be listed when you list users in the management console.
Default: blank |
ReadGroups | read_groups | Read Groups | When WriteGroups is set to falses, this Indicates whether groups should be read from the user store. If this is disabled by setting it to false, none of the groups in the user store can be read, and the following group configurations are NOT mandatory: GroupSearchBase, GroupNameListFilter, or GroupNameAttribute. Default: true
|
WriteGroups | write_groups | Write Groups | Indicates whether groups should be written to the user store. Default: true
|
GroupSearchBase | group_search_base | Group Search Base | DN of the context or object under which the group entries are stored in the user store. When the user store searches for groups, it will start from this location of the directory
Default: ou=Groups,dc=wso2,dc=org |
GroupEntryObjectClass | group_entry_object_class | Group Entry Object Class | Object class used to construct group entries. Default: groupOfNames |
GroupNameAttribute | group_name_attribute | Group Name Attribute | Attribute used for uniquely identifying a group entry. This attribute is to be treated as the group name.
Default: cn |
GroupNameSearchFilter | group_name_search_filter | Group Search Filter | Filtering criteria used to search for a particular group entry.
Default: (&(objectClass=groupOfNames)(cn=?)) |
GroupNameListFilter | group_name_list_filter | Group List Filter | Filtering criteria for searching group entries in the user store. This query or filter is used when doing search operations on groups with different search attributes.
Default: ((objectClass=groupOfNames)) In this case, the search operation only provides the objects created from the groupOfName object class. |
RoleDNPattern | role_dn_pattern | Role DN Pattern | The pattern for the group's DN, which can be defined to improve the search. When there are many group entries in the LDAP user store, defining a RoleDNPattern provides more impact on performances as the LDAP does not have to traverse through the entire tree to findgroup.
Sample values: cn={0},ou=Groups,dc=wso2,dc=org |
MembershipAttribute | membership_attribute_range | Membership Attribute | Defines the attribute that contains the distinguished names (DN) of user objects that are in a group.
Default: member |
MemberOfAttribute | member_of_attribute | Member Of Attribute | Define the attribute that contains the distinguished names (DN ) of group objects that user is assigned to. Possible values: memberOf |
BackLinksEnabled | back_links_enabled | Enable Back Links | Defines whether the backlink support is enabled. If you are using MemberOfAttribute attributes this should be set to 'true'.
Default : false |
UsernameJavaRegEx | username_java_regex | Username RegEx (Java) | The regular expression used by the back-end components for username validation. By default, strings with non-empty characters have a length of 3 to 30 allowed. You can provide ranges of alphabets, numbers and also ranges of ASCII values in the RegEx properties. Default: [a-zA-Z0-9.-|//]{3,30}</td> </tr> <tr class="even"> <td>UsernameJava<br>ScriptRegEx</td> <td>username_java<br>_script_regex</td> <td>Username RegEx (Javascript)</td> <td>The regular expression used by the front-end components for username validation.<br /> Default: ^[\S]{3,30} |
UsernameJava ScriptRegEx |
username_java _script_regex |
Username RegEx (Javascript) | The regular expression used by the front-end components for username validation. Default: ^[\S]{3,30} |
UsernameJavaReg ExViolationErrorMsg |
username_java_reg _ex_violation_error_msg |
Username RegEx Violation Error Message | Error message when the Username is not matched with UsernameJavaRegEx Default: Username pattern policy violated |
PasswordJavaRegEx | password_java_regex | Password RegEx (Java) | The regular expression used by the back-end components for password validation. By default, strings with non-empty characters have a length of 5 to 30 allowed. You can provide ranges of alphabets, numbers and also ranges of ASCII values in the RegEx properties. Default: ^[\S]{5,30}</td> </tr> <tr class="odd"> <td>PasswordJava<br>ScriptRegEx</td> <td>password_java<br>_script_regex</td> <td>Password RegEx (Javascript)</td> <td>The regular expression used by the front-end components for password validation.<br /> Default: ^[\S]{5,30} |
PasswordJava ScriptRegEx |
password_java _script_regex |
Password RegEx (Javascript) | The regular expression used by the front-end components for password validation. Default: ^[\S]{5,30} |
PasswordJavaReg ExViolationErrorMsg |
password_java_reg ex_violation_error_msg |
Password RegEx Violation Error Message | The error message that appears when the password does not comply with the passwordJavaRegEx Default: Password length should be within 5 to 30 characters |
RolenameJavaRegEx | rolename_java_regex | Role Name RegEx (Java) | The regular expression used by the back-end components for role name validation. By default, strings with non-empty characters have a length of 3 to 30 allowed. You can provide ranges of alphabets, numbers and also ranges of ASCII values in the RegEx properties. Default: [a-zA-Z0-9.-|//]{3,30}$ |
SCIMEnabled | scim_enabled | Enable SCIM | This is to configure whether user store is supported for SCIM provisioning. Possible values: True : User store support for SCIM provisioning. False: User does not store support for SCIM provisioning. Default: false |
PasswordHashMethod | password_hash_method | Password Hashing Algorithm | Specifies the Password Hashing Algorithm used to hash the password before storing in the user store. Possible values: SHA - Uses SHA digest method. SHA-1, SHA-256 MD5 - Uses MD 5 digest method. PLAIN_TEXT - Plain text passwords.(Default) If you just configure it as SHA, it is considered as SHA-1. It is always better to configure an algorithm with higher bit value as the digest bit size would be increased. |
MultiAttribute Separator |
multi_attribute separator |
Multiple Attribute Separator | This property is used to define a character to separate multiple attributes. This ensures that it will not appear as part of a claim value. Normally “,” is used to separate multiple attributes, but you can define ",,," or "..." or a similar character sequence Default: “,” |
MaxUserName ListLength |
max_user_name _list_length |
Maximum User List Length | Controls the number of users listed in the user store of a WSO2 product. This is useful when you have a large number of users and don't want to list them all. Setting this property to 0 displays all users. Default: 100 In some user stores, there are policies to limit the number of records that can be returned from the query. Setting the value 0 it will list the maximum results returned by the user store. If you need to increase that you need to set it in the user store level. Eg : Active directory has the MaxPageSize property with the default value 1000. |
MaxRoleName ListLength |
max_role_name list_length |
Maximum Role List Length | Controls the number of roles listed in the user store of a WSO2 product. This is useful when you have a large number of roles and don't want to list them all. Setting this property to 0 displays all roles. Default: 100 In some user stores, there are policies to limit the number of records that can be returned from the query. Setting the value 0 it will list the maximum results returned by the user store. If you need to increase that you need to set it in the user store level. Eg: Active directory has the MaxPageSize property with the default value 1000. |
kdcEnabled | kdc_enabled | Enable KDC | If your user store is capable of acting as a Kerberos, Key Distribution Center (KDC) and if you like to enable it, set this property to true. Default: false |
UserRoles CacheEnabled |
user_roles_ cache_enabled |
Enable User Role Cache | This is to indicate whether to cache the role list of a user. Default: true Possible values: false: Set it to false if the user roles are changed by external means and those changes should be instantly reflected in the Carbon instance. Default: true |
Connection PoolingEnabled |
connection_ pooling_enabled |
Enable LDAP Connection Pooling | Define whether LDAP connection pooling is enabled Possible values: True: Enable connection pooling. Enabling it will improve the performance False: Disable connection pooling Default: false |
LDAPConnection Timeout |
ldap_connection timeout |
LDAP Connection Timeout | Timeout in making the initial LDAP connection. This is configured in milliseconds. Default: 5000 |
ReadTimeout | read_timeout | LDAP Read Timeout | The value of this property is the read timeout in milliseconds for LDAP operations. If the LDAP provider cannot get a LDAP response within that period, it aborts the read attempt. The integer should be greater than zero. An integer less than or equal to zero means no read timeout is specified that is equivalent to waiting for the response infinitely until it is received.
Default: not configured |
Membership AttributeRange |
membership attribute_range |
Membership Attribute Range | This is to define the maximum users that correspond to the role that is returned by the LDAP/AD user store. This does not depend on the max page size of the user store.
Default: not configured |
RetryAttempts | retry_attempts | Retry Attempts | Retry the authentication request if a timeout happened
Default: not configured |
LDAPConnection Timeout |
ldap_connection _timeout |
LDAP Connection Timeout | If the connection to the LDAP is inactive for the length of time
(in milliseconds) specified by this property, the connection
will be terminated.
Default: not configured Sample: 20 |