Thursday, July 18, 2013

How to get a user profile for OAuth Token using JWT headers

In this blog post lets discuss how you can retrieve user profile and view attributes of a user using only the OAuth token in WSO2 Identity server. I assume that reader is familiar with WSO2 identity server and if you need more help you can follow the documentation at

1) Change the CARBON_HOME/repository/conf/identity.xml and make following attribute true. Then start the WSO2 Identity server.


2) Get the oauth Token ( you need to get the base64 encoded value for (client id:client secret) value.

You can use an online service for encoding such as and then issue following CURL command to obtain the access token. (make sure you have the correct port in the server URL)

curl -v -X POST -H "Authorization: Basic VE01enNFem9FZG9NRERjVEJjbXRBcWJGdTBFYTpYUU9URExINlBBOHJvUHJfSktrTHhUSTNseGNh" -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -k -d "grant_type=password&username=admin&password=admin" https://localhost:9443/oauth2endpoints/token

 3) Now you need to invoke and admin service in the Identity server. Please follow on how to invoke admin services using SOAP UI.

We shall now invoke the following service.



Now you will be getting the authorization context token which is encoded in base64 and delimited with "." values. Middle part will contain the user profile value and we can get it decoded using


Following is the output of the decoded value which has the user profile details of the user who generated the OAuth access token.

Monday, April 22, 2013

How to disable automatic service creation with WSDL upload

When you upload a WSDL to WSO2 Governance Registry it will create a Service Artifact automatically for that WSDL. But in case you do not want that to be automated and need to add services differently this is how to disable that feature.

1) Open GREG_HOME/repository/conf/registry.xml

2) Search for 
<property name="createService">false</property>
and uncomment them.

There will be two locations generally for normal WSDL handler and for ZIP or archive based upload handler (Where you upload multiple WSDL files together).

Save registry.xml and restart your server. Now you can observe that it will not create Services automatically for WSDL uploads.

Tuesday, March 26, 2013

How to send CDATA inside your SOAP message payload

(Please note this a temporary workaround and this will be addressed properly in future releases)

If you need to send a SOAP message payload ever and if it resulted something like this.


Because by default, a StAX parser must be in non coalescing mode (It overrides the default settings mandated by the StAX specification) and as a side effect of that parser coaelsce CDATA sections. [1]
You need to add the file with the following entry to CARBON_HOME/ (root) folder.

For more information


Saturday, February 16, 2013

Make a Torrent downloader with Raspberry Pi in 3 steps :)

If you are downloading torrents heavily with your highly capable machine, You are wasting a lot of resources. Why do not you use your Raspberry Pi to do it ;)

I recieved a Raspberry Pi @ wso2con 2013. I was really happy after seeing this as i was planning to get down a one anyway. This is my first project out of it. Need some time to go for a real big project. Yes i have a pieces of my old nookcolor including its LCD ;).

1st step

You need to configure your Raspberry pi with this tutorial.

When you go to configuration screen make sure you enable ssh. So you can get rid of your monitor after that.

2nd Step

Install a remote viewer so you can view your Raspberry Pi desktop remotely.

3rd Step

Install Transmission in Raspberry pi. 

sudo apt-get update
apt-get install transmission

So you can download torrents from Raspberry pi and SCP them to your local machine at anytime. There are few torrent clients available so you can try them if you do not like transmission.

Sunday, February 3, 2013

Application Governance with WSO2 GReg and Jenkins

This tutorial will show how you can automate the application Governance using WSO2 Governance Registry and Jenkins (for Build Automation).


Things to note

  • Jenkins or similar build automation tool should be used to build the artifact and deploy it to the specific Dev SVN location. 
  • There are three SVN locations required for Dev , QA and Production artifact deployment. 
  • User needs to specify the exact name of the artifact (without the extension) as Application Name when adding the application to WSO2 Governance Registry. 
  • This particular sample is tested with WSO2 Governance Registry 4.5.1. Therefore it is recommended to use the same version of the product.

Resource Location

Please download resources from following location.



n this workflow build automation is excluded and user needs to add the built artifact and first deploy to Dev SVN location. (Developer may use Jenkins to build and its plugin to add it to a SVN location)

1) Create the Registry Extension file for Applications as specified below. Deploy the Application RXT file to Governance Registry as described in

<artifactType type="application/vnd.wso2-application+xml"

shortName="applications" singularLabel="Application" pluralLabel="Applications" hasNamespace="false" iconSet="9">
            <column name="Name">
                <data type="path" value="overview_name" href="/applications/@{name}"/>
            <column name="type">
                <data type="type" value="overview_type"/>
        <table name="Overview">
            <field type="text" required="true">
            <field type="options">
            <field type="text-area">

