Search in sources :

Example 26 with GluuCustomAttribute

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

the class WhitePagesAction method getPhotoThumbData.

public byte[] getPhotoThumbData(GluuCustomPerson person) {
    List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.USER);
    GluuAttribute photoAttribute = attributeService.getAttributeByName(PHOTO_NAME, attributes);
    GluuCustomAttribute customAttribute = new GluuCustomAttribute(PHOTO_NAME, person.getAttribute(PHOTO_NAME));
    customAttribute.setMetadata(photoAttribute);
    GluuImage image = imageService.getImage(customAttribute);
    if (image == null || (person.getGluuOptOuts() != null && person.getGluuOptOuts().contains(PHOTO_NAME))) {
        return imageService.getBlankPhotoData();
    }
    return imageService.getThumImageData(image);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuImage(org.xdi.model.GluuImage) GluuAttribute(org.xdi.model.GluuAttribute)

Example 27 with GluuCustomAttribute

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

the class CacheRefreshTimer method getRemovedPersons.

private List<GluuSimplePerson> getRemovedPersons(HashMap<String, Integer> currInumWithEntryHashCodeMap, Map<String, Integer> prevInumWithEntryHashCodeMap) {
    // First time run
    if (prevInumWithEntryHashCodeMap == null) {
        return new ArrayList<GluuSimplePerson>(0);
    }
    // Add all inums which not exist in new snapshot
    Set<String> deletedInums = new HashSet<String>();
    for (String prevInumKey : prevInumWithEntryHashCodeMap.keySet()) {
        if (!currInumWithEntryHashCodeMap.containsKey(prevInumKey)) {
            deletedInums.add(prevInumKey);
        }
    }
    List<GluuSimplePerson> deletedPersons = new ArrayList<GluuSimplePerson>(deletedInums.size());
    for (String deletedInum : deletedInums) {
        GluuSimplePerson person = new GluuSimplePerson();
        String personDn = personService.getDnForPerson(deletedInum);
        person.setDn(personDn);
        List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
        customAttributes.add(new GluuCustomAttribute(OxTrustConstants.inum, deletedInum));
        person.setCustomAttributes(customAttributes);
        deletedPersons.add(person);
    }
    return deletedPersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 28 with GluuCustomAttribute

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

the class ServiceUtil method syncEmailForward.

/**
	 * One-way sync from "oxTrustEmail" to "mail". Ultimately this is persisted so "mail" will be
	 * updated by values from "oxTrustEmail".
	 *
	 * @param gluuCustomPerson
	 * @return
	 * @throws Exception
	 */
public static GluuCustomPerson syncEmailForward(GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception {
    logger.info(" IN Utils.syncEmailForward()...");
    GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
    if (oxTrustEmail != null && oxTrustEmail.getValues().length > 0) {
        // JSON array in element 0
        String[] oxTrustEmails = oxTrustEmail.getValues();
        String[] newMails = new String[oxTrustEmails.length];
        ObjectMapper mapper = getObjectMapper();
        if (isScim2) {
            for (int i = 0; i < oxTrustEmails.length; i++) {
                Email email = mapper.readValue(oxTrustEmails[i], Email.class);
                newMails[i] = email.getValue();
            }
        } else {
            for (int i = 0; i < oxTrustEmails.length; i++) {
                ScimPersonEmails email = mapper.readValue(oxTrustEmails[i], ScimPersonEmails.class);
                newMails[i] = email.getValue();
            }
        }
        gluuCustomPerson.setAttribute("mail", newMails);
    /* // Just do nothing if null, same as in UserWebService.updateUser()
		} else {
			gluuCustomPerson.setAttribute("mail", new String[0]);
		*/
    }
    logger.info(" LEAVING Utils.syncEmailForward()...");
    return gluuCustomPerson;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) Email(org.gluu.oxtrust.model.scim2.Email) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 29 with GluuCustomAttribute

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

the class UpdatePersonAction method save.

/**
	 * Saves person to ldap
	 * 
	 * @return String describing success of the operation
	 */
public String save() throws Exception {
    if (!organizationService.isAllowPersonModification()) {
        return OxTrustConstants.RESULT_FAILURE;
    }
    updateCustomObjectClasses();
    List<GluuCustomAttribute> removedAttributes = customAttributeAction.detectRemovedAttributes();
    customAttributeAction.updateOriginCustomAttributes();
    List<GluuCustomAttribute> customAttributes = customAttributeAction.getCustomAttributes();
    for (GluuCustomAttribute customAttribute : customAttributes) {
        if (customAttribute.getName().equalsIgnoreCase("gluuStatus")) {
            customAttribute.setValue(gluuStatus.getValue());
        }
    }
    this.person.setCustomAttributes(customAttributeAction.getCustomAttributes());
    this.person.getCustomAttributes().addAll(removedAttributes);
    // Sync email, in reverse ("oxTrustEmail" <- "mail")
    this.person = ServiceUtil.syncEmailReverse(this.person, true);
    if (update) {
        try {
            if (externalUpdateUserService.isEnabled()) {
                externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
            }
            personService.updatePerson(this.person);
        } catch (LdapMappingException ex) {
            log.error("Failed to update person {}", ex, inum);
            return OxTrustConstants.RESULT_FAILURE;
        }
    } else {
        if (personService.getPersonByUid(this.person.getUid()) != null) {
            return OxTrustConstants.RESULT_DUPLICATE;
        }
        this.inum = personService.generateInumForNewPerson();
        String iname = personService.generateInameForNewPerson(this.person.getUid());
        String dn = personService.getDnForPerson(this.inum);
        // Save person
        this.person.setDn(dn);
        this.person.setInum(this.inum);
        this.person.setIname(iname);
        this.person.setUserPassword(this.password);
        List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
        if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
            List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
            changedAttributes.addAll(personAttributes);
            changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
            this.person.setCustomAttributes(changedAttributes);
        } else {
            this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
        }
        try {
            if (externalUpdateUserService.isEnabled()) {
                externalUpdateUserService.executeExternalAddUserMethods(this.person);
            }
            personService.addPerson(this.person);
        } catch (Exception ex) {
            log.error("Failed to add new person {}", ex, this.person.getInum());
            return OxTrustConstants.RESULT_FAILURE;
        }
        this.update = true;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ArrayList(java.util.ArrayList) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException)

Example 30 with GluuCustomAttribute

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

the class PersonImportAction method save.

public String save() {
    if (!organizationService.isAllowPersonModification()) {
        return OxTrustConstants.RESULT_FAILURE;
    }
    personService.addCustomObjectClass(this.person);
    if (personService.getPersonByUid(this.person.getUid()) != null) {
        return OxTrustConstants.RESULT_DUPLICATE;
    }
    this.inum = personService.generateInumForNewPerson();
    String iname = personService.generateInameForNewPerson(this.person.getUid());
    String dn = personService.getDnForPerson(this.inum);
    // Save person
    this.person.setDn(dn);
    this.person.setInum(this.inum);
    this.person.setIname(iname);
    List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
    if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
        List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
        changedAttributes.addAll(personAttributes);
        changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
        this.person.setCustomAttributes(changedAttributes);
    } else {
        this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
    }
    try {
        if (externalUpdateUserService.isEnabled()) {
            externalUpdateUserService.executeExternalAddUserMethods(this.person);
        }
        personService.addPerson(this.person);
    } catch (Exception ex) {
        log.error("Failed to add new person {}", ex, this.person.getInum());
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) IOException(java.io.IOException)

Aggregations

GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)42 ArrayList (java.util.ArrayList)19 GluuAttribute (org.xdi.model.GluuAttribute)15 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)12 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)5 HashSet (java.util.HashSet)4 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)4 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)4 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)4 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)4 ScimName (org.gluu.oxtrust.model.scim.ScimName)4 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)4 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)4 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)4 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)4 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)4 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)4 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)4 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)4 IOException (java.io.IOException)3