RSS

Database Configuration in WSO2 Carbon Products

08 Jan

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

create database WSO2_MYSQL_CARBON_DB

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

<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>

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

      <dataSource>jdbc/WSO2MysqlCarbonDB</dataSource>  

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

<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>

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.

<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>

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

       <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>      

2.registry.xml – refer H2 datasource

    <dataSource>jdbc/WSO2RegistryDB</dataSource>     

3.user-mgt.xml – refer mysql datasource

<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>  

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

About these ads
 
1 Comment

Posted by on January 8, 2013 in Identity Server, java, mysql, wso2

 

Tags: , , , ,

One response to “Database Configuration in WSO2 Carbon Products

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: