Search in sources :

Example 11 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.

the class Scim2GroupService method transferAttributesToGroupResource.

public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, boolean fillMembersDisplay, String groupsUrl, String usersUrl) {
    res.setId(gluuGroup.getInum());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(gluuGroup.getAttribute("jansMetaCreated"));
    meta.setLastModified(gluuGroup.getAttribute("jansMetaLastMod"));
    meta.setLocation(gluuGroup.getAttribute("jansMetaLocation"));
    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<>();
        for (String dn : memberDNs) {
            GluuCustomPerson person = null;
            if (fillMembersDisplay) {
                try {
                    person = personService.getPersonByDn(dn);
                } catch (Exception e) {
                    log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
                }
            }
            if (person == null) {
                person = new GluuCustomPerson();
                person.setInum(userPersistenceHelper.getUserInumFromDN(dn));
            }
            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(io.jans.scim.model.scim2.Meta) GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) UserResource(io.jans.scim.model.scim2.user.UserResource) Member(io.jans.scim.model.scim2.group.Member) WebApplicationException(javax.ws.rs.WebApplicationException) HashSet(java.util.HashSet)

Example 12 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.

the class Scim2GroupService method searchGroups.

public PagedResult<BaseScimResource> searchGroups(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String groupsUrl, String usersUrl, int maxCount, boolean fillMembersDisplay) throws Exception {
    Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("inum"), GroupResource.class);
    log.info("Executing search for groups using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    PagedResult<GluuGroup> list = ldapEntryManager.findPagedEntries(groupService.getDnForGroup(null), GluuGroup.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, maxCount);
    List<BaseScimResource> resources = new ArrayList<>();
    if (externalScimService.isEnabled() && !externalScimService.executeScimPostSearchGroupsMethods(list)) {
        throw new WebApplicationException("Failed to execute SCIM script successfully", Status.PRECONDITION_FAILED);
    }
    for (GluuGroup group : list.getEntries()) {
        GroupResource scimGroup = new GroupResource();
        transferAttributesToGroupResource(group, scimGroup, fillMembersDisplay, groupsUrl, usersUrl);
        resources.add(scimGroup);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
    PagedResult<BaseScimResource> result = new PagedResult<>();
    result.setEntries(resources);
    result.setTotalEntriesCount(list.getTotalEntriesCount());
    return result;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Filter(io.jans.orm.search.filter.Filter) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) GluuGroup(io.jans.scim.model.GluuGroup) GroupResource(io.jans.scim.model.scim2.group.GroupResource) PagedResult(io.jans.orm.model.PagedResult)

Example 13 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.

the class GroupAssignUserTest method assignToGroup.

@Test(dependsOnMethods = "createUsers")
public void assignToGroup() {
    Set<Member> buddies = friends.stream().map(buddy -> {
        Member m = new Member();
        m.setValue(buddy.getId());
        m.setDisplay(buddy.getDisplayName());
        return m;
    }).collect(Collectors.toSet());
    GroupResource gr = new GroupResource();
    gr.setDisplayName("3 best demented buddies");
    gr.setMembers(buddies);
    logger.info("Assigning users to new group...");
    Response response = client.createGroup(gr, null, null);
    assertEquals(response.getStatus(), CREATED.getStatusCode());
    group = response.readEntity(GroupResource.class);
    // Verify the sanitarium is completely booked
    assertTrue(group.getMembers().stream().map(Member::getValue).collect(Collectors.toSet()).equals(friends.stream().map(UserResource::getId).collect(Collectors.toSet())));
}
Also used : Member(io.jans.scim.model.scim2.group.Member) UserBaseTest(io.jans.scim2.client.UserBaseTest) java.util(java.util) UserResource(io.jans.scim.model.scim2.user.UserResource) Test(org.testng.annotations.Test) Collectors(java.util.stream.Collectors) GroupResource(io.jans.scim.model.scim2.group.GroupResource) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) SearchRequest(io.jans.scim.model.scim2.SearchRequest) Group(io.jans.scim.model.scim2.user.Group) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) ListResponse(io.jans.scim.model.scim2.ListResponse) Status(javax.ws.rs.core.Response.Status) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) Member(io.jans.scim.model.scim2.group.Member) GroupResource(io.jans.scim.model.scim2.group.GroupResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 14 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.

the class MinimalGroupTest method updateGroup.

@Parameters("group_minimal_update")
@Test(dependsOnMethods = "createGroup")
public void updateGroup(String json) {
    logger.debug("Updating group {} with json", group.getDisplayName());
    Response response = client.updateGroup(json, group.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    GroupResource updated = response.readEntity(groupClass);
    assertNotEquals(group.getDisplayName(), updated.getDisplayName());
    // Impl. ignores externalId for groups
    assertNull(updated.getExternalId());
    logger.debug("Updated group {}", updated.getDisplayName());
}
Also used : Response(javax.ws.rs.core.Response) GroupResource(io.jans.scim.model.scim2.group.GroupResource) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 15 with GroupResource

use of io.jans.scim.model.scim2.group.GroupResource in project oxTrust by GluuFederation.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<Response, String>(response, idCreated);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Aggregations

GroupResource (io.jans.scim.model.scim2.group.GroupResource)13 Response (javax.ws.rs.core.Response)13 URI (java.net.URI)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)6 GluuGroup (io.jans.scim.model.GluuGroup)5 Member (io.jans.scim.model.scim2.group.Member)5 UserResource (io.jans.scim.model.scim2.user.UserResource)5 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)4 ArrayList (java.util.ArrayList)4 Consumes (javax.ws.rs.Consumes)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 ListViewResponse (org.gluu.persist.model.ListViewResponse)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)3