Search in sources :

Example 36 with Group

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

the class ResourceTypeWS method getResourceTypeGroup.

@Path("Group")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeGroup(@HeaderParam("Authorization") String authorization) throws Exception {
    ResourceType groupResourceType = new ResourceType();
    groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
    groupResourceType.setEndpoint("/v2/Groups");
    groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
    Meta groupMeta = new Meta();
    groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    groupMeta.setResourceType("ResourceType");
    groupResourceType.setMeta(groupMeta);
    // ResourceType[] resourceTypes = new ResourceType[]{groupResourceType};
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(groupResourceType).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with Group

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

the class Scim2GroupService method updateGroup.

public Group updateGroup(String id, Group group) throws Exception {
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    if (gluuGroup == null) {
        throw new EntryPersistenceException("Scim2GroupService.updateGroup(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update displayName of a different id
        if (gluuGroup.getDisplayName() != null) {
            GluuGroup groupToFind = new GluuGroup();
            groupToFind.setDisplayName(group.getDisplayName());
            List<GluuGroup> foundGroups = groupService.findGroups(groupToFind, 2);
            if (foundGroups != null && foundGroups.size() > 0) {
                for (GluuGroup foundGroup : foundGroups) {
                    if (foundGroup != null && !foundGroup.getInum().equalsIgnoreCase(gluuGroup.getInum())) {
                        throw new DuplicateEntryException("Cannot update displayName of a different id: " + group.getDisplayName());
                    }
                }
            }
        }
    }
    GluuGroup updatedGluuGroup = copyUtils2.copy(group, gluuGroup, true);
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(updatedGluuGroup, groupService.getDnForGroup(id));
    }
    log.info(" Setting meta: update group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuGroup.getAttribute("oxTrustMetaLocation") == null || (updatedGluuGroup.getAttribute("oxTrustMetaLocation") != null && updatedGluuGroup.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Groups/" + id;
        updatedGluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // For custom script: update group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateGroupMethods(updatedGluuGroup);
    }
    groupService.updateGroup(updatedGluuGroup);
    log.debug(" group updated ");
    Group updatedGroup = copyUtils2.copy(updatedGluuGroup, null);
    return updatedGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 38 with Group

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

the class Scim2GroupService method createGroup.

public Group createGroup(Group group) throws Exception {
    log.debug(" copying gluuGroup ");
    GluuGroup gluuGroup = copyUtils2.copy(group, null, false);
    if (gluuGroup == null) {
        throw new Exception("Scim2GroupService.createGroup(): Failed to create group; GluuGroup is null");
    }
    log.debug(" generating inum ");
    String inum = groupService.generateInumForNewGroup();
    log.debug(" getting DN ");
    String dn = groupService.getDnForGroup(inum);
    log.debug(" getting iname ");
    String iname = groupService.generateInameForNewGroup(group.getDisplayName().replaceAll(" ", ""));
    log.debug(" setting dn ");
    gluuGroup.setDn(dn);
    log.debug(" setting inum ");
    gluuGroup.setInum(inum);
    log.debug(" setting iname ");
    gluuGroup.setIname(iname);
    log.info("group.getMembers().size() : " + group.getMembers().size());
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(gluuGroup, dn);
    }
    // As per spec, the SP must be the one to assign the meta attributes
    log.info(" Setting meta: create group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateCreated = DateTime.now().toDate();
    String relativeLocation = "/scim/v2/Groups/" + inum;
    gluuGroup.setAttribute("oxTrustMetaCreated", dateTimeFormatter.print(dateCreated.getTime()));
    gluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateCreated.getTime()));
    gluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    // For custom script: create group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimCreateGroupMethods(gluuGroup);
    }
    log.debug("adding new GluuGroup");
    groupService.addGroup(gluuGroup);
    Group createdGroup = copyUtils2.copy(gluuGroup, null);
    return createdGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)12 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)12 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)10 DefaultValue (javax.ws.rs.DefaultValue)9 HeaderParam (javax.ws.rs.HeaderParam)9 Produces (javax.ws.rs.Produces)9 GluuGroup (org.gluu.oxtrust.model.GluuGroup)9 Group (org.gluu.oxtrust.model.scim2.Group)9 URI (java.net.URI)8 Group (org.openstack4j.model.identity.v3.Group)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 Response (javax.ws.rs.core.Response)7 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)7 Group (com.google.monitoring.v3.Group)5 Path (javax.ws.rs.Path)5 Test (org.junit.Test)5 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)5 IOException (java.io.IOException)4 Map (java.util.Map)4 GET (javax.ws.rs.GET)4