Search in sources :

Example 1 with GroupResource

use of org.gluu.oxtrust.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 org.gluu.oxtrust.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 org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.

the class Scim2GroupService method transferAttributesToGroupResource.

public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, String groupsUrl, String usersUrl) {
    res.setId(gluuGroup.getInum());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(gluuGroup.getAttribute("oxTrustMetaCreated"));
    meta.setLastModified(gluuGroup.getAttribute("oxTrustMetaLastModified"));
    meta.setLocation(gluuGroup.getAttribute("oxTrustMetaLocation"));
    if (meta.getLocation() == null)
        meta.setLocation(groupsUrl + "/" + gluuGroup.getInum());
    res.setMeta(meta);
    res.setDisplayName(gluuGroup.getDisplayName());
    // Transfer members from GluuGroup to GroupResource
    List<String> memberDNs = gluuGroup.getMembers();
    if (memberDNs != null) {
        Set<Member> members = new HashSet<Member>();
        for (String dn : memberDNs) {
            GluuCustomPerson person = null;
            try {
                person = personService.getPersonByDn(dn);
            } catch (Exception e) {
                log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
            }
            if (person != null) {
                Member aMember = new Member();
                aMember.setValue(person.getInum());
                aMember.setRef(usersUrl + "/" + person.getInum());
                aMember.setType(ScimResourceUtil.getType(UserResource.class));
                aMember.setDisplay(person.getDisplayName());
                members.add(aMember);
            }
        }
        res.setMembers(members);
    }
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) Member(org.gluu.oxtrust.model.scim2.group.Member) WebApplicationException(javax.ws.rs.WebApplicationException) HashSet(java.util.HashSet)

Example 4 with GroupResource

use of org.gluu.oxtrust.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 5 with GroupResource

use of org.gluu.oxtrust.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)

Aggregations

GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)6 Response (javax.ws.rs.core.Response)5 ListViewResponse (org.gluu.persist.model.ListViewResponse)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 URI (java.net.URI)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 DefaultValue (javax.ws.rs.DefaultValue)4 HeaderParam (javax.ws.rs.HeaderParam)4 Produces (javax.ws.rs.Produces)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)4 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)4 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)4 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)4 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 UserResource (org.gluu.oxtrust.model.scim2.user.UserResource)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2