Saturday, March 11, 2017

How to add a certificate as a trusted certificated to a Java KeyStore (JKS file)?

1. What is Asymmetric Cryptography?


Asymmetric cryptography is used for secured communication. Public and private keys are the main parts of asymmetric cryptography. 

2. How it works? 


For an example, say server A wants to securely send a message to server B.  In order to do that Server B has to generate a public private key pair and share the public key with server A. When sending the message, server B encrypts it using public key of server A. Speciality of using the public key of server B for the encryption is that it can only be decrypted using the private key of server B. Once the server B receives the message it uses his private key to decrypt the message. 

Refer to: [1] to learn more on how asymmetric (public key) encryption works.

3. What is a Java KeyStore?


As per the above example it is clear that private key should be store very securely. You can think of the keyStore as a safe that you can store your keys. KeyStore as well as public-private key pair should be protected using a password.  

4. How to add a certificate as a trusted certificated to a Java KeyStore?


Lets take the above example;

Step 01


Server B wants to generate a key pair given the key pair alias as 'serverb' and add it into the created keyStore given the name 'serverbkeystore.jks'.

Key tool command [2]

keytool -genkey -alias serverb -keystore serverbkeystore.jks 

Output


Enter keystore password:  
Re-enter new password: 
What is your first and last name?
  [Unknown]:  serverb.com
What is the name of your organizational unit?
  [Unknown]:  qa
What is the name of your organization?
  [Unknown]:  wso2
What is the name of your City or Locality?
  [Unknown]:  colombo
What is the name of your State or Province?
  [Unknown]:  western
What is the two-letter country code for this unit?
  [Unknown]:  lk
Is CN=serverb.com, OU=qa, O=wso2, L=colombo, ST=western, C=lk correct?
  [no]:  yes

Enter key password for
(RETURN if same as keystore password):

Step 02


List keys in the key store. 
Notice that 'Entry type' of the key pair with private key is marked as 'PrivateKeyEntry' whereas public certificates are marked as 'trustedCertEntry'.

Key tool command


keytool -list -v -keystore serverbkeystore.jks


Output

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 2 entries

Alias name: verisignclass3g3ca
Creation date: Mar 11, 2017
Entry type: trustedCertEntry

Owner: CN=VeriSign Class 3 Public Primary Certification Authority - G3, OU="(c) 1999 VeriSign, Inc. - For authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
Issuer: CN=VeriSign Class 3 Public Primary Certification Authority - G3, OU="(c) 1999 VeriSign, Inc. - For authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US
Serial number: 9b7e0649a33e62b9d5ee90487129ef57
Valid from: Fri Oct 01 06:00:00 IST 1999 until: Thu Jul 17 05:29:59 IST 2036
Certificate fingerprints:
MD5:  CD:68:B6:A7:C7:C4:CE:75:E0:1D:4F:57:44:61:92:09
SHA1: 13:2D:0D:45:53:4B:69:97:CD:B2:D5:C3:39:E2:55:76:60:9B:5C:C6
SHA256: EB:04:CF:5E:B1:F3:9A:FA:76:2F:2B:B1:20:F2:96:CB:A5:20:C1:B9:7D:B1:58:95:65:B8:1C:B9:A1:7B:72:44
Signature algorithm name: SHA1withRSA
Version: 1


*******************************************
*******************************************


Alias name: serverb
Creation date: Mar 11, 2017
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=serverb.com, OU=qa, O=wso2, L=colombo, ST=western, C=lk
Issuer: CN=serverb.com, OU=qa, O=wso2, L=colombo, ST=western, C=lk
Serial number: 3f06ea7a
Valid from: Sat Mar 11 20:59:07 IST 2017 until: Fri Jun 09 20:59:07 IST 2017
Certificate fingerprints:
MD5:  29:63:1F:2F:83:19:5B:D3:CF:65:45:15:63:3E:26:B6
SHA1: 94:C8:F2:28:AB:71:D7:2E:9F:7A:9C:90:9E:51:B2:C9:19:FC:C9:AE
SHA256: 3A:0E:F5:C0:A7:10:0F:19:47:95:29:C3:0A:9B:A8:39:56:74:9C:26:0B:A6:F6:63:74:CA:CB:FE:D4:32:3E:D8
Signature algorithm name: SHA1withDSA
Version: 3

Extensions: 

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 2C F1 24 27 05 A5 AB 16   3A 33 CC 3F E4 CF EC 1E  ,.$'....:3.?....
0010: 63 35 74 CF                                        c5t.
]
]


*******************************************
*******************************************

Step 03


Export the certificate to a file before importing it into the keyStore of server A.
Note : when exporting you must use the same alias which is being used in the private key. When importing you can use any alias of your choice.

Key tool command

keytool -export -keystore serverbkeystore.jks -alias serverb -file serverb.cert

Output

A file containing certificate should be created with the name 'serverb.cert' 

Step 04


Import the certificate into the keyStore of server A.

Key tool command

keytool -import -keystore serverakeystore.jks -alias serverb.com -file serverb.cert


Output


"Certificate was added to keystore" will be printed if the certificate is being added successfully. You can also list keys in server A keyStore to verify.

References

Tuesday, March 7, 2017

How to start Tomcat server in debug mode to debug a web application?

I recently develop a web application in and deployed it in Tomcat server.  To troubleshoot an issue occurred in the application I wanted to debug my application.  For that below are the steps I needed to perform to run my application in the debug mode.

1. Start Tomcat server in debug mode
2. Add a remote debug configuration
3. Debug application.


1. Start Tomcat server in debug mode

1. Navigate to Tomcat bin location.

2. Export below JVM parameters as an environment variable.


export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

Explanations : 

  • transport [1] - Transport method to use in connecting to debugger application (e.g. IDE) from the virtual machine (Tomcat).
  • address -  JVM starts and listens on the debug port given as the address.
  • suspend - If we set this as 'y' VM waits without loading the main class. (in this case without loading the main class in Catalina which is Catalina's bootstrap) In our case we have set this parameter to 'n' as we need Catalina to start on the given debug port.

3. Start Tomcat given 


./catalina.sh jpda start


2. Add a remote debug configuration 

Note : I have used Intellij Idea as my IDE.

1. Go to 'Run' > 'Edit Configuration' and click on the '+' to add a new debug configuration.



2. Configure remote debugging given the port similar to the address value specified in JVM environment variable.



3. When there are multiple debug configurations available, select relevant configuration.




4. Click on debug icon. If everything is configured accurately you will see a message saying Connected target VM with connection information. Then send you can send a request to the web application after adding debug points.




References

[1]. http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html


Thursday, June 9, 2016

How to fix "ERROR 1067 (42000): Invalid default value for tableName" occur even after removing 'DEFAULT 0' when two timestamp columns are defined.

In MySQL 5.7 'DEFAULT 0' is not accepted for when defining timestamp columns as 'NO_ZERO_DATE' mode is enabled by default.

I get "ERROR 1067 (42000): Invalid default value for 'REG_LAST_UPDATED_TIME' error when creating the table below, even after removing 'DEFAULT 0' in
EX: 'REG_CREATED_TIME    TIMESTAMP NOT NULL DEFAULT 0,'

1. Issue description

CREATE TABLE IF NOT EXISTS REG_RESOURCE(
            REG_PATH_ID         INTEGER NOT NULL,
            REG_NAME            VARCHAR(256),
            REG_VERSION         INTEGER NOT NULL AUTO_INCREMENT,
            REG_MEDIA_TYPE      VARCHAR(500),
            REG_CREATOR         VARCHAR(31) NOT NULL,
            REG_CREATED_TIME    TIMESTAMP NOT NULL,
            REG_LAST_UPDATOR    VARCHAR(31),
            REG_LAST_UPDATED_TIME    TIMESTAMP NOT NULL,
            REG_DESCRIPTION     VARCHAR(1000),
            REG_CONTENT_ID      INTEGER,
            REG_TENANT_ID INTEGER DEFAULT 0,
            REG_UUID VARCHAR(100) NOT NULL,
            CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
)ENGINE INNODB;

When creating above table "ERROR 1067 (42000): Invalid default value for 'REG_LAST_UPDATED_TIME' error occurred and table didn't get created. Please note that this error shows only when there are two timestamp columns (REG_CREATED_TIME and REG_LAST_UPDATED_TIME) in the table.

2. What happens when there are two time stamp columns?

According to [1] when we have two timestamp columns not declared an explicit 'DEFAULT' or 'ON UPDATE' clause, first column is automatically assigned the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP attributes, while the second one is assigned the '0000-00-00 00:00:00' (the “zero” timestamp).

3. Why are we getting the Error explained In issue description?

When 'strict SQL mode' and ' NO_ZERO_DATE' mode is enabled in MySQL server the “zero” timestamp is not allowed and it gives an error [2]. In MySQL 5.7 by default 'NO_ZERO_DATE' mode is enabled.

4.Fix

1) Recommended way of doing is replacing "DEFAULT 0" with "DEFAULT CURRENT_TIMESTAMP" .

2) You can also fix it by changing mysql modes

E.g. Setting MySQL mode to  'ALLOW_INVALID_DATES' [3].

