Exposing WSO2 Identity Server Admin Services as REST APIs

WSO2 Identity server 4.5.0 does not provide REST APIs for accessing its administrative services out of the box. However we could use WSO2 ESB to convert SOAP based administrative services to REST. Please follow the below steps to do this:

  1. Download WSO2 ESB 4.8.1 and IS 4.5.0.

  2. Extract ESB distribution and set the offset to 1 in carbon.xml file. <offset>1</offset>

  3. Extract IS distribution and set the HideAdminServiceWSDLs property to false in carbon.xml file. This will expose administrative services WSDLs.

<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>

  1. Now start IS with OSGi console enabled:

sh <IS-HOME>/bin/wso2server.sh -DosgiConsole

  1. Enter listAdminServices command in OSGi console and retrieve the list of administrative services available and their WSDLs.

  2. In this article I will use listAllUsers() method available in UserAdmin service to demonstrate how to convert SOAP based services to REST. UserAdmin service WSDL could be found at:

https://localhost:9443/services/UserAdmin?wsdl

  1. Now create an in sequence in ESB with the following content:

[code lang=“xml” escaped=“true”] xsd:filter$1/xsd:filter xsd:limit$2/xsd:limit /xsd:listAllUsers


8. Create an out sequence with the following content:

[code lang="xml" escaped="true"]
<sequence xmlns="http://ws.apache.org/ns/synapse" name="ListUsersOutSeq">
    <log level="full"/>
    <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
    <send/>
</sequence>
  1. Create an API with the following content:

[code lang=“xml” escaped=“true”]


10. Send a HTTP GET request to the listUsers API:

Request:

curl -v http://localhost:8281/listUsers?filter=*&limit=10


Response:

{“listAllUsersResponse”: {“return”:[ {“@type”:“ax2629:FlaggedName”,“dn”:{“@nil”:“true”},“domainName”:{“@nil”:“true”},“editable”:true, “itemDisplayName”:“admin”,“itemName”:“admin”,“readOnly”:false,“roleType”:{“@nil”:“true”},“selected”:false,“shared”:false}, {“@type”:“ax2629:FlaggedName”,“dn”:{“@nil”:“true”},“domainName”:{“@nil”:“true”},“editable”:false, “itemDisplayName”:null,“itemName”:false,“readOnly”:false,“roleType”:{“@nil”:“true”},“selected”:false,“shared”:false} ]}} ````

Imesh Gunaratne

Read more posts by this author.

Colombo, LK http://imesh.io