2) Create an Application in Governance Registry.

Add→ Application

Specify Name of the car/war file. (This should be the exact name in the svn location without extension)
eg: myCapp

3) Add Svn Executor to Governance Registry Server.

  • Edit the svn-executor-1.0.jar’s file and add your svn credentials and Jenkins URL.

  • Copy the svn-executor-1.0.jar and svnkit-bundle-1.0.0.jar (provided separately) to G-REG_HOME/repository/components/lib folder.

  • Copy svn-client-adapter-1.6.18.wso2v2.jar to G-REG_HOME/repository/components/dropins folder.

4) Add a new lifecycle in Governance Registry names AppLifeCycle by following the instructions provided in Use the lifecycle configuration specified below.

 ~ Copyright (c) 2005-2010, WSO2 Inc. ( All Rights Reserved.
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
<aspect name="AppLifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle">
    <configuration type="literal">
            <scxml xmlns=""
                <state id="Development">
                        <data name="checkItems">
                            <item name="Code Completed" forEvent="">                            
                            <item name="Added to SVN" forEvent="">

   <data name="transitionExecution">
                            <execution forEvent="Promote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
     <parameter name="currentEnvironment" value=""/>
                                <parameter name="targetEnvironment" value=""/>
                    <transition event="Promote" target="Testing"/>                  
                <state id="Testing">
                        <data name="checkItems">
                            <item name="Effective Inspection Completed" forEvent="">
                            <item name="Test Cases Passed" forEvent="">
                            <item name="Smoke Test Passed" forEvent="">
                         <data name="transitionExecution">
                            <execution forEvent="Promote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
                                <parameter name="currentEnvironment" value=""/>
                                <parameter name="targetEnvironment" value=""/>

                            <execution forEvent="Demote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
                             <parameter name="currentEnvironment" value=""/>
                    <transition event="Promote" target="Production"/>
                    <transition event="Demote" target="Development"/>
                <state id="Production">  
                        <data name="checkItems">
                            <item name="Verify No one using the application" forEvent="">
   <data name="transitionExecution">
                            <execution forEvent="Retire" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
    <parameter name="currentEnvironment" value=""/>
                                <parameter name="targetEnvironment" value=""/>
                    <transition event="Retire" target="Retired"/>
                <state id="Retired">  

In the above lifecycle configuration you need to change your svn locations that are used in promotions.


From Dev to QA
<parameter name="currentEnvironment" value=""/>
  <parameter name="targetEnvironment" 

5) Attach the AppLifeCycle to your application.

6) Promote Application from Development to Testing.
This will copy external CApp from Dev environment to QA environment (in the relevant SVN locations)

7) Demote Application from Testing to Development back
This will remove the artifact from QA environment (QA SVN location)

Deployment Automation with Jenkins

1) Start Jenkins and add the URL to svn-executor-1.0.jar’s properties file.

2) Create two Build jobs with name “promote” and “demote”.

3) Apply “This build is parameterized” check box and add following parameters to each of the job separately .

  • name
  • svnUrl
  • state

4) Create a local repository (A folder in you local file system) to check out the artifacts.
eg: /home/user1/repository

5) for promote Build job add the following script ( Build → Add build step → execute shell). Please change the values appropriately to suit your environment


if  [[ "${state}" == "Testing" ]] ;
##  repository location
cd /media/data/wso2/support/repository/

svn checkout $svnUrl

## svn checkout location (This will be repository url + ‘qa’ as
## QA artifact was store in our repository

cd /media/data/wso2/support/repository/qa
cp -r ./$name 

## Location of the Testing server

if [[ "${state}" == "Production" ]] ;
cd /media/data/wso2/support/repository/
svn checkout $svnUrl

## svn checkout location (This will be repository url + ‘prod’ as
## Production artifact was store in our repository

cd /media/data/wso2/support/repository/prod
cp -r ./$name 

## url of the Production server

6) For demote Build job use the following action ( Build → Add build step → execute shell)


if  [[ "${state}" == "Testing" ]] ;

## location of the local ‘QA’ artifacts are stored.
cd /media/data/wso2/support/repository/qa

svn update 

cd /media/data/wso2/support/wso2qaesb-4.5.0/repository/carbonapps/0

rm -rf ./$name

7) When you promote as in the script it will deploy the artifact to Development server and when demote it will remove the Application from Carbon server which will respectively deploy/ undeploy

8) You need to have similar script for artifact deployment from initial project to developer location which is not covered in the sample.