How to Easily Add and Test a MySQL Secondary User Store to WSO2 Micro Integrator

Piyumal Kularathna
2 min readOct 17, 2022

--

This article will guide you to get the job done from the scratch. First things first. Download JDK 11, MySQL Server and Micro Integrator 4.1, if you do not already have them.

For the sake of simplicity, let’s identify the path of Micro Integrator as <micro-integrator> for the rest of the article. This path can be any location you decide to put Micro Integrator.

Let’s say your MySQL username is “root” and MySQL password is “root@Root”. Login to MySQL server using below command.

mysql -u root -p

Now you have to run DB Scripts to create relevant Databases. In order to create ClusterDB, run below commands in MySQL server.

create database clusterdb;
use clusterdb;
source <micro-integrator>/dbscripts/mysql/mysql_cluster.sql;

Now run below commands to create TransactionDB.

create database transactiondb;
use transactiondb;
source <micro-integrator>/dbscripts/mysql/mysql_transaction_count.sql;

Also don’t forget to create UserDB using below commands which will be the User Store.

create database userdb;
use userdb;
source <micro-integrator>/dbscripts/mysql/mysql_user.sql;

After successfully created above databases, you will be able to view them using MySQL Workbench or MySQL Server.

Now that we have the databases,

go to <micro-integrator>/conf/deployment.toml change [user_store] properties as below.

[user_store]
type = “database”
class = “org.wso2.micro.integrator.security.user.core.jdbc.JDBCUserStoreManager”

Also add below lines to the deployment.toml.

[internal_apis.file_user_store]
enable = false
[[datasource]]
id = "WSO2CarbonDB" # "WSO2_COORDINATION_DB"
url = "jdbc:mysql://localhost:3306/userdb"
username = "root"
password = "root@Root"
driver = "com.mysql.jdbc.Driver"

Now UserDB in MySQL will be used as the user store for the Micro Integrator. Also get “mysql-connector-java-8.0.3.jar” file and add that to <micro-integrator>/lib path. Without it, I wasn’t able to get it working when running Micro Integrator. After that, you can run and add users and check whether it’s working or not.

Now you can follow this documentation and download the relevant file. In our case, file will be JDBC.xml.

Create a directory called “userstores” in

<micro-integrator>/repository/deployment/server/ and add that JDBC file to that directory. Let’s say you are planning to create a secondary user store called “wso2.com”, in that case, change the file like below.

<Property name=”url”>jdbc:mysql://localhost:3306/userdb2</Property>
<Property name=”userName”>root</Property>
<Property name=”password”>root@Root</Property>
<Property name=”DomainName”>wso2.com</Property>
<Property name=”driverName”>com.mysql.jdbc.Driver</Property>

Also make sure to change the file name as “wso2_com.xml”. The reason is explained in the WSO2 official documentation. Now create a database called userdb2 and run DB Script of UserDB in MySQL Server. The commands will be like below.

create database userdb2;
use userdb2;
source <micro-integrator>/dbscripts/mysql/mysql_user.sql;

At last, before running, make sure you change micro-integrator.sh/micro-integrator.bat’s property of DNonUserCoreMode as false.

-DNonUserCoreMode=false \

Now, if all things go accordingly, you will be able to run Micro Integrator and add users to different user stores using their domain names.

Happy Coding ♥️​

--

--