Tuesday, January 8, 2013

Database Configuration in WSO2 Carbon Products

Wso2 Carbon is an open source enterprise SOA midldeware platform. There is a facility to engage with different databases such as H2,Apache Derby,MS SQL Server,MySQL,Oracle,OpenEdge,PostgreSQL,IBM DB2 to hold the User Management data,Registry..etc.

Following diagram will help you to identify how we can configure the database in different way
Here I'm using WSO2 Identity Server as Carbon product and explaining two simple samples.
DB Configuration

Before going to discuss about samples we have to understand which configuration files that we need use.

First You have to go to $IS_HOME/repository/conf 
user-mgt.xml - all user store and user permission configurations.
registry.xml - all registry configurations.

Lets go to $IS_HOME/repository/conf/datasources 
master-datasources.xml - this is the common file that we used to define data sources configurations.

Move to above sample 1 there is a single mysql database to store User permission, Registry data and embedded LDAP for User Store (ex/ username, password,..etc ).

1.master-datasources.xml - first you have to define the mysql datasource
Go to mysql and create database call WSO2_MYSQL_CARBON_DB

[sourcecode language="sql"]
create database WSO2_MYSQL_CARBON_DB
[/sourcecode]

1.Then place the database name under name tag
2.Change the Jndi Config name jdbc/WSO2MysqlCarbonDB
3.Update url as jdbc:mysql://localhost:3306/WSO2_MYSQL_CARBON_DB
4.Set username and password rootroot123 5.Driver class name com.mysql.jdbc.Driver
5.Define driver class name as com.mysql.jdbc.Driver
6.Now you have to copy the driver into $IS_HOME/repository/components/lib

[sourcecode language="xml"]
<datasource>
   <name>WSO2_CARBON_DB</name>
   <description>The datasource used for registry and user manager</description>
   <jndiConfig>
      <name>jdbc/WSO2CarbonDB</name>
   </jndiConfig>
   <definition type="RDBMS">
    <configuration>
      <url>jdbc:h2:repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</url>
      <username>wso2carbon</username>
      <password>wso2carbon</password>
      <driverClassName>org.h2.Driver</driverClassName>
      <maxActive>50</maxActive>
      <maxWait>60000</maxWait>
      <testOnBorrow>true</testOnBorrow>
      <validationQuery>SELECT 1</validationQuery>
      <validationInterval>30000</validationInterval>
    </configuration>
   </definition>
</datasource>
[/sourcecode]

2.registry.xml
Now you have to refer the created datasource in registry xml.
change datasource name as jdbc/WSO2MysqlCarbonDB

[sourcecode language="xml"]
<dataSource>jdbc/WSO2MysqlCarbonDB</dataSource>
[/sourcecode]

3.user-mgt.xml
Refer the created data source in here as well. This is for User permission data.

[sourcecode language="xml"]
<Configuration>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>admin</Password>
</AdminUser>
<EveryOneRoleName>everyone</EveryOneRoleName> <!-- By default users in this role sees the registry root -->
<Property name="dataSource">jdbc/WSO2MysqlCarbonDB</Property>
<Property name="MultiTenantRealmConfigBuilder">org.wso2.carbon.user.core.config.multitenancy.CommonLDAPRealmConfigBuilder</Property>
</Configuration>
[/sourcecode]

Now if we look at User Store configuration we don't need Jdbc connection because this is going to connect with LDAP so its different protocol. to understand follow this configuration.

[sourcecode language="xml"]
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
<Property name="defaultRealmName">WSO2.ORG</Property>
<Property name="kdcEnabled">false</Property>
<Property name="ConnectionURL">ldap://localhost:${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="ConnectionName">uid=admin,ou=system</Property>
<Property name="ConnectionPassword">admin</Property>
<Property name="passwordHashMethod">SHA</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="UserEntryObjectClass">scimPerson</Property>
<Property name="UserSearchBase">ou=Users,dc=wso2,dc=org</Property>
<Property name="UserNameSearchFilter">(&amp;(objectClass=person)(uid=?))</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="PasswordJavaScriptRegEx">^[\\S]{5,30}$</Property>
<Property name="ServicePasswordJavaRegEx">^[\\S]{5,30}$</Property>
<Property name="ServiceNameJavaRegEx">^[\\S]{2,30}/[\\S]{2,30}$</Property>
<Property name="UsernameJavaScriptRegEx">^[\\S]{3,30}$</Property>
<Property name="UsernameJavaRegEx">[a-zA-Z0-9._-|//]{3,30}$</Property>
<Property name="RolenameJavaScriptRegEx">^[\\S]{3,30}$</Property>
<Property name="RolenameJavaRegEx">[a-zA-Z0-9._-|//]{3,30}$</Property>
<Property name="ReadLDAPGroups">true</Property>
<Property name="WriteLDAPGroups">true</Property>
<Property name="EmptyRolesAllowed">true</Property>
<Property name="GroupSearchBase">ou=Groups,dc=wso2,dc=org</Property>
<Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="GroupEntryObjectClass">groupOfNames</Property>
<Property name="GroupNameSearchFilter">(&amp;(objectClass=groupOfNames)(cn=?))</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="MembershipAttribute">member</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="UserDNPattern">uid={0},ou=Users,dc=wso2,dc=org</Property>
<Property name="SCIMEnabled">true</Property>
<Property name="maxFailedLoginAttempt">0</Property>
<Property name="DomainName">domain.com</Property>
</UserStoreManager>
[/sourcecode]

Lets move to Sample 2 you can see there are two databases connect with IS, one for user management and other for registry.
1.Create two data sources in master-datasources.xml as follows

[sourcecode language="xml"]
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for user permission data</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/WSO2_MYSQL_CARBON_DB</url>
<username>root</username>
<password>root123</password>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>

<datasource>
<name>WSO2_REGISTRY_DB</name>
<description>The datasource used for registry</description>
<jndiConfig>
<name>jdbc/WSO2RegistryDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:h2:repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<driverClassName>org.h2.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
[/sourcecode]

2.registry.xml - refer H2 datasource

[sourcecode language="xml"]
<dataSource>jdbc/WSO2RegistryDB</dataSource>

[/sourcecode]

3.user-mgt.xml - refer mysql datasource

[sourcecode language="xml"]
<Configuration>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>admin</Password>
</AdminUser>
<EveryOneRoleName>everyone</EveryOneRoleName> <!-- By default users in this role sees the registry root -->
<Property name="dataSource">jdbc/WSO2CarbonDB</Property>
<Property name="MultiTenantRealmConfigBuilder">org.wso2.carbon.user.core.config.multitenancy.CommonLDAPRealmConfigBuilder</Property>
</Configuration>
[/sourcecode]

This is the way that we can simply configure the different databases with Carbon Products.

1 comment:

  1. [...] of all we need to do some configuration in Identity Server. Refer this post for additional information about data base configuration with wso2 [...]

    ReplyDelete