Search in sources :

Example 26 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class CacheRefreshTimer method updateTargetEntryViaCopy.

private boolean updateTargetEntryViaCopy(GluuSimplePerson sourcePerson, String targetInum, String[] targetCustomObjectClasses, Map<String, String> targetServerAttributesMapping) {
    String targetPersonDn = personService.getDnForPerson(targetInum);
    GluuCustomPerson targetPerson = null;
    boolean updatePerson;
    if (personService.contains(targetPersonDn)) {
        try {
            targetPerson = personService.findPersonByDn(targetPersonDn);
            log.debug("Found person by inum '{}'", targetInum);
        } catch (EntryPersistenceException ex) {
            log.error("Failed to find person '{}'", ex, targetInum);
            return false;
        }
        updatePerson = true;
    } else {
        targetPerson = new GluuCustomPerson();
        targetPerson.setDn(targetPersonDn);
        targetPerson.setInum(targetInum);
        targetPerson.setStatus(GluuStatus.ACTIVE);
        updatePerson = false;
    }
    targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
    targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
    cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
    // Execute interceptor script
    boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    if (!executionResult) {
        log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
        return false;
    }
    try {
        if (updatePerson) {
            personService.updatePerson(targetPerson);
            log.debug("Updated person '{}'", targetInum);
        } else {
            personService.addPerson(targetPerson);
            log.debug("Added new person '{}'", targetInum);
        }
    } catch (Exception ex) {
        log.error("Failed to '{}' person '{}'", ex, updatePerson ? "update" : "add", targetInum);
        return false;
    }
    return true;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) SocketException(java.net.SocketException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 27 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class ImportPersonConfiguration method prepareAttributes.

private List<GluuAttribute> prepareAttributes() throws Exception {
    List<GluuAttribute> result = new ArrayList<GluuAttribute>();
    List<ImportPerson> mappings = configurationFactory.getImportPersonConfig().getMappings();
    Iterator<ImportPerson> it = mappings.iterator();
    while (it.hasNext()) {
        ImportPerson importPerson = (ImportPerson) it.next();
        String attributeName = importPerson.getLdapName();
        boolean required = importPerson.getRequired();
        if (StringHelper.isNotEmpty(attributeName)) {
            GluuAttribute attr = null;
            try {
                attr = attributeService.getAttributeByName(attributeName);
            } catch (EntryPersistenceException ex) {
                log.error("Failed to load attribute '{}' definition from LDAP", ex, attributeName);
            }
            if (attr == null) {
                log.warn("Failed to find attribute '{}' definition in LDAP", attributeName);
                attr = createAttributeFromConfig(importPerson);
                if (attr == null) {
                    log.error("Failed to find attribute '{}' definition in '{}'", attributeName, GLUU_IMPORT_PERSON_PROPERTIES_FILE);
                    continue;
                }
            } else {
                attr.setRequred(required);
            }
            result.add(attr);
        }
    //}
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ImportPerson(org.xdi.config.oxtrust.ImportPerson) GluuAttribute(org.xdi.model.GluuAttribute)

Example 28 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.

the class Scim2UserService method validUsernameByInum.

private GluuCustomPerson validUsernameByInum(User user, String id) throws DuplicateEntryException {
    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());
                    }
                }
            }
        }
    }
    return gluuPerson;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 29 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException 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 30 with EntryPersistenceException

use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException 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)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)63 Response (javax.ws.rs.core.Response)24 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)24 Path (javax.ws.rs.Path)23 Produces (javax.ws.rs.Produces)23 URI (java.net.URI)19 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)19 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)16 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)13 DefaultValue (javax.ws.rs.DefaultValue)13 HeaderParam (javax.ws.rs.HeaderParam)13 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)13 GluuGroup (org.gluu.oxtrust.model.GluuGroup)12 EmptyEntryPersistenceException (org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException)11 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)10 GET (javax.ws.rs.GET)9 MappingException (org.gluu.site.ldap.persistence.exception.MappingException)9 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)8 ParseException (java.text.ParseException)8 ConnectionException (org.gluu.site.ldap.exception.ConnectionException)8