Monday, December 22, 2014

Custom SSO redirect page for WSO management console

When we enable Single-Sign-On Across Different WSO2 Products[1] we get a default SAML SSO redirect page which displays text "Loading WSO2 StratosLive..."

Currently we cannot customize this code directly.

Therefore, I have written a new osgi component registering a filter which redirects URL requests for the default "redirect_ajaxprocessor.jsp" to a custom jsp. With this approach I was able to change the SSO redirect "Loading WSO2 StratosLive..." to "Redirecting to SSO Login..." using this custom jsp. I have tested this with IS 5.0.0 and DSS 3.2.2.
Hence, you can do desired customizations to this SSO redirect page using a custom ('/org.wso2.carbon.sso.redirector.custom.ui/src/main/resources/web/stratos-auth-custom/redirect_ajaxprocessor.jsp') by implementing a custom component. 

You can checkout sample code (valid for wso2 products in carbon 4.2.0) of the above mentioned component from git repo.

  • Checkout the code from
  • Do any custom changes u need to see in t redirect page in /org.wso2.carbon.sso.redirector.custom.ui/src/main/resources/web/stratos-auth-custom/redirect_ajaxprocessor.jsp
  • After building '/org.wso2.carbon.sso.redirector.custom.ui' component, copy the .jar into CARBON_HOME/repository/components/dropins.
  • Restart the server.

You have to do this for every WSO2 product in the cluster.
Read More

Sunday, December 21, 2014

Generate Selenium UI tests into a Custom format

  1. Install Firefox
  2. Install Selenium plugin for firefox [1]
  3. Start a firefox browser and start selenium IDE. (tools> Selenium IDE)
  4. Goto Options>Options>Formats of Selenium IDE user interface.
  5. Select one from the list of formats which is closely related to your test platform.
    1. ex: select Java/Junit4/Webdriver and click on source.

  1. Copy and save the code from Selenium IDE Format Source to a local location and close the window.
  2. Click on Add in Selenium IDE Options
  3. Give a proper name for the new format (ex: Jave/ CustomJunit/ WebDriver)
  4. Copy the content of the step 6 in to the “Selenium IDE Format Source” window.
  5. Save and restart the Selenium IDE.
  6. You can edit this template as per your preference. Edit relevant formating as mentioned in below image. 
    1. change package name
    2. add/remove imports
    3. etc

  7. Now you are done with a custom format for your test generation. 
    Perform UI actions you need to add in your test case.Now you will see that those actions get recorded in Selenium IDE. [2]
  8. Now File> Export Test Case as> Jave/ Custom/ WebDriver
  9. Save the test-case into your test project and execute it 

Read More

Saturday, July 19, 2014

Removing Default Types from WSO2 Enterprise Store

WSO2ES shipped with default store items of types 'Gadgets','E-Books' and 'WebSites'.

When you are building your own store using wso2es, you may need to remove default items and related menus from both the store and publiser. Here's the guide to do this.

Removing from Store- Front Office
  • Delete unwanted <asset-type> folders from 
'ES_HOME/repository/deployment/server/jaggeryapps/store/extensions/assets/' directory.
  • Remove unwanted entries from 
"assets": ["gadget", "site", "ebook"]
ex: if you need site only
    "assets": ["site"]
  • If you have started the server earlier, you will have to remove these entries from registry by editing '/_system/config/store/configs/store.json' using the management console.
  • Now remove the 
Removing from Publisher- Back Office
  • Delete unwanted <asset-type>.json's from
'/ES_HOME/repository/deployment/server/jaggeryapps/publisher/config/ext/' directory.
  • Edit following two code snippets of
'/ES_HOME/repository/deployment/server/jaggeryapps/publisher/config/publisher-tenant.json' to remove unwanted entries.
"collections": ["gadgets", "sites", "ebooks"]

ex: if you need site only
           "collections": ["sites"]

           "defaultAssets": {
                      "assetData": [{
                                                "type": "gadgets",
                                                "ignore":["agricultural-land", "intro-gadget-1", "intro-gadget-2", "gadget-template-explorer",  "gadget-explorer", "co2-emission", "electric-power",  "energy-use", "greenhouse-gas"]},
                        "type": "ebooks"},
                         "type": "sites" }]}

