Search in sources :

Example 41 with Group

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

the class GroupWebService method searchGroups.

@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
        } else {
            log.info(" Searching groups from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuGroup> groupList = groupService.getAllGroupsList();
            ListResponse groupsListResponse = new ListResponse();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
            log.info(" setting schema");
            groupsListResponse.setSchemas(schema);
            // Set total
            groupsListResponse.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && groupList != null && !groupList.isEmpty()) {
                for (GluuGroup gluuGroup : groupList) {
                    Group group = copyUtils2.copy(gluuGroup, null);
                    log.info(" group to be added displayName : " + group.getDisplayName());
                    groupsListResponse.getResources().add(group);
                    log.info(" group added? : " + groupsListResponse.getResources().contains(group));
                }
                // Set the rest of results info
                groupsListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
                groupsListResponse.setStartIndex(vlvResponse.getStartIndex());
            }
            // Serialize to JSON
            String json = serializeToJson(groupsListResponse, attributesArray);
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups");
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchGroups", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) 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) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 42 with Group

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

the class GroupWebService method createGroup.

@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Create group", notes = "Create group (https://tools.ietf.org/html/rfc7644#section-3.3)", response = Group.class)
public Response createGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "Group", required = true) Group group, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        Group createdGroup = scim2GroupService.createGroup(group);
        // Serialize to JSON
        String json = serializeToJson(createdGroup, attributesArray);
        URI location = new URI(createdGroup.getMeta().getLocation());
        // Return HTTP response with status code 201 Created
        return Response.created(location).entity(json).build();
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to create group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 43 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 44 with Group

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

the class Scim2GroupService method transferAttributesToGroup.

private void transferAttributesToGroup(GroupResource res, GluuGroup group, String usersUrl) {
    // externalId (so oxTrustExternalId) not part of LDAP schema
    group.setAttribute("oxTrustMetaCreated", res.getMeta().getCreated());
    group.setAttribute("oxTrustMetaLastModified", res.getMeta().getLastModified());
    // When creating group, location will be set again when having an inum
    group.setAttribute("oxTrustMetaLocation", res.getMeta().getLocation());
    group.setDisplayName(res.getDisplayName());
    group.setStatus(GluuStatus.ACTIVE);
    group.setOrganization(organizationService.getDnForOrganization());
    // Add the members, and complement the $refs and users' display names in res
    Set<Member> members = res.getMembers();
    if (members != null && members.size() > 0) {
        List<String> listMembers = new ArrayList<String>();
        for (Member member : members) {
            // it's not null as it is required in GroupResource
            String inum = member.getValue();
            GluuCustomPerson person = personService.getPersonByInum(inum);
            if (person == null)
                log.info("Member identified by {} does not exist. Ignored", inum);
            else {
                member.setDisplay(person.getDisplayName());
                member.setRef(usersUrl + "/" + inum);
                member.setType(ScimResourceUtil.getType(UserResource.class));
                listMembers.add(person.getDn());
            }
        }
        group.setMembers(listMembers);
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) Member(org.gluu.oxtrust.model.scim2.group.Member)

Example 45 with Group

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

Aggregations

ArrayList (java.util.ArrayList)15 GluuGroup (org.gluu.oxtrust.model.GluuGroup)14 DefaultValue (javax.ws.rs.DefaultValue)13 HeaderParam (javax.ws.rs.HeaderParam)13 Produces (javax.ws.rs.Produces)13 Response (javax.ws.rs.core.Response)13 URI (java.net.URI)12 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)12 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)11 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)10 Path (javax.ws.rs.Path)8 Group (org.gluu.oxtrust.model.scim2.Group)8 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)8 Group (org.openstack4j.model.identity.v3.Group)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Consumes (javax.ws.rs.Consumes)7 ListViewResponse (org.gluu.persist.model.ListViewResponse)7 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)6 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)6 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)6