Calling UserStore related service in WSO2 Carbon using WS-Client
WSO2 Carbon Servers expose all functionalities as Web-Services. In fact the WSO2 Management console is one such web app that utilize the Web services to build a comprehensive management console. Such services are called as Admin Services.
We are going to use the API to list the users of a provided role using a Java based web-service client (WS-Client). WSO2 has a set of service stubs released that can be used get this done.
The other option is to use the WSDL (Web Service Descriptor) to generate the stubs. WSDLs of the Admin Services are hidden by default. To enable them - change the flag in the carbon.xml - <HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>
After that you can view the Admin Services deployed on the server by starting the server on OSGi mode. To start with OSGi mode run - sh bin/wso2server.sh -DosgiConsole. Once the server finished booting up you can execute - listAdminServices.
Creating the Maven Project
Next thing we want to do is to create the maven project which has all the necessary dependencies. Below section needs to be added to the pom.xml file.
Admin Services are protected with Basic Authentication. To call the UserStore related Services - I first need an authorized cookie. I am going to call the Authentication Endpoint to obtain the authorized cookie.
When we call the authenticate() method with user credentials - we get a return of the authenticated cookie. Next I am going to call the service method that returns me all the user that belongs to a role.
In the above class - we have created a method called getUsersOfRole() which calls an existing method in the stub.
Below is a code block that utilize the above created ServiceAdminClient class to print the list of users for a role.
org.wso2.carbon.um.ws.api.stub is one such stub that can be perform operations available in WSO2 Components. A custom app can be used to build and register users using the services available.