ex: if you need site only
           "defaultAssets": {
                      "assetData": [{"type": "sites"}]}
  • If you have started the server earlier, you will have to do the changes to registry by editing
'/_system/config/publisher/configs/publisher.json' using the management console.

  • Edit
'ES_HOME/repository/deployment/server/jaggeryapps/publisher/controllers/index_router.jag' to set the landing page to preferred asset-type.      

ex: if you need site
Restart the server and here you go!
Read More

Saturday, June 7, 2014

Writing a Jaggery Client for secured REST Resource

Every day, the more I learn new stuff,the more I feel exited !!!

Last week I had a delicious bite from {Jaggery.js} and let me share a bit with you all. :)

First we need to setup a {Jaggery.js} server to host the client application we are about to write.

Setting up Jaggery

  • Download {Jaggery.js} server from {Jaggery.js} site
  • Extract to a directory you prefer. lets call it JAGGERY_HOME
  • Navigate to JAGGERY_HOME/bin directory which contains all the Jaggery execution scripts.
  • Run sh JAGGERY_HOME/bin/   ( JAGGERY_HOME/bin/server.bat in windows) command to start the server.

Writing the Jaggery Client

  • Goto JAGGERY_HOME/apps directory. 
  • Create directory JaggeryClient inside JAGGERY_HOME/apps.
  • Create secureClient.jag and Base64Encode.jag files inside JAGGERY_HOME/apps/JaggeryClient directory.
  • secureClient.jag file content is as follows.                                                   

    1. </%function secure_call(request){                           
    2. var Base64Encode = require("Base64Encode.jag");  

    3. var username = request.username;                 
    4. var password = request.password;                 
    5. var url = request.url;                           
    6. var data =;                                                                  
    7. var code = "Basic " + username + ":" + password;;
    8. var auth = Base64Encode.base64_encode(code);     
    9. var header = {"Authorization":auth};             
    10. var repleyJson = get(url, data ,header,"json");  
    12. response.content  = repleyJson;                  
    13. }                                                        
    14. %> 
  • Above request filed is in JSON format as follows.
{ username:"username",password:"password", url:"url of the resource", data:"" }
  • Jaggery GET method is used to access the rest resource and Basic Authentication username and password are sent, encoded in the header.
    • Base64Encode file content is as follows. [source:]     
      1. function base64_encode(data) {                           
      2.  var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
      3.   var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
      4.     ac = 0,
      5.     enc = '',
      6.     tmp_arr = [];

      7.   if (!data) {
      8.     return data;
      9.   }

      10.   do { // pack three octets into four hexets
      11.     o1 = data.charCodeAt(i++);
      12.     o2 = data.charCodeAt(i++);
      13.     o3 = data.charCodeAt(i++);

      14.     bits = o1 << 16 | o2 << 8 | o3;

      15.     h1 = bits >> 18 & 0x3f;
      16.     h2 = bits >> 12 & 0x3f;
      17.     h3 = bits >> 6 & 0x3f;
      18.     h4 = bits & 0x3f;

      19.     // use hexets to index into b64, and append result to encoded string
      20.     tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
      21.   } while (i < data.length);
      22.  enc = tmp_arr.join('');
      23.  var r = data.length % 3;
      24.  return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
      25. }
      26. %>
    • Now we are done with the Jaggery Client.

    Accessing secured resource via the Client

    • Next we try it with a secured REST Resource as shown in following secureCall.jag.
      1. <%                                                       
      2. var include = require("secureClient.jag");
      3. include.secure_call({ username:"replace_with_valid_username",password:"replace_with_valid_password", url:"replace_with_valid_url_to secured source", data:"" });
      4. %>
    • place above secureCall.jag file in JAGGERY_HOME/apps/JaggeryClient folder and goto http://localhost:9763/JaggerySecureClient/secureCall.jag to see whether it works. 
      Hope you enjoyed the taste. smiley

        Read More
        Designed ByBlogger Templates