Version warning
Content of this page applies to Apache Syncope >= 1.2.0
Syncope Client Library
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()) {
Raw HTTP requests
When only relying on raw HTTP requests, the following steps are required:
- invoke
GET /rest/users?page=X&size=Y
where X and Y are respectively page number and page size; for each invocation take note ofid
property for each reported user invoke
POST /rest/users/bulk
with headers
and payload like as follows:Accept: application/json
, Content-Type: application/json{ "operation":"DELETE", "targets":[ "100", "101", "107" ] }
More information on the REST API reference.