Search in sources :

Example 36 with GluuCustomPerson

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

the class Scim2UserService method deleteUser.

public void deleteUser(String id) throws Exception {
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    if (gluuPerson == null) {
        throw new EntryPersistenceException("Scim2UserService.deleteUser(): " + "Resource " + id + " not found");
    } else {
        // For custom script: delete user
        if (externalScimService.isEnabled()) {
            externalScimService.executeScimDeleteUserMethods(gluuPerson);
        }
        log.info("person.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
        if (gluuPerson.getMemberOf() != null) {
            if (gluuPerson.getMemberOf().size() > 0) {
                String dn = personService.getDnForPerson(id);
                log.info("DN : " + dn);
                serviceUtil.deleteUserFromGroup(gluuPerson, dn);
            }
        }
        memberService.removePerson(gluuPerson);
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 37 with GluuCustomPerson

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

the class Scim2UserService method replaceUserPatch.

private void replaceUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.replacePatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: replaceUserPatch update user ");
    setMeta(updatedGluuPerson);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser)

Example 38 with GluuCustomPerson

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

the class Scim2UserService method patchUser.

public User patchUser(String id, ScimPatchUser patchUser) throws Exception {
    for (Operation operation : patchUser.getOperatons()) {
        String val = operation.getOperationName();
        if (val.equalsIgnoreCase("replace")) {
            replaceUserPatch(operation, id);
        }
        if (val.equalsIgnoreCase("remove")) {
            removeUserPatch(operation, id);
        }
        if (val.equalsIgnoreCase("add")) {
            addUserPatch(operation, id);
        }
    }
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    User updatedUser = copyUtils2.copy(gluuPerson, null);
    return updatedUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) Operation(org.gluu.oxtrust.model.scim2.Operation)

Example 39 with GluuCustomPerson

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

the class Scim2UserService method updateUser.

public User updateUser(String id, User user) throws Exception {
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    if (gluuPerson == null) {
        throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update userName of a different id
        if (user.getUserName() != null) {
            GluuCustomPerson personToFind = new GluuCustomPerson();
            personToFind.setUid(user.getUserName());
            List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
            if (foundPersons != null && foundPersons.size() > 0) {
                for (GluuCustomPerson foundPerson : foundPersons) {
                    if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
                        throw new DuplicateEntryException("Cannot update userName of a different id: " + user.getUserName());
                    }
                }
            }
        }
    }
    GluuCustomPerson updatedGluuPerson = copyUtils2.copy(user, gluuPerson, true);
    if (user.getGroups().size() > 0) {
        serviceUtil.groupMembersAdder(updatedGluuPerson, personService.getDnForPerson(id));
    }
    log.info(" Setting meta: update user ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuPerson.getAttribute("oxTrustMetaLocation") == null || (updatedGluuPerson.getAttribute("oxTrustMetaLocation") != null && updatedGluuPerson.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Users/" + id;
        updatedGluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // Sync email, forward ("oxTrustEmail" -> "mail")
    updatedGluuPerson = serviceUtil.syncEmailForward(updatedGluuPerson, true);
    // For custom script: update user
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateUserMethods(updatedGluuPerson);
    }
    personService.updatePerson(updatedGluuPerson);
    log.debug(" person updated ");
    User updatedUser = copyUtils2.copy(updatedGluuPerson, null);
    return updatedUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 40 with GluuCustomPerson

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

the class ServiceUtil method personMembersAdder.

/**
 * Adds a group to a person's memberOf
 *
 * @return void
 * @throws Exception
 */
public void personMembersAdder(GluuGroup gluuGroup, String dn) throws Exception {
    List<String> members = gluuGroup.getMembers();
    for (String member : members) {
        GluuCustomPerson gluuPerson = personService.getPersonByDn(member);
        List<String> groups = gluuPerson.getMemberOf();
        if (!isMemberOfExist(groups, dn)) {
            List<String> cleanGroups = new ArrayList<String>();
            cleanGroups.add(dn);
            for (String aGroup : groups) {
                cleanGroups.add(aGroup);
            }
            gluuPerson.setMemberOf(cleanGroups);
            personService.updatePerson(gluuPerson);
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)114 ArrayList (java.util.ArrayList)37 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 Test (org.testng.annotations.Test)21 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)17 Response (javax.ws.rs.core.Response)17 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)14 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)14 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)14 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)14 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)14 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)14 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)13 ScimEntitlements (org.gluu.oxtrust.model.scim.ScimEntitlements)13 ScimName (org.gluu.oxtrust.model.scim.ScimName)13 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)13 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)13 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)12