Search in sources :

Example 6 with ListViewResponse

use of org.gluu.persist.model.ListViewResponse in project oxTrust by GluuFederation.

the class Scim2UserService method searchUsers.

public ListViewResponse<BaseScimResource> searchUsers(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url, int maxCount) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", UserResource.class);
    log.info("Executing search for users using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuCustomPerson> list = ldapEntryManager.findListViewResponse(personService.getDnForPerson(null), GluuCustomPerson.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuCustomPerson person : list.getResult()) {
        UserResource scimUsr = new UserResource();
        transferAttributesToUserResource(person, scimUsr, url);
        resources.add(scimUsr);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
    ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
    result.setResult(resources);
    result.setTotalResults(list.getTotalResults());
    return result;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Filter(org.gluu.search.filter.Filter) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Example 7 with ListViewResponse

use of org.gluu.persist.model.ListViewResponse in project oxTrust by GluuFederation.

the class UserWebService method searchUsers.

@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@QueryParam(QUERY_PARAM_FILTER) String filter, @QueryParam(QUERY_PARAM_START_INDEX) Integer startIndex, @QueryParam(QUERY_PARAM_COUNT) Integer count, @QueryParam(QUERY_PARAM_SORT_BY) String sortBy, @QueryParam(QUERY_PARAM_SORT_ORDER) String sortOrder, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. searchUsers");
        sortBy = translateSortByAttribute(UserResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = scim2UserService.searchUsers(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, getMaxCount());
        String json = getListResponseSerialized(resources.getTotalResults(), startIndex, resources.getResult(), attrsList, excludedAttrsList, count == 0);
        response = Response.ok(json).location(new URI(endpointUrl)).build();
    } catch (SCIMException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at searchUsers method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

ListViewResponse (org.gluu.persist.model.ListViewResponse)7 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)6 Filter (org.gluu.search.filter.Filter)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 DefaultValue (javax.ws.rs.DefaultValue)3 GET (javax.ws.rs.GET)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)3 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)3 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)3 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)3 FidoDeviceResource (org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource)2 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)2 UserResource (org.gluu.oxtrust.model.scim2.user.UserResource)2 SearchResult (com.unboundid.ldap.sdk.SearchResult)1