This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Configuring Primary User Stores
Every WSO2 product comes with an embedded, internal user store, which is configured in <PRODUCT_HOME>/repository/conf/user-mgt.xml
. In WSO2 Identity Server, the embedded user store is LDAP, and in other products it is JDBC. Because the domain name (unique identifier) of this default user store is set to PRIMARY
by default, it is called the primary user store.
Instead of using the embedded user store, you can set your own user store as the primary user store. Since the user store you want to connect to might have different schemas from the ones available in the embedded user store, it needs to go through an adaptation process. WSO2 products provide the following adapters to enable you to authenticate users from different types of user stores and plug into LDAP, Active Directory, and JDBC to perform authentication:
User store manager class | Description |
---|---|
org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager | Use |
org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager | Use |
org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager | Use |
org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager | Use |
The user-mgt.xml
file already has sample configurations for all of the above user stores. To enable these configurations, you must uncomment them in the code and comment out the ones that you do not need.
The following topics provide details on the various primary user stores you can configure.
If you are using LDAPS (secure) to connect to the Active Directory, you need to import its public certificate to the client-truststore.jks of the WSO2 product you are configuring.
Configuring an external LDAP or Active Directory user store
All WSO2 products can read and write users and roles from external Active Directory or LDAP user stores. You can configure WSO2 products to access these user stores in one of the following modes:
Read-only mode
Before you begin
- If you create the
user-mgt.xml
file yourself, be sure to save it in the<PRODUCT_HOME>/repository/conf
directory. - The
class
attribute for a read-only LDAP is<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager">
When you configure a product to read users/roles from your company LDAP in read-only mode, it does not write any data into the LDAP.
Comment out the following user store which is enabled by default in the
<PRODUCT_HOME>/repository/conf/user-mgt.xml
file.<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
Given below is a sample for the LDAP user store. This configuration is found in the
<PRODUCT_HOME>
/repository/conf/user-mgt.xml
file, however, you need to uncomment them and make the appropriate adjustments. Also ensure that you comment out the configurations for other user stores which you are not using.<UserManager> <Realm> ... <UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager"> <Property name="TenantManager">org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager</Property> <Property name="ReadOnly">true</Property> <Property name="Disabled">false</Property> <Property name="MaxUserNameListLength">100</Property> <Property name="ConnectionURL">ldap://localhost:10389<</Property> <Property name="ConnectionName">uid=admin,ou=system</Property> <Property name="ConnectionPassword">admin</Property> <Property name="PasswordHashMethod">PLAIN_TEXT</Property> <Property name="UserSearchBase">ou=system</Property> <Property name="UserNameListFilter">(objectClass=person)</Property> <Property name="UserNameSearchFilter">(&(objectClass=person)(uid=?))</Property> <Property name="UserNameAttribute">uid</Property> <Property name="ReadGroups">true</Property> <Property name="GroupSearchBase">ou=system</Property> <Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property> <Property name="GroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property> <Property name="GroupNameAttribute">cn</Property> <Property name="SharedGroupNameAttribute">cn</Property> <Property name="SharedGroupSearchBase">ou=SharedGroups,dc=wso2,dc=org</Property> <Property name="SharedGroupNameListFilter">(objectClass=groupOfNames)</Property> <Property name="SharedTenantNameListFilter">(objectClass=organizationalUnit)</Property> <Property name="SharedTenantNameAttribute">ou</Property> <Property name="SharedTenantObjectClass">organizationalUnit</Property> <Property name="MembershipAttribute">member</Property> <Property name="UserRolesCacheEnabled">true</Property> <Property name="ReplaceEscapeCharactersAtUserLogin">true</Property> <Property name="MaxRoleNameListLength">100</Property> <Property name="MaxUserNameListLength">100</Property> <Property name="SCIMEnabled">false</Property> </UserStoreManager> </Realm> </UserManager>
Update the connection details to match your user store. For example:
<Property name="ConnectionURL">ldap://localhost:10389</Property>
Obtain a user who has permission to read all users/attributes and perform searches on the user store from your LDAP/Active Directory administrator. For example, if the privileged user is "AdminLDAP" and the password is "2010#Avrudu", update the following sections of the realm configuration as follows:
<Property name="ConnectionName">uid=AdminLDAP,ou=system</Property> <Property name="ConnectionPassword">2010#Avrudu</Property>
Update
<Property name="UserSearchBase">
with the directory name where the users are stored. When LDAP searches for users, it will start from this location of the directory.<Property name="UserSearchBase">ou=system</Property>
Set the attribute to use as the username, typically either cn or uid for LDAP. Ideally,
<Property name="UserNameAttribute">
and<Property name="UserNameSearchFilter">
should refer to the same attribute. If you are not sure what attribute is available in your user store, check with your LDAP/Active Directory administrator.For example:
<Property name="UserNameAttribute">uid</Property>
- Optionally, configure the realm to read roles from the user store by reading the user/role mapping based on a membership (user list) or backlink attribute, as follows:
The following code snippet represents reading roles based on a membership attribute. This is used by the
ApacheDirectory
server andOpenLDAP
.<Property name="ReadLDAPGroups">false</Property> <Property name="GroupSearchBase">ou=system</Property> <Property name="GroupSearchFilter">(objectClass=groupOfNames)</Property> <Property name="GroupNameAttribute">cn</Property> <Property name="MembershipAttribute">member</Property>
Start your server and try to log in as the admin user you specified. The password is the admin user's password in the LDAP server.
Read/write mode
Before you begin
- To read and write to an Active Directory user store, set the
WriteGroups
property totrue
instead offalse
. To write user entries to an LDAP user store (roles are not written, just user entries), you follow the steps in the Read-only mode section but specify the following class instead:
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
Use the following class for Active Directory.
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager">
The <PRODUCT_HOME>/repository/conf/user-mgt.xml
file has commented-out configurations for external LDAP/AD user stores.
- Enable the
<ReadWriteLDAPUserStoreManager>
or the<ActiveDirectoryUserStoreManager>
in the<PRODUCT_HOME>/repository/conf/user-mgt.xml
file by uncommenting the code. When it is enabled, the user manager reads/writes into the LDAP/AD user store. Note that these configurations already exist in theuser-mgt.xml
file so you only need to uncomment them and make the appropriate adjustments. Also ensure that you comment out the configurations for other user stores which you are not using. The default configuration for the external read/write user store in the
user-mgt.xml
file is as follows. Change the values according to your requirements.When working with Active Directory it is best to enable the
GetAllRolesOfUserEnabled
property in theAuthorizationManager
as follows.<AuthorizationManager class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager"> <Property name="AdminRoleManagementPermissions">/permission</Property> <Property name="AuthorizationCacheEnabled">true</Property> <Property name="GetAllRolesOfUserEnabled">true</Property> </AuthorizationManager>
While using the user store manager does not depend on this property, you must consider enabling this if there are any performance issues in your production environment. Enabling this property affects the performance when the user logs in. This depends on the users, roles and permissions stats.
If you create the
user-mgt.xml
file yourself, be sure to save it in the<PRODUCT_HOME>/repository/conf
directory.The
class
attribute of theUserStoreManager
element indicates whether it is an Active Directory or LDAP user store:- Active Directory:
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager">
- Read-only LDAP:
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager">
- Active Directory:
Set the attribute to use as the username, typically either cn or uid for LDAP. Ideally,
<Property name="UserNameAttribute">
and<Property name="UserNameSearchFilter">
should refer to the same attribute. If you are not sure what attribute is available in your user store, check with your LDAP/Active Directory administrator.For example:
The following code snippet represents reading roles based on a backlink attribute. This is used by the Active Directory.
<Property name="ReadLDAPGroups">true</Property> <Property name="GroupSearchBase">cn=users,dc=wso2,dc=lk</Property> <Property name="GroupSearchFilter">(objectcategory=group)</Property> <Property name="GroupNameAttribute">cn</Property> <Property name="MemberOfAttribute">memberOf</Property>
Start your server and try to log in as the admin user you specified. The password is the admin user's password in the LDAP server.
When configuring an external LDAP for Governance Registry or API Manager, the user name and password for the default admin will change to the LDAP admin. As a result, the <PRODUCT_HOME>/repository/conf/api-manager.xml file must be updated with the new LDAP admin credentials.
Configuring an internal/external JDBC user store
The default internal JDBC user store reads/writes into the internal database of the Carbon server. JDBC user stores can be configured using the <PRODUCT_HOME>/repository/conf/user-mgt.xml
file's JDBCUserStoreManager
configuration section. Additionally, all Carbon-based products can work with an external RDBMS. You can configure Carbon to read users/roles from your company RDBMS and even write to it. Therefore, in this scenario, the user core connects to two databases:
- The Carbon database where authorization information is stored internally.
- Your company database where users/roles reside.
Therefore, the user-mgt.xml
file must contain details for two database connections. The connection details mentioned earlier are used by the authorization manager. If we specify another set of database connection details inside the UserStoreManager, it reads/writes users to that database. The following are step-by-step guidelines for connecting to an internal and external JDBC user store in read-only mode:
Uncomment the following section in
<PRODUCT_HOME>/repository/conf/user-mgmt.xml
:<UserStoreManager class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager">
The following are samples for the internal and external JDBC user store configuration:
The sample for the external JDBC user store consists of properties pertaining to various SQL statements. This is because the schema may be different for an external user store, and these adjustments need to be made in order to streamline the configurations with WSO2 products.
You can define a data source in
<PRODUCT_HOME>/repository/conf/datasources/master-datasources.xml
and refer to it from theuser-mgt.xml
file. This takes the properties defined in themaster-datasources.xml
file and reuses them in theuser-mgt.xml
file. To do this, you need to define the following property:<
Property
name
=
"dataSource"
>jdbc/WSO2CarbonDB</
Property
>
Find a valid user that resides in the RDBMS. For example, say a valid username is AdminSOA. Update the Admin user section of your configuration as follows. You do not have to update the password element; leave it as is.
<AdminUser> <UserName>AdminSOA</UserName> <Password>XXXXXX</Password> </AdminUser>
Add the
PasswordHashMethod
property to the UserStoreManager configuration forJDBCUserStoreManager
. For example:<UserStoreManager class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"> <Property name="PasswordHashMethod">SHA</Property> ... </UserStoreManager>
The
PasswordHashMethod
property specifies how the password should be stored. It usually has the following values:SHA
- Uses SHA digest method.MD5
- Uses MD 5 digest method.PLAIN_TEXT
- Plain text passwords.
In addition, it also supports all digest methods in http://docs.oracle.com/javase/6/docs/api/java/security/MessageDigest.html.
- Update the connection details found within the
<UserStoreManager>
class based on your preferences. In the realm configuration section, set the value of the
MultiTenantRealmConfigBuilder
property toorg.wso2.carbon.user.core.config.multitenancy.SimpleRealmConfigBuilder
. For example:<Property name="MultiTenantRealmConfigBuilder">org.wso2.carbon.user.core.config.multitenancy.SimpleRealmConfigBuilder</Property>
- Add the JDBC driver to the classpath by copying its JAR file into the
<PRODUCT_HOME>/repository/components/lib
directory. - Edit the SQLs in the
user-mgt.xml
file according to your requirements, and then start the server.