Friday, June 29, 2018

Bulk delete users via admin services in WSO2 IS

There are times you create bulk users in WSO2 IS product for testing purposes and once you are done with the test you need to delete them. The following script can be used to bulk delete users by iteratively calling the deleteUser operation of the UserAdmin admin service.

This script is written to delete users created according to the following pattern.

If the username is Test,
Test001
Test002
...
Test010
Test011
...
Test099
Test100

You can modify the script according to your requirement.

#!/bin/bash
username=<username>

echo "Started deleting users"

for i in `seq -w 1 100`
do
   
 
curl -v -k --user <username>:<password> 
https://<hostname>:<port>/services/UserAdmin.UserAdminHttpsSoap11Endpoint/
 --data '<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://org.apache.axis2/xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <xsd:deleteUser>
         <!--Optional:-->
         <xsd:userName>'"${username}${i}"'</xsd:userName>
      </xsd:deleteUser>   
   </soapenv:Body>
</soapenv:Envelope>' --header "Content-Type:text/xml" --header "SOAPAction:urn:deleteApplication"


  echo "Deleted user : ${username}${i}"
done

echo "Completed deleting users"
Hope it is useful :)

No comments:

Post a Comment