Tag: admin service

How to access wso2 admin service from jaggery

This post explain how to access wso2 admin service from jaggary code.

By default admin services are hidden from consumers in wso2 products. Discovering the admin service wslds of a product can be found here[1]

As an example we are going to see how to add a role to a user in any wso2 product using admin service.

1 . Create a role called “subsciber”  via admin console

2. Create a user called “jena” via admin console

3. Assign the role created in 1 to user created in 2 via admin service call.

(for this post assume step 1 and 2 are done in carbon super tenant)

For this particular scenario we need use https://localhost:9443/services/UserAdmin?wsdl. In the wsdl there is a operation called “addRemoveRolesOfUser”  which is used to add or remove roles of a user.

In order to invoke this method in jaggery code we need to know
1. Endpoint of the service
2. Request payload
3. Admin user credential of the tenant where particular user exists(admin service is protected with basic authentication)
Both can be taken from the wsdl manually or taken by creating new soap ui project using this wsld.

add_role_soapui

jaggery code – User WSRequest object[2] to send the request


<%
 var ws = require("ws");
 var version = new ws.WSRequest();
 var options = new Array();
 options.usesSOAP = 1.2;
 options.mep = "in-only";
 options.action = "urn:addRemoveRolesOfUser";
 var log=new Log();
 var username = "jena"

 var paylod = '<xsd:addRemoveRolesOfUser xmlns:xsd="http://org.apache.axis2/xsd"><xsd:userName>'+username+'</xsd:userName><xsd:newRoles>subscriber</xsd:newRoles><xsd:deletedRoles>?</xsd:deletedRoles></xsd:addRemoveRolesOfUser>';
var result;
try {
 version.open(options, "https://localhost:9443/services/UserAdmin.UserAdminHttpsSoap12Endpoint", false, "admin", "admin");
 version.send(paylod);
 } catch (e) {
 log.error(e.toString());
 }
%>

  1. https://docs.wso2.com/display/AM160/WSO2+Admin+Services
  2. http://jaggeryjs.org/documentation.jag?api=ws
Advertisements