Search in sources :

Example 1 with GroupResource

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

the class GroupWebService method updateGroup.

/**
 * This implementation differs from spec in the following aspects:
 * - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
 * empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
 * operation should be used
 */
@Path("{id}")
@PUT
@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 = "Update group", notes = "Update group (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = GroupResource.class)
public Response updateGroup(@ApiParam(value = "Group", required = true) GroupResource group, @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. updateGroup");
        GroupResource updatedResource = scim2GroupService.updateGroup(id, group, endpointUrl, userWebService.getEndpointUrl());
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateGroup 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) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 2 with GroupResource

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

the class GroupWebService method patchGroup.

@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 = GroupResource.class)
public Response patchGroup(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. patchGroup");
        String usersUrl = userWebService.getEndpointUrl();
        GroupResource group = new GroupResource();
        // group is not null (check associated decorator method)
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        // Fill group instance with all info from gluuGroup
        scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, endpointUrl, usersUrl);
        // Apply patches one by one in sequence
        for (PatchOperation po : request.getOperations()) group = (GroupResource) scim2PatchService.applyPatchOperation(group, po);
        // Throws exception if final representation does not pass overall validation
        log.debug("patchGroup. Revising final resource representation still passes validations");
        executeDefaultValidation(group);
        // Update timestamp
        String now = ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis());
        group.getMeta().setLastModified(now);
        // Replaces the information found in gluuGroup with the contents of group
        scim2GroupService.replaceGroupInfo(gluuGroup, group, endpointUrl, usersUrl);
        String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
        response = Response.ok(new URI(group.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 patchGroup 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) PatchOperation(org.gluu.oxtrust.model.scim2.patch.PatchOperation) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 3 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource 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 4 with GroupResource

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

the class Scim2GroupService method updateGroup.

public GroupResource updateGroup(String id, GroupResource group, String groupsUrl, String usersUrl) throws Exception {
    // This is never null (see decorator involved)
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    GroupResource tmpGroup = new GroupResource();
    transferAttributesToGroupResource(gluuGroup, tmpGroup, groupsUrl, usersUrl);
    long now = System.currentTimeMillis();
    tmpGroup.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
    tmpGroup = (GroupResource) ScimResourceUtil.transferToResourceReplace(group, tmpGroup, extService.getResourceExtensions(group.getClass()));
    replaceGroupInfo(gluuGroup, tmpGroup, groupsUrl, usersUrl);
    return tmpGroup;
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource)

Example 5 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
        else if (ws == fido2DeviceWS)
            switch(verb) {
                case PUT:
                    Fido2DeviceResource dev = mapper.readValue(data, Fido2DeviceResource.class);
                    response = fido2DeviceWS.updateF2Device(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fido2DeviceWS.deleteF2Device(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fido2DeviceWS.patchF2Device(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fido2DeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<>(response, idCreated);
}
Also used : BulkResponse(io.jans.scim.model.scim2.bulk.BulkResponse) Response(javax.ws.rs.core.Response) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) GroupResource(io.jans.scim.model.scim2.group.GroupResource) Pair(io.jans.util.Pair)

Aggregations

GroupResource (io.jans.scim.model.scim2.group.GroupResource)13 Response (javax.ws.rs.core.Response)13 URI (java.net.URI)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)6 GluuGroup (io.jans.scim.model.GluuGroup)5 Member (io.jans.scim.model.scim2.group.Member)5 UserResource (io.jans.scim.model.scim2.user.UserResource)5 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)4 ArrayList (java.util.ArrayList)4 Consumes (javax.ws.rs.Consumes)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 ListViewResponse (org.gluu.persist.model.ListViewResponse)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)3