Search in sources :

Example 1 with GluuCustomPerson

use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.

the class BaseScimWebService method validateExistenceOfUser.

public Response validateExistenceOfUser(String id) {
    Response response = null;
    if (StringUtils.isNotEmpty(id)) {
        GluuCustomPerson person = personService.getPersonByInum(id);
        if (person == null) {
            log.info("Person with inum {} not found", id);
            response = getErrorResponse(Response.Status.NOT_FOUND, "User with id " + id + " not found");
        }
    }
    return response;
}
Also used : ErrorResponse(io.jans.scim.model.scim2.ErrorResponse) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) GluuCustomPerson(io.jans.scim.model.GluuCustomPerson)

Example 2 with GluuCustomPerson

use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.

the class Scim2GroupService method transferAttributesToGroup.

private void transferAttributesToGroup(GroupResource res, GluuGroup group, boolean skipMembersValidation, boolean fillMembersDisplay, String usersUrl) {
    // externalId (so jansExtId) not part of LDAP schema
    group.setAttribute("jansMetaCreated", res.getMeta().getCreated());
    group.setAttribute("jansMetaLastMod", res.getMeta().getLastModified());
    // When creating group, location will be set again when having an inum
    group.setAttribute("jansMetaLocation", res.getMeta().getLocation());
    group.setDisplayName(res.getDisplayName());
    group.setStatus(GluuStatus.ACTIVE);
    group.setOrganization(organizationService.getDnForOrganization());
    Set<Member> members = res.getMembers();
    if (members != null && members.size() > 0) {
        Set<String> groupMembers = group.getMembers().stream().map(userPersistenceHelper::getUserInumFromDN).collect(Collectors.toCollection(HashSet::new));
        List<String> listMembers = new ArrayList<>();
        List<Member> invalidMembers = new ArrayList<>();
        // Add the members, and complement the $refs and users' display names in res
        for (Member member : members) {
            GluuCustomPerson person;
            // it's not null as it is required in GroupResource
            String inum = member.getValue();
            // we make database lookups
            if (!skipMembersValidation && !groupMembers.contains(inum)) {
                person = personService.getPersonByInum(inum);
                if (person != null && fillMembersDisplay) {
                    member.setDisplay(person.getDisplayName());
                }
            } else {
                person = new GluuCustomPerson();
                person.setDn(personService.getDnForPerson(inum));
            }
            if (person == null) {
                log.info("Member identified by {} does not exist. Ignored", inum);
                invalidMembers.add(member);
            } else {
                member.setRef(usersUrl + "/" + inum);
                member.setType(ScimResourceUtil.getType(UserResource.class));
                if (skipMembersValidation) {
                    // In overhead bypass mode, display names must not be returned
                    member.setDisplay(null);
                }
                listMembers.add(person.getDn());
            }
        }
        group.setMembers(listMembers);
        members.removeAll(invalidMembers);
        if (members.isEmpty()) {
            res.setMembers(null);
        }
    } else {
        group.setMembers(new ArrayList<>());
    }
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) ArrayList(java.util.ArrayList) UserResource(io.jans.scim.model.scim2.user.UserResource) Member(io.jans.scim.model.scim2.group.Member)

Example 3 with GluuCustomPerson

use of io.jans.scim.model.GluuCustomPerson 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 4 with GluuCustomPerson

use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.

the class Scim2GroupService method syncMemberAttributeInPerson.

private void syncMemberAttributeInPerson(String groupDn, Set<String> before, Set<String> after) {
    log.debug("syncMemberAttributeInPerson. Updating memberOf attribute in user LDAP entries");
    log.trace("Before member dns {}; After member dns {}", before, after);
    // Do removals
    for (String dn : before) {
        if (!after.contains(dn)) {
            try {
                GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
                List<String> memberOf = new ArrayList<>();
                memberOf.addAll(gluuPerson.getMemberOf());
                memberOf.remove(groupDn);
                gluuPerson.setMemberOf(memberOf);
                personService.updatePerson(gluuPerson);
            } catch (Exception e) {
                log.error("An error occurred while removing group {} from user {}", groupDn, dn);
                log.error(e.getMessage(), e);
            }
        }
    }
    // Do insertions
    for (String dn : after) {
        if (!before.contains(dn)) {
            try {
                GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
                List<String> memberOf = new ArrayList<>();
                memberOf.add(groupDn);
                if (gluuPerson.getMemberOf() != null)
                    memberOf.addAll(gluuPerson.getMemberOf());
                gluuPerson.setMemberOf(memberOf);
                personService.updatePerson(gluuPerson);
            } catch (Exception e) {
                log.error("An error occurred while adding group {} to user {}", groupDn, dn);
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) ArrayList(java.util.ArrayList) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 5 with GluuCustomPerson

use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.

the class PersonService method searchPersons.

public List<GluuCustomPerson> searchPersons(String pattern, int sizeLimit, List<GluuCustomPerson> excludedPersons) throws Exception {
    Filter orFilter = buildFilter(pattern);
    Filter searchFilter = orFilter;
    if (excludedPersons != null && excludedPersons.size() > 0) {
        List<Filter> excludeFilters = new ArrayList<Filter>();
        for (GluuCustomPerson excludedPerson : excludedPersons) {
            Filter eqFilter = Filter.createEqualityFilter(OxConstants.UID, excludedPerson.getUid());
            excludeFilters.add(eqFilter);
        }
        Filter orExcludeFilter = null;
        if (excludedPersons.size() == 1) {
            orExcludeFilter = excludeFilters.get(0);
        } else {
            orExcludeFilter = Filter.createORFilter(excludeFilters);
        }
        Filter notFilter = Filter.createNOTFilter(orExcludeFilter);
        searchFilter = Filter.createANDFilter(orFilter, notFilter);
    }
    return persistenceEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, searchFilter, sizeLimit);
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList)

Aggregations

GluuCustomPerson (io.jans.scim.model.GluuCustomPerson)16 ArrayList (java.util.ArrayList)6 Filter (io.jans.orm.search.filter.Filter)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 Member (io.jans.scim.model.scim2.group.Member)2 UserResource (io.jans.scim.model.scim2.user.UserResource)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 GluuAttribute (io.jans.model.GluuAttribute)1 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)1 DuplicateEmailException (io.jans.scim.exception.DuplicateEmailException)1 ErrorResponse (io.jans.scim.model.scim2.ErrorResponse)1 ListResponse (io.jans.scim.model.scim2.ListResponse)1 Meta (io.jans.scim.model.scim2.Meta)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Response (javax.ws.rs.core.Response)1