Search in sources :

Example 1 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevices.

private ListViewResponse<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "oxId=*", FidoDeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuCustomFidoDevice> list = ldapEntryManager.findListViewResponse(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, startIndex, count, getMaxCount(), sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuCustomFidoDevice device : list.getResult()) {
        FidoDeviceResource scimDev = new FidoDeviceResource();
        transferAttributesToFidoResource(device, scimDev, url, getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    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 : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) Filter(org.gluu.search.filter.Filter) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList)

Example 2 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevices.

@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 devices", notes = "Returns a list of devices", response = ListResponse.class)
public Response searchDevices(@QueryParam("userId") String userId, @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. searchDevices");
        sortBy = translateSortByAttribute(FidoDeviceResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = searchDevices(userId, filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl);
        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 searchDevices 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) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) 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)

Example 3 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class GroupWebService method searchGroups.

@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 groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@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. searchGroups");
        sortBy = translateSortByAttribute(GroupResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = scim2GroupService.searchGroups(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, userWebService.getEndpointUrl(), 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 searchGroups 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) URI(java.net.URI) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) 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)

Example 4 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class Scim2GroupService method searchGroups.

public ListViewResponse<BaseScimResource> searchGroups(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String groupsUrl, String usersUrl, int maxCount) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", GroupResource.class);
    log.info("Executing search for groups using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuGroup> list = ldapEntryManager.findListViewResponse(groupService.getDnForGroup(null), GluuGroup.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuGroup group : list.getResult()) {
        GroupResource scimGroup = new GroupResource();
        transferAttributesToGroupResource(group, scimGroup, groupsUrl, usersUrl);
        // TODO: Delete this IF in the future - added for backwards compatibility with SCIM-Client <= 3.1.2.
        if (scimGroup.getMembers() == null)
            scimGroup.setMembers(new HashSet<Member>());
        resources.add(scimGroup);
    }
    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 : Filter(org.gluu.search.filter.Filter) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) HashSet(java.util.HashSet)

Example 5 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class ListResponseJsonSerializer method serialize.

@Override
public void serialize(ListResponse listResponse, JsonGenerator jGen, SerializerProvider provider) throws IOException {
    try {
        jGen.writeStartObject();
        jGen.writeArrayFieldStart("schemas");
        for (String schema : listResponse.getSchemas()) jGen.writeString(schema);
        jGen.writeEndArray();
        jGen.writeNumberField("totalResults", listResponse.getTotalResults());
        if (!skipResults) {
            if (listResponse.getItemsPerPage() > 0) {
                // these two bits are "REQUIRED when partial results are returned due to pagination." (section 3.4.2 RFC 7644)
                jGen.writeNumberField("startIndex", listResponse.getStartIndex());
                jGen.writeNumberField("itemsPerPage", listResponse.getItemsPerPage());
            }
            // Section 3.4.2 RFC 7644: Resources [...] REQUIRED if "totalResults" is non-zero
            if (listResponse.getTotalResults() > 0) {
                jGen.writeArrayFieldStart("Resources");
                if (listResponse.getResources().size() > 0)
                    for (BaseScimResource resource : listResponse.getResources()) {
                        JsonNode jsonResource = mapper.readTree(resourceSerializer.serialize(resource, attributes, excludeAttributes));
                        jGen.writeTree(jsonResource);
                    }
                else if (jsonResources != null)
                    for (JsonNode node : jsonResources) jGen.writeTree(node);
                jGen.writeEndArray();
            }
        }
        jGen.writeEndObject();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)12 Extension (io.jans.scim.model.scim2.extensions.Extension)12 ArrayList (java.util.ArrayList)12 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)12 Response (javax.ws.rs.core.Response)11 SCIMException (io.jans.scim.model.exception.SCIMException)10 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 URI (java.net.URI)8 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)7 ListResponse (io.jans.scim.model.scim2.ListResponse)6 URISyntaxException (java.net.URISyntaxException)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 SearchRequest (io.jans.scim.model.scim2.SearchRequest)5 UserResource (io.jans.scim.model.scim2.user.UserResource)5 PagedResult (io.jans.orm.model.PagedResult)4 Filter (io.jans.orm.search.filter.Filter)4 Attribute (io.jans.scim.model.scim2.annotations.Attribute)4 DefaultValue (javax.ws.rs.DefaultValue)4 GET (javax.ws.rs.GET)4 HeaderParam (javax.ws.rs.HeaderParam)4