---
slideOptions:
transition: slide
theme: night
tags: WSO2IS, Configure, Tutorial
type:
title: Configure OpenLdap become to primary User-Store with WSO2 Identity Server
---
<style>
.reveal section img {
background: transparent!important;
border: none!important;
box-shadow: none!important;
}
</style>
# How to configure OpenLdap with WSO2 Identity Server 5.4.0
- Hướng dẫn này sẽ giúp cấu hình một user-store (via OpenLdap) do bạn build thành primary user-store của wso2IS mà không cần dùng user-store mặc định của wso2.
## Thiết lập OpenLdap của bạn làm primary user-store
- Bước 1: Cài đặt OpenLdap theo hướng dẫn tại đây: [Ubuntu](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-OpenLdap-and-phpldapadmin-on-ubuntu-16-04) | [Windows](https://www.maxcrc.de/userbooster/)
- Bước 2: Tải các file custome schema và add vào OpenLdap đã cài đặt ở bước 1
+ [97-wso2Person.ldif](https://drive.google.com/file/d/1cVEZmuR2HzUStwhWG4nJ4nkTR2acbLwg/view?usp=sharing)
+ [98-scimPerson.ldif](https://drive.google.com/file/d/1iXk9MeWMEHYiopAVIm29v0tZ1-ziYObT/view?usp=sharing)
+ [99-identityPerson.ldif](https://drive.google.com/file/d/1Y9jvUanM2AP0kAoEIJr0aZhPOjMuNsoy/view?usp=sharing)
- Bước 3: Add các file config đã download ở bước 2 vào OpenLdap đã cài đặt ở bước 1
```ssh
sudo ldapadd -Y EXTERNAL -H ldapi:// -f 97-wso2Person.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:// -f 98-scimPerson.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:// -f 99-identityPerson.ldif
```
- Bước 4: Khởi tạo 2 OU (Organization Unit) có tên là <b>"User"</b> và <b>"Groups"</b> trong Ldap
- Bước 5: [Download](https://github.com/wso2/product-is/releases) phiên bản mới nhất của WSO2 Identity server và cài đặt
- Bước 6: Ở chế độ mặc định, Wso2 identity server sẽ nhúng một LDAP là user-store mặc định. Để dùng OpenLdap bạn đã cài đặt trên server của mình thì cần phải sửa 02 file
- <b><i>user-mgt.xml</i></b>(<i>[Carbon_home]/repository/conf</i>)
- <b><i>tenant-mgt.xml</i></b> (<i>[Carbon_home]/repository/conf</i>)
Nhớ đổi cn=admin,dc=wso2,dc=com tương ứng với các giá trị trên OpenLdap mà bạn đã cài đặt
1. <b><i>user-mgt.xml</i></b>(<i>[Carbon_home]/repository/conf</i>):
```
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager</Property>
**<Property name="ConnectionURL">ldap://localhost:389</Property>**
<Property name="ConnectionName">cn=admin,dc=wso2,dc=com</Property>
<Property name="ConnectionPassword">root</Property>
<Property name="AnonymousBind">false</Property>
<Property name="UserSearchBase">ou=Users,dc=wso2,dc=com</Property>
<Property name="UserEntryObjectClass">identityPerson</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="UserNameSearchFilter">(&(objectClass=person)(uid=?))</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="DisplayNameAttribute"/>
<Property name="ReadGroups">true</Property>
<Property name="WriteGroups">true</Property>
<Property name="GroupSearchBase">ou=Groups,dc=wso2,dc=com</Property>
<Property name="GroupEntryObjectClass">groupOfNames</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="GroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property>
<Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="MembershipAttribute">member</Property>
<Property name="BackLinksEnabled">false</Property>
<Property name="UsernameJavaRegEx">[a-zA-Z0-9._\-|//]{3,30}$</Property>
<Property name="UsernameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="UsernameJavaRegExViolationErrorMsg">Username pattern policy violated</Property>
<Property name="PasswordJavaRegEx">^[\S]{5,30}$</Property>
<Property name="PasswordJavaScriptRegEx">^[\S]{5,30}$</Property>
<Property name="PasswordJavaRegExViolationErrorMsg">Password length should be within 5 to 30 characters</Property>
<Property name="RolenameJavaRegEx">[a-zA-Z0-9._\-|//]{3,30}$</Property>
<Property name="RolenameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="SCIMEnabled">true</Property>
<Property name="IsBulkImportSupported">false</Property>
<Property name="EmptyRolesAllowed">false</Property>
<Property name="PasswordHashMethod">PLAIN_TEXT</Property>
<Property name="MultiAttributeSeparator">,</Property>
<Property name="MaxUserNameListLength">100</Property>
<Property name="MaxRoleNameListLength">100</Property>
<Property name="kdcEnabled">false</Property>
<Property name="defaultRealmName">WSO2.ORG</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="ConnectionPoolingEnabled">false</Property>
<Property name="LDAPConnectionTimeout">5000</Property>
<Property name="ReadTimeout"/>
<Property name="RetryAttempts"/>
</UserStoreManager>
```
2. <b><i>tenant-mgt.xml</i></b> (<i>[Carbon_home]/repository/conf</i>):
```
<!--When the primary user store is using LDAP user store, in MT mode following tenant manager will be used.-->
<TenantManager class="org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager">
<Property name="MultiTenantRealmConfigBuilder">org.wso2.carbon.user.core.config.multitenancy.CommonLDAPRealmConfigBuilder</Property>
<Property name="RootPartition">dc=wso2,dc=com</Property>
<Property name="OrganizationalObjectClass">organizationalUnit</Property>
<Property name="OrganizationalAttribute">ou</Property>
<Property name="OrganizationalSubContextObjectClass">organizationalUnit</Property>
<Property name="OrganizationalSubContextAttribute">ou</Property>
</TenantManager>
```
- Start WOS2IS, bạn sẽ thấy OpenLdap của bạn đã là primary data source.
## Configure cho phép add user thông qua Wso2 identity server console
Tuy nhiên, khi bạn thử thêm một user bằng manager console của WSOIS thì bạn sẽ bị gặp lỗi sau:
> Could not add user PRIMARY/asenelupin@gmail.com. Error: Cannot access the directory context or user already exists in the system for user :asenelupin@gmail.com
Trong LDAP Console bạn có thể nhìn thấy Wso2 identity server đang cố gắng thêm user với một <b><i>ref-attribute</i></b>. Nguyên nhân gây ra lỗi trên là do <b><i>resourceType</i></b> mapped các thuộc tính của Ldap. Để khắc phục lỗi này chúng ta thực hiện như sau:
- Bước 1: Login và Console manager của Wso2 identity server và vào <b>Home</b> -> <b>Indentity</b> -> <b>Claims</b> -> <b>List</b>
- Bước 2: Chọn <b><i>"urn:ietf:params:scim:schemas:core:2.0"</i></b> và click <b>Edit</b> vào <b><i>"urn:ietf:params:scim:schemas:core:2.0:meta.resourceType"</i></b>
- Bước 3: Ở ô nhập giá trị của <b><i>"Mapped Local Claim"</i></b> và thay đổi giá trị từ <b><i>http://wso2.org/claims/resourceType</i></b> thành <b><i>http://wso2.org/claims/userType</i></b> rồi click <b>Update</b>

- Bước 4: Sau khi thay đổi bạn đã có thể thêm được user vào OpenLdap của bạn thông quan Console manager của Wso2 identity server