Search in sources :

Example 11 with GluuGroup

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

the class GroupWebService method getGroupById.

@Path("{id}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getGroupById(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        if (gluuGroup == null) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
        }
        ScimGroup group = copyUtils.copy(gluuGroup, null);
        URI location = new URI("/Groups/" + id);
        return Response.ok(group).location(location).build();
    } catch (EntryPersistenceException ex) {
        ex.printStackTrace();
        return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
    } catch (Exception ex) {
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with GluuGroup

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

the class MemberService method removePerson.

public void removePerson(GluuCustomPerson person) {
    // TODO: Do we realy need to remove group if owner is removed?
    List<GluuGroup> groups = groupService.getAllGroups();
    for (GluuGroup group : groups) {
        if (StringHelper.equalsIgnoreCase(group.getOwner(), person.getDn())) {
            groupService.removeGroup(group);
        }
    }
    // Remove person
    personService.removePerson(person);
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 13 with GluuGroup

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

the class GroupService method countGroups.

/* (non-Javadoc)
	 * @see org.gluu.oxtrust.ldap.service.IGroupService#countGroups()
	 */
@Override
public int countGroups() {
    GluuGroup gluuGroup = new GluuGroup();
    gluuGroup.setBaseDn(getDnForGroup(null));
    return ldapEntryManager.countEntries(gluuGroup);
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 14 with GluuGroup

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

the class ServiceUtil method deleteUserFromGroup.

/**
 * Delete a person from a group
 *
 * @return void
 * @throws Exception
 */
public void deleteUserFromGroup(GluuCustomPerson person, String dn) throws Exception {
    List<String> groups = person.getMemberOf();
    for (String oneGroup : groups) {
        GluuGroup aGroup = groupService.getGroupByDn(oneGroup);
        List<String> groupMembers = aGroup.getMembers();
        List<String> tempGroupMembers = new ArrayList<String>();
        if (groupMembers != null && !groupMembers.isEmpty()) {
            for (String aMember : groupMembers) {
                tempGroupMembers.add(aMember);
            }
        }
        for (String oneMember : tempGroupMembers) {
            if (oneMember.equalsIgnoreCase(dn)) {
                tempGroupMembers.remove(oneMember);
                break;
            }
        }
        List<String> cleanGroupMembers = new ArrayList<String>();
        for (String aMember : tempGroupMembers) {
            cleanGroupMembers.add(aMember);
        }
        aGroup.setMembers(cleanGroupMembers);
        if (aGroup.getMembers() != null && aGroup.getMembers().isEmpty()) {
            // Reset to no members
            aGroup.setMembers(null);
        }
        groupService.updateGroup(aGroup);
    }
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 15 with GluuGroup

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

Aggregations

GluuGroup (org.gluu.oxtrust.model.GluuGroup)42 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)13 Produces (javax.ws.rs.Produces)11 Response (javax.ws.rs.core.Response)11 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)11 ArrayList (java.util.ArrayList)10 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)6 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)6 DefaultValue (javax.ws.rs.DefaultValue)5 GET (javax.ws.rs.GET)5 HeaderParam (javax.ws.rs.HeaderParam)5 Group (org.gluu.oxtrust.model.scim2.Group)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Consumes (javax.ws.rs.Consumes)4 ListViewResponse (org.gluu.persist.model.ListViewResponse)4 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3