Search in sources :

Example 36 with GluuGroup

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

the class Scim2UserService method transferAttributesToUserResource.

public void transferAttributesToUserResource(GluuCustomPerson person, UserResource res, String url) {
    log.debug("transferAttributesToUserResource");
    res.setId(person.getInum());
    res.setExternalId(person.getAttribute("oxTrustExternalId"));
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(person.getAttribute("oxTrustMetaCreated"));
    if (meta.getCreated() == null) {
        Date tmpDate = person.getCreationDate();
        meta.setCreated(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
    }
    meta.setLastModified(person.getAttribute("oxTrustMetaLastModified"));
    if (meta.getLastModified() == null) {
        Date tmpDate = person.getUpdatedAt();
        meta.setLastModified(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
    }
    meta.setLocation(person.getAttribute("oxTrustMetaLocation"));
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + person.getInum());
    res.setMeta(meta);
    // Set values in order of appearance in UserResource class
    res.setUserName(person.getUid());
    Name name = new Name();
    name.setGivenName(person.getGivenName());
    name.setFamilyName(person.getSurname());
    name.setMiddleName(person.getAttribute("middleName"));
    name.setHonorificPrefix(person.getAttribute("oxTrusthonorificPrefix"));
    name.setHonorificSuffix(person.getAttribute("oxTrusthonorificSuffix"));
    String formatted = person.getAttribute("oxTrustNameFormatted");
    if (// recomputes the formatted name if absent in LDAP
    formatted == null)
        name.computeFormattedName();
    else
        name.setFormatted(formatted);
    res.setName(name);
    res.setDisplayName(person.getDisplayName());
    res.setNickName(person.getAttribute("nickname"));
    res.setProfileUrl(person.getAttribute("oxTrustProfileURL"));
    res.setTitle(person.getAttribute("oxTrustTitle"));
    res.setUserType(person.getAttribute("oxTrustUserType"));
    res.setPreferredLanguage(person.getPreferredLanguage());
    res.setLocale(person.getAttribute("locale"));
    res.setTimezone(person.getTimezone());
    res.setActive(Boolean.valueOf(person.getAttribute("oxTrustActive")) || GluuBoolean.getByValue(person.getAttribute("gluuStatus")).isBooleanValue());
    res.setPassword(person.getUserPassword());
    res.setEmails(getAttributeListValue(person, Email.class, "oxTrustEmail"));
    res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "oxTrustPhoneValue"));
    res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "oxTrustImsValue"));
    res.setPhotos(getAttributeListValue(person, Photo.class, "oxTrustPhotos"));
    res.setAddresses(getAttributeListValue(person, Address.class, "oxTrustAddresses"));
    List<String> listOfGroups = person.getMemberOf();
    if (listOfGroups != null && listOfGroups.size() > 0) {
        List<Group> groupList = new ArrayList<Group>();
        for (String groupDN : listOfGroups) {
            try {
                GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
                Group group = new Group();
                group.setValue(gluuGroup.getInum());
                String reference = groupWS.getEndpointUrl() + "/" + gluuGroup.getInum();
                group.setRef(reference);
                group.setDisplay(gluuGroup.getDisplayName());
                // Only support direct membership: see section 4.1.2 of RFC 7644
                group.setType(Group.Type.DIRECT);
                groupList.add(group);
            } catch (Exception e) {
                log.warn("transferAttributesToUserResource. Group with dn {} could not be added to User Resource. {}", groupDN, person.getUid());
                log.error(e.getMessage(), e);
            }
        }
        if (groupList.size() > 0)
            res.setGroups(groupList);
    }
    res.setEntitlements(getAttributeListValue(person, Entitlement.class, "oxTrustEntitlements"));
    res.setRoles(getAttributeListValue(person, Role.class, "oxTrustRole"));
    res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "oxTrustx509Certificate"));
    res.setPairwiseIdentitifers(person.getOxPPID());
    transferExtendedAttributesToResource(person, res);
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.user.Group) Email(org.gluu.oxtrust.model.scim2.user.Email) Address(org.gluu.oxtrust.model.scim2.user.Address) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.user.Photo) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Date(java.util.Date) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) WebApplicationException(javax.ws.rs.WebApplicationException) X509Certificate(org.gluu.oxtrust.model.scim2.user.X509Certificate) Name(org.gluu.oxtrust.model.scim2.user.Name) Role(org.gluu.oxtrust.model.scim2.user.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.user.PhoneNumber) Entitlement(org.gluu.oxtrust.model.scim2.user.Entitlement) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress)

Example 37 with GluuGroup

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

the class GroupWebServiceDecorator method validateExistenceOfGroup.

private Response validateExistenceOfGroup(String id) {
    Response response = null;
    GluuGroup group = StringUtils.isEmpty(id) ? null : groupService.getGroupByInum(id);
    if (group == null) {
        log.info("Group with inum {} not found", id);
        response = getErrorResponse(Response.Status.NOT_FOUND, "Resource " + id + " not found");
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 38 with GluuGroup

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

the class GroupWebServiceDecorator method checkDisplayNameExistence.

private void checkDisplayNameExistence(String displayName, String id) throws DuplicateEntryException {
    // Validate if there is an attempt to supply a displayName already in use by a group other than current
    GluuGroup groupToFind = new GluuGroup();
    groupToFind.setDisplayName(displayName);
    List<GluuGroup> list = groupService.findGroups(groupToFind, 2);
    if (list != null) {
        for (GluuGroup g : list) if (!g.getInum().equals(id))
            throw new DuplicateEntryException("Duplicate group displayName value: " + displayName);
    }
}
Also used : DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 39 with GluuGroup

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

the class ServiceUtil method groupMembersAdder.

/**
 * Adds a person to a group
 *
 * @return void
 * @throws Exception
 */
public void groupMembersAdder(GluuCustomPerson gluuPerson, String dn) throws Exception {
    List<String> groups = gluuPerson.getMemberOf();
    for (String group : groups) {
        GluuGroup oneGroup = groupService.getGroupByDn(group);
        List<String> groupMembers = oneGroup.getMembers();
        if ((groupMembers != null && !groupMembers.isEmpty()) && !isMemberExist(groupMembers, dn)) {
            List<String> cleanGroupMembers = new ArrayList<String>();
            cleanGroupMembers.add(dn);
            for (String personDN : groupMembers) {
                cleanGroupMembers.add(personDN);
            }
            oneGroup.setMembers(cleanGroupMembers);
            groupService.updateGroup(oneGroup);
        }
    }
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 40 with GluuGroup

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

the class GroupWebService method deleteGroup.

@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@ApiOperation(value = "Delete group", notes = "Delete group (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteGroup(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteGroup");
        // group cannot be null (check associated decorator method)
        GluuGroup gr = groupService.getGroupByInum(id);
        scim2GroupService.deleteGroup(gr);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteGroup 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) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) 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