Search in sources :

Example 26 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class SchemaWebService method getSchemaById.

@GET
@Path("{schemaUrn}")
@Produces(MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT)
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@RejectFilterParam
public Response getSchemaById(@PathParam("schemaUrn") String urn) {
    Response response;
    try {
        Class<? extends BaseScimResource> cls = resourceSchemas.get(urn);
        if (cls == null) {
            log.info("Schema urn {} not recognized", urn);
            response = Response.status(Response.Status.NOT_FOUND).build();
        } else {
            String json = resourceSerializer.serialize(getSchemaInstance(cls, urn));
            URI location = new URI(endpointUrl + "/" + urn);
            response = Response.ok(json).location(location).build();
        }
    } catch (Exception e) {
        log.error("Failure at getSchemaById 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) URI(java.net.URI) RejectFilterParam(org.gluu.oxtrust.service.scim2.interceptor.RejectFilterParam)

Example 27 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource 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

Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)12 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)6 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 Response (javax.ws.rs.core.Response)5 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)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 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)3 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)3