Using the search API

Crowd currently supports searching for users and groups using the Crowd REST API.

Searching users

It is possible to search for users using the following methods:

1
2
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchUsers
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchUsersWithAttributes
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchUserNames

This will perform a search on all the directories assigned to your application and return a list of users (depending on the method the output will be strings, User or UserWithAttributes objects) matching the search restrictions. Queries can be paged and filtered using the com.atlassian.crowd.embedded.api.SearchRestriction API. The full list of searchable properties can be found in the com.atlassian.crowd.search.query.entity.restriction.constants.UserTermKeys class.

Example

Suppose we would like to obtain a list of 20 active users from Crowd. This could be achieved by performing the following:

1
2
// obtain an instance of the RestCrowdClient
CrowdClient client = new RestCrowdClientFactory().newInstance(getBaseUrl(), APPLICATION_NAME, APPLICATION_PASSWORD);

// build search criteria
SearchRestriction restriction = Restriction.on(UserTermKeys.ACTIVE).exactlyMatching(true);

// execute search
List<User> users = client.searchUsers(restriction, 0, 20);

Searching Groups

You can search for groups in a similar manner to searching for users, by using the following methods:

1
2
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchGroups
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchGroupsWithAttributes
com.atlassian.crowd.integration.rest.service.RestCrowdClient#searchGroupNames

Just like with users, group queries can be paged and filtered using the com.atlassian.crowd.embedded.api.SearchRestriction API. The full list of searchable properties can be found in the com.atlassian.crowd.search.query.entity.restriction.constants.GroupTermKeys class.

Direct searches

It is possible to perform direct searches to determine if a user is a member of a group, to list the members of a group, to list the group memberships of a user, find a user by their name and much more using methods on the CrowdClient interface.

Rate this page: