Wednesday, November 27, 2013

How to access the H2 database of the WSO2 API Manager

1. Go to <APIM HOME>\repository\conf and open the carbon.xml

2. Enable the following configurations as shown below:-

<H2DatabaseConfiguration>
        <property name="web" />
        <property name="webPort">8082</property>
        <property name="webAllowOthers" />
        <!--property name="webSSL" />
        <property name="tcp" />
        <property name="tcpPort">9092</property>
        <property name="tcpAllowOthers" />
        <property name="tcpSSL" />
        <property name="pg" />
        <property name="pgPort">5435</property>
        <property name="pgAllowOthers" />
        <property name="trace" />
        <property name="baseDir">${carbon.home}</property-->
    </H2DatabaseConfiguration>

3. The start the server

4. Go to http://localhost:8082 where you can see the login page for the H2 database



5. Type jdbc:h2:repository/database/WSO2AM_DB as JDBC URL and wso2carbon as username and password.



Monday, November 25, 2013

How to configure WSO2 API Manager to use WSO2 BAM for statistics

1. Download WSO2 API Manager from here and WSO2 BAM from here.

First lets configure the BAM. I am using BAM 2.3.0 and APIM 1.5.0

BAM configuration
----------------------------

1. Change the <offset> tag of carbon.xml to 1 which is in <BAM HOME>\repository\conf (We are going to run APIM on port 9443 and BAM on 9444)

You can refer this for introductory information on WSO2 product start up. 

2. Then you have to copy the  API_Manager_Analytics.tbox which is in <APIM HOME>\wso2am-1.5.0\statistics to <BAM HOME>/repository/deployment/server/bam-toolbox

3. Add the following to <BAM_HOME>/conf/datasources/master-datasources.xml file.

<datasource>
          <name>WSO2AM_STATS_DB</name>
          <description>The datasource used for getting statistics to API Manager</description>
   <jndiConfig>
                <name>jdbc/WSO2AM_STATS_DB</name>
            </jndiConfig>
          <definition type="RDBMS">
          <configuration>
                 <!-- JDBC URL to query the database -->
                 <url>jdbc:h2:<BAM_HOME>/repository/database/APIMGTSTATS_DB;AUTO_SERVER=TRUE</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>

        <datasource>
           <name>WSO2BAM_CASSANDRA_DATASOURCE</name>
           <description>The datasource used for Cassandra data</description>
           <definition type="RDBMS">
               <configuration>
                   <url>jdbc:cassandra://localhost:9161/EVENT_KS</url>
                   <username>admin</username>
                   <password>admin</password>
               </configuration>
           </definition>
       </datasource>

Note:- When adding the above configurations, please check whether some of those are already there. No need of duplicating. And also check whehter the cassandra port is set to 9161 since we are running the BAM on port 9444. (we changed the offset of BAM)

For <BAM HOME> you need to give the path where you have extracted the BAM product.

Now lets go and configure APIM.

APIM configurations
--------------------------------------

1. Enable the following configurations in repository/conf/api-manager.xml.

<!--
   Enable/Disable the API usage tracker.
    -->
<Enabled>true</Enabled>

    <!--
        JNDI name of the data source to be used for getting BAM statistics.This data source should
        be defined in the master-datasources.xml file in conf/datasources directory.
    -->
    <DataSourceName>jdbc/WSO2AM_STATS_DB</DataSourceName>

2. Configure the following in the <APIM HOME>/conf/datasources/master-datasources.xml file.

<datasource>
         <name>WSO2AM_STATS_DB</name>
         <description>The datasource used for getting statistics to API Manager</description>
         <jndiConfig>
            <!-- This jndi name should be same as the DataSourceName defined in api-manager.xml -->
            <name>jdbc/WSO2AM_STATS_DB</name>
         </jndiConfig>
         <definition type="RDBMS">
            <configuration>
                <!-- JDBC URL to query the database -->
                <url>jdbc:h2:<BAM_HOME>/repository/database/APIMGTSTATS_DB;AUTO_SERVER=TRUE</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>

Note:- For <BAM HOME> you need to give the path where you have extracted the BAM product.

Now start the BAM server and then start the APIM.
Using WSO2 APIM you can create APIs and publish them to be used by external users by subscribing.
Lets learn about the WSO2 API Manager in the coming posts.

NOTE:-
In a clustered deployment change APIM setting in Gateway and Publisher nodes.

See ya'll for now :)

Wednesday, November 6, 2013

How to connect a JDBC user store as a secondary user store for WSO2 IS 4.5.0

Hi All,

Today lets talk about how to connect WSO2 Identity Server to a JDBC user store to be used as a secondary user store.

Environment is : 

WSO2 IS 4.5.0
Ubuntu
MySQL

You need to have MySQL server installed. Download WSO2 Identity Server from here and MySql jdbc driver from here. Extract the IS server into a local folder and extract jdbc driver .zip as well.

1) First type the following command for root user access.
mysql -u root -p

Note:- You have to have your domain registered in the hosts file. In this scenario we are using localhost.

2) Then you can create a user for your new database.
CREATE USER umesha@localhost IDENTIFIED BY 'umesha';

3) Then create a new database
create database userStoreTest;

4) Then grant all access to the new user for that database
grant all on userStoreTest.* TO umesha@localhost identified by "umesha";

5) Exit from root user 
exit;

6) Go to [IS HOME] /wso2is-4.5.0/dbscripts$ and start MySql with newly created user
mysql -u umesha -p  and enter the password

7)  Use the newly created database
use userStoreTest;

8) Run the mysql database script provided by the WSO2 IS 4.5.0 to created the necessary tables for the storage of IS user information
source ./mysql.sql

9) Copy the jdbc driver .jar to <IS HOME>/repository/components/lib

10) Start the Identity Server with sh wso2server.sh and login to the management console by admin and admin as username and password respectively

11) Go to Configure/ User Store Management/ Add Secondary User Store

12) Fill as follows:

1. give a domain name
2.  driverName : com.mysql.jdbc.Driver
3. give the database url, username and password

(please click on the image to maximize ;) )



Click on add and the userstore will be saved. You can create users and roles for the IS using this secondary user store.

Thanks :)