use of org.xdi.ldap.model.VirtualListViewResponse in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching groups from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuGroup> groupList = groupService.getAllGroupsList();
ListResponse groupsListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
groupsListResponse.setSchemas(schema);
// Set total
groupsListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && groupList != null && !groupList.isEmpty()) {
for (GluuGroup gluuGroup : groupList) {
Group group = copyUtils2.copy(gluuGroup, null);
log.info(" group to be added displayName : " + group.getDisplayName());
groupsListResponse.getResources().add(group);
log.info(" group added? : " + groupsListResponse.getResources().contains(group));
}
// Set the rest of results info
groupsListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
groupsListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(groupsListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups");
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchGroups", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
Aggregations