Search in sources :

Example 46 with GluuCustomPerson

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

the class PersonService method findPersonsByUids.

/* (non-Javadoc)
     * @see org.gluu.oxtrust.ldap.service.IPersonService#findPersonsByUids(java.util.List, java.lang.String[])
     */
@Override
public List<GluuCustomPerson> findPersonsByUids(List<String> uids, String[] returnAttributes) throws Exception {
    List<Filter> uidFilters = new ArrayList<Filter>();
    for (String uid : uids) {
        uidFilters.add(Filter.createEqualityFilter(OxConstants.UID, uid));
    }
    Filter filter = Filter.createORFilter(uidFilters);
    List<GluuCustomPerson> result = ldapEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, filter, returnAttributes);
    return result;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList)

Example 47 with GluuCustomPerson

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

the class CacheRefreshTimer method validateTargetServerSchema.

private boolean validateTargetServerSchema(CacheRefreshConfiguration cacheRefreshConfiguration, Map<String, String> targetServerAttributesMapping, String[] customObjectClasses) {
    // Get list of return attributes
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    GluuSimplePerson sourcePerson = new GluuSimplePerson();
    for (String returnAttribute : returnAttributes) {
        sourcePerson.setAttribute(returnAttribute, "Test");
    }
    String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
    String targetPersonDn = personService.getDnForPerson(targetInum);
    GluuCustomPerson targetPerson = new GluuCustomPerson();
    targetPerson.setDn(targetPersonDn);
    targetPerson.setInum(targetInum);
    targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
    targetPerson.setCustomObjectClasses(customObjectClasses);
    // Update list of return attributes according mapping
    cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
    // Execute interceptor script
    externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
    if (!executionResult) {
        log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
        return false;
    }
    // Validate target server attributes
    List<GluuCustomAttribute> customAttributes = targetPerson.getCustomAttributes();
    List<String> targetAttributes = new ArrayList<String>(customAttributes.size());
    for (GluuCustomAttribute customAttribute : customAttributes) {
        targetAttributes.add(customAttribute.getName());
    }
    List<String> targetObjectClasses = Arrays.asList(ldapEntryManager.getObjectClasses(targetPerson, GluuCustomPerson.class));
    return validateTargetServerSchema(targetObjectClasses, targetAttributes);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList)

Example 48 with GluuCustomPerson

use of org.gluu.oxtrust.model.GluuCustomPerson 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 '{}'", targetInum, ex);
            return false;
        }
        updatePerson = true;
    } else {
        targetPerson = new GluuCustomPerson();
        targetPerson.setDn(targetPersonDn);
        targetPerson.setInum(targetInum);
        targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
        updatePerson = false;
    }
    targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
    targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
    targetPerson.setSourceServerUserDn(sourcePerson.getDn());
    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 '{}'", updatePerson ? "update" : "add", targetInum, ex);
        return false;
    }
    return true;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) SearchException(org.gluu.persist.exception.operation.SearchException) SocketException(java.net.SocketException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException)

Example 49 with GluuCustomPerson

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

the class PersonService method getPersonByAttribute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IPersonService#getPersonByAttribute(java.lang.
	 * String, java.lang.String)
	 */
@Override
public GluuCustomPerson getPersonByAttribute(String attribute, String value) throws Exception {
    GluuCustomPerson person = new GluuCustomPerson();
    person.setBaseDn(getDnForPerson(null));
    person.setAttribute(attribute, value);
    List<GluuCustomPerson> persons = persistenceEntryManager.findEntries(person);
    if ((persons != null) && (persons.size() > 0)) {
        return persons.get(0);
    }
    return null;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson)

Example 50 with GluuCustomPerson

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

the class PersonService method addPerson.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IPersonService#addPerson(org.gluu.oxtrust.model
	 * .GluuCustomPerson)
	 */
// TODO: Review this methods. We need to check if uid is unique in outside
// method
@Override
public void addPerson(GluuCustomPerson person) throws Exception {
    try {
        List<GluuCustomPerson> persons = getPersonsByUid(person.getUid());
        if (persons == null || persons.size() == 0) {
            person.setCreationDate(new Date());
            persistenceEntryManager.persist(person);
        } else {
            throw new DuplicateEntryException("Duplicate UID value: " + person.getUid());
        }
    } catch (Exception e) {
        if (e.getCause().getMessage().contains("unique attribute conflict was detected for attribute mail")) {
            throw new DuplicateEmailException("Email Already Registered");
        } else {
            throw new Exception("Duplicate UID value: " + person.getUid());
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) Date(java.util.Date) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)133 ArrayList (java.util.ArrayList)42 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)27 Test (org.testng.annotations.Test)22 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)18 Produces (javax.ws.rs.Produces)17 Response (javax.ws.rs.core.Response)17 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 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)12