The content below is for Apache Syncope <= 1.2 - for later versions the Reference Guide is available. |
In order to leverage the Syncope Client Library (from Java), you need to setup a Maven-based project with at least the following dependency (replace 1.2.6 with your actual Syncope version):
<dependency>
<groupId>org.apache.syncope</groupId>
<artifactId>syncope-client</artifactId>
<version>1.2.6</version>
</dependency> |
The following code snippet will first query for all users and then request bulk action to delete all users. Naturally, depending on the actual total number of users, some adjustments might be needed.
SyncopeClient syncopeClient = new SyncopeClientFactoryBean().
setAddress("http://localhost:9080/syncope/rest/").
create("admin", "password");
UserService service = syncopeClient.getService(UserService.class);
BulkAction bulkAction = new BulkAction();
bulkAction.setOperation(BulkAction.Type.DELETE);
final int pageSize = 100;
final int count = service.list(1, 1).getTotalCount();
for (int page = 1; page <= (count / pageSize) + 1; page++) {
for (UserTO user : service.list(page, pageSize, null, false).getResult()) {
bulkAction.getTargets().add(String.valueOf(user.getId()));
}
}
BulkActionResult bulkResult = service.bulk(bulkAction);
bulkResult.getResultMap(); |
Please note the false parameter in the call at line 12: this saves time as will not require Syncope to fetch virtual attributes' values from external resources.
Rather then deleting all users, a restricting search condition can be used by replacing line 10 with
final String fiql = SyncopeClient.getUserSearchConditionBuilder().is("id").lessThan(150).query();
final int count = service.search(fiql, 1, 1).getTotalCount(); |
and line 12 with
for (UserTO user : service.search(fiql, page, pageSize, null, false).getResult()) { |
When only relying on raw HTTP requests, the following steps are required:
GET /rest/users?page=X&size=Yid property for each reported userinvoke POST /rest/users/bulk with headers and payload like as follows:Accept: application/json, Content-Type: application/json
{
"operation":"DELETE",
"targets":[
"100", "101", "107"
]
} |
Rather then deleting all users, a restricting search condition can be used by replacing the first invocation above with GET /rest/users/search?fiql=id%3Dlt%3D150&page=X&size=Y
More information by consulting the REST API reference.