Search in sources :

Example 11 with RefAdjusted

use of org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted in project oxTrust by GluuFederation.

the class GroupWebService method getGroupById.

@Path("{id}")
@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 = "Find group by id", notes = "Returns a group by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.2.1)", response = GroupResource.class)
public Response getGroupById(@PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getGroupById");
        GroupResource group = new GroupResource();
        // gluuGroup is not null (check associated decorator method)
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, endpointUrl, userWebService.getEndpointUrl());
        String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
        response = Response.ok(new URI(group.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getGroupById 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) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) 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 12 with RefAdjusted

use of org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted in project oxTrust by GluuFederation.

the class SearchResourcesWebService method search.

@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "General search POST /.search", notes = "Returns a list of resources (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response search(@ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) {
    SearchRequest searchReq = new SearchRequest();
    Response response = prepareSearchRequest(searchRequest.getSchemas(), searchRequest.getFilter(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), searchReq);
    if (response == null) {
        try {
            List<JsonNode> resources = new ArrayList<JsonNode>();
            Pair<Integer, Integer> totals = computeResults(searchReq, resources);
            ListResponseJsonSerializer custSerializer = new ListResponseJsonSerializer(resourceSerializer, searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 0);
            if (resources.size() > 0)
                custSerializer.setJsonResources(resources);
            ObjectMapper objmapper = new ObjectMapper();
            SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
            module.addSerializer(ListResponse.class, custSerializer);
            objmapper.registerModule(module);
            // Provide to constructor original start index, and totals calculated in computeResults call
            ListResponse listResponse = new ListResponse(searchReq.getStartIndex(), totals.getFirst(), totals.getSecond());
            String json = objmapper.writeValueAsString(listResponse);
            response = Response.ok(json).location(new URI(endpointUrl)).build();
        } catch (Exception e) {
            log.error("Failure at search method", e);
            response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
        }
    }
    return response;
}
Also used : SearchRequest(org.gluu.oxtrust.model.scim2.SearchRequest) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) ListResponseJsonSerializer(org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer) URI(java.net.URI) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 13 with RefAdjusted

use of org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted in project oxTrust by GluuFederation.

the class UserWebService method getUserById.

@Path("{id}")
@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 = "Find user by id", notes = "Returns a user by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = UserResource.class)
public Response getUserById(@PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getUserById");
        UserResource user = new UserResource();
        // person is not null (check associated decorator method)
        GluuCustomPerson person = personService.getPersonByInum(id);
        scim2UserService.transferAttributesToUserResource(person, user, endpointUrl);
        String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
        response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getUserById 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) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) 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 14 with RefAdjusted

use of org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted in project oxTrust by GluuFederation.

the class UserWebService method patchUser.

@Path("{id}")
@PATCH
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "PATCH operation", notes = "https://tools.ietf.org/html/rfc7644#section-3.5.2", response = UserResource.class)
public Response patchUser(PatchRequest request, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. patchUser");
        UserResource user = new UserResource();
        // person is not null (check associated decorator method)
        GluuCustomPerson person = personService.getPersonByInum(id);
        // Fill user instance with all info from person
        scim2UserService.transferAttributesToUserResource(person, user, endpointUrl);
        // Apply patches one by one in sequence
        for (PatchOperation po : request.getOperations()) {
            // Handle special case: https://github.com/GluuFederation/oxTrust/issues/800
            if (po.getType().equals(REMOVE) && po.getPath().equals("pairwiseIdentitifers")) {
                // If this block weren't here, the implementation will throw error because read-only attribute cannot be altered
                // Note the path is intentionally mistyped, see class member in UserResource
                person.setOxPPID(null);
                user.setPairwiseIdentitifers(null);
                scim2UserService.removePPIDsBranch(person.getDn());
            } else
                user = (UserResource) scim2PatchService.applyPatchOperation(user, po);
        }
        // Throws exception if final representation does not pass overall validation
        log.debug("patchUser. Revising final resource representation still passes validations");
        executeDefaultValidation(user);
        ScimResourceUtil.adjustPrimarySubAttributes(user);
        // Update timestamp
        String now = ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis());
        user.getMeta().setLastModified(now);
        // Replaces the information found in person with the contents of user
        scim2UserService.replacePersonInfo(person, user, endpointUrl);
        String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
        response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (SCIMException e) {
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at patchUser 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) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchOperation(org.gluu.oxtrust.model.scim2.patch.PatchOperation) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 15 with RefAdjusted

use of org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted 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

ApiOperation (com.wordnik.swagger.annotations.ApiOperation)17 URI (java.net.URI)17 Response (javax.ws.rs.core.Response)17 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)17 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 DefaultValue (javax.ws.rs.DefaultValue)16 HeaderParam (javax.ws.rs.HeaderParam)16 Produces (javax.ws.rs.Produces)16 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)16 ListViewResponse (org.gluu.persist.model.ListViewResponse)16 Path (javax.ws.rs.Path)11 Consumes (javax.ws.rs.Consumes)10 GET (javax.ws.rs.GET)6 POST (javax.ws.rs.POST)5 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)4 UserResource (org.gluu.oxtrust.model.scim2.user.UserResource)4 PUT (javax.ws.rs.PUT)3 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)3