> SET SQL_MODE='ALLOW_INVALID_DATES';


[1]. http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp
[2]. http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date
[3]. http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_allow_invalid_dates


Tuesday, May 24, 2016

How to sync time between servers.

Recently when I was working with a WSO2 Identity server cluster I needed server time to be sync between all nodes (servers). I used Centos and below are the steps I used.

1. Install ntpdate using

sudo yum install ntpdate

2. Synced time with 'sltime.org' time server

3. Created a shell script to run above command every 6 hours.


  • Create a file given .sh as the extension  (vi synctime.sh)
  • Add below into the created file. (This loop runs 120 times. System is syncing time to time server every 6 hours.)

for i in {1..120}
do
  sudo ntpdate sltime.org
  sleep 6h
done

  • Give execute permission to 'synctime.sh' file created before. 
  • Run the shell script in background.
./synctime.sh &

When I searched I also came across below blog post which I think is a better approach. Also check that our :)

http://www.cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock/
http://www.pool.ntp.org/zone/lk

Monday, April 4, 2016

How to troubleshoot SVN-Based Deployment Synchronizer issues in WSO2 products.

Observation

Recently when I was setting up a WSO2 API manager cluster which had publisher/store/key manager in a one node, gateway manager and gateway worker node having clustering and SVN-Based Deployment Synchronizer [1] enabled. The issue I faced was even though all my nodes started with no errors after publishing an API my API invocation failed with below error message in the carbon log of gateway worker node. 

[2015-09-16 17:36:29,279]  INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = /api1/1.0.0/customerservice/customers/123

Possible cause of the issue

  • This issue can occur when synapse configuration of the particular API is not in the /repository/deployment/server/synapse-configs/default/api synapse folder of the worker nodes. 

How to troubleshoot Deployment synchronisation issues 

1. Check /repository/deployment/server/synapse-configs/default/api folder for the API synapse config in each of the worker node.

If you cannot find the synapse config in the specified location there should something wrong with the deployment synchronisation.

As the next step you can check whether particular synapse file is in the SVN server repo. (URL of the SVN repo should be configured in 'DeploymentSynchronizer' section in _repository/conf/carbon.xml file in gateway worker nodes as well as gateway manager nodes.)

What configurations I should check?

Scenario 01 : Say you can see the synapse files in svn server location but not inside /repository/deployment/server/synapse-configs/default/api folder of the worker node

This means your manager node is successfully committing configurations into the SVN location yet worker nodes does not checkout the files.

This can happen due to incorrect configuration in 'DeploymentSynchronizer' section in  /repository/conf/carbon.xml file in gateway worker nodes. In the worker nodes make sure you have set 'AutoCommit' parameter to false and 'AutoCheckout' parameter to true.

Scenario 02 : Say configuration files are not committed to svn server location.

This means gateway manager node is not doing his work of committing artefact to the svn location.

This can happen due to incorrect configuration in 'DeploymentSynchronizer' section in /repository/conf/carbon.xml file in gateway manager node. In the manager node make sure you have set both  'AutoCommit' parameter and 'AutoCheckout' parameter to true.

For more information please refer to [1].

Note: 
Another possible reason for svn based deployment synchronization to not work is that your cluster is not configured properly. Normally when gateway manager commits an artifact to svn server location a cluster message is sent to worker nodes and once it is received workers check out the changes from the svn location. If everything is working fine, relevant messages should get printed on carbon logs of gateway manager and workers.

If you cannot see these messages check clustering configurations done under clustering section of the /repository/conf/axis2/axis2.xml file in all three nodes.  Verify that you have given the same domain name in all nodes and defined well known members correctly in the member section.

[1] https://docs.wso2.com/display/CLUSTER420/SVN-Based+Deployment+Synchronizer




Thursday, December 10, 2015

Monitor database calls using log4jdbc jar file.

When testing WSO2 API manager gateway resource cache I needed to monitor database calls in order to verify whether resources are taken from the cache or not. In this blog post I will explain how to use "log4jdbc.jar" to monitor db calls.

Note: 

  • I have used mysql database as my database connection. You can also use this for other databases as h2, Oracle.  
  • Create database tables before configuring 'log4jdbc'. To do that you can remove 'log4jdbc.jar' from the /repository/components/lib folder start with -Dsetup, once server is started successfully shutdown server add log4jdbc.jar and restart. 

How to configure

1. Add 'log4jdbc.jar' to /repository/component/lib folder. You may also have the  JDBC connector jar in this folder based on the database type you are using. You can download 'log4jdbc.jar' from here 

2. Edit /repository/conf/datasources/master-datasources.xml by giving "net.sf.log4jdbc.DriverSpy" as the driverClassName and  specify URL as "jdbc:log4jdbc:mysql://localhost:3306/apim1100_carbon".

        
3. Add below entries to /repository/conf/log4j.properties file

#Log all JDBC calls except for ResultSet calls 
#Log timing information about the SQL that is executed. 
log4j.logger.jdbc.sqltiming=DEBUG,sqltiming 
log4j.additivity.jdbc.sqltiming=false 

#the appender used for the JDBC API layer call logging above, sql timing 
log4j.appender.sqltiming=org.apache.log4j.FileAppender 
log4j.appender.sqltiming.File=./repository/logs/sqltiming.log 
log4j.appender.sqltiming.Append=false 
log4j.appender.sqltiming.layout=org.apache.log4j.PatternLayout 

log4j.appender.sqltiming.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n 

4. you can navigate to /repository/logs and tail 'sqltiming.log' file in order to monitor which queries are been executed. 

Reference


Sunday, August 30, 2015

Fix for WSO2 API Manager startup error "Caused by: java.sql.SQLException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging..." With MariaDB 5.5

Exception

ERROR - DefaultRealmService Cannot initialize the realm.
org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:377)
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:199)
at org.wso2.carbon.user.core.common.DefaultRealm.init(DefaultRealm.java:108)
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:225)
at org.wso2.carbon.user.core.common.DefaultRealmService.(DefaultRealmService.java:96)
at org.wso2.carbon.user.core.common.DefaultRealmService.(DefaultRealmService.java:109)
at org.wso2.carbon.user.core.internal.Activator.startDeploy(Activator.java:68)
at org.wso2.carbon.user.core.internal.BundleCheckActivator.start(BundleCheckActivator.java:61)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:334)
... 22 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while updating database
at org.wso2.carbon.user.core.util.UserCoreUtil.persistDomain(UserCoreUtil.java:733)
at org.wso2.carbon.user.core.common.AbstractUserStoreManager.persistDomain(AbstractUserStoreManager.java:3445)
at org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.(JDBCUserStoreManager.java:252)
at org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.(JDBCUserStoreManager.java:194)
... 27 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while updating database
at org.wso2.carbon.user.core.util.DatabaseUtil.updateDatabase(DatabaseUtil.java:534)
at org.wso2.carbon.user.core.util.UserCoreUtil.persistDomain(UserCoreUtil.java:729)
... 30 more
Caused by: java.sql.SQLException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at org.wso2.carbon.user.core.util.DatabaseUtil.updateDatabase(DatabaseUtil.java:524)
... 31 more
[2015-08-21 10:54:27,698] ERROR - Activator Cannot start User Manager Core bundle
org.wso2.carbon.user.core.UserStoreException: Cannot initialize the realm.
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:233)
at org.wso2.carbon.user.core.common.DefaultRealmService.(DefaultRealmService.java:96)
at org.wso2.carbon.user.core.common.DefaultRealmService.(DefaultRealmService.java:109)
at org.wso2.carbon.user.core.internal.Activator.startDeploy(Activator.java:68)
at org.wso2.carbon.user.core.internal.BundleCheckActivator.start(BundleCheckActivator.java:61)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:377)
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:199)
at org.wso2.carbon.user.core.common.DefaultRealm.init(DefaultRealm.java:108)
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:225)
... 19 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:334)
... 22 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while updating database
at org.wso2.carbon.user.core.util.UserCoreUtil.persistDomain(UserCoreUtil.java:733)
at org.wso2.carbon.user.core.common.AbstractUserStoreManager.persistDomain(AbstractUserStoreManager.java:3445)
at org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.(JDBCUserStoreManager.java:252)
at org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager.(JDBCUserStoreManager.java:194)
... 27 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while updating database
at org.wso2.carbon.user.core.util.DatabaseUtil.updateDatabase(DatabaseUtil.java:534)
at org.wso2.carbon.user.core.util.UserCoreUtil.persistDomain(UserCoreUtil.java:729)
... 30 more
Caused by: java.sql.SQLException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at org.wso2.carbon.user.core.util.DatabaseUtil.updateDatabase(DatabaseUtil.java:524)
... 31 more

Fix

1. Shutdown Confluence and your MySQL database
2. Open the MySQL configuration file (my.cnf) in a text editor
3.Locate the binlog_format property in this file in the [mysqld] section and ensure that its value is    
         row, such that you end up with:
         binlog_format=row
4. Save your changes to this file
5. Restart Confluence and your MySQL database

References

When using WSO2 products with MariaDB it is recommended to use compatible version MySQL JDBC connector. EX: MariaDB 10.0.20 with mysql-connector-java-5.1.36-bin.jar