Search in sources :

Example 36 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 {
        boolean runScript = externalUpdateUserService.isEnabled();
        if (runScript) {
            externalUpdateUserService.executeExternalAddUserMethods(this.person);
        }
        personService.addPerson(this.person);
        if (runScript) {
            externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
        }
    } catch (Exception ex) {
        log.error("Failed to add new person {}", this.person.getInum(), ex);
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) IOException(java.io.IOException)

Example 37 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;
    }
    if (!update) {
        if (!validatePerson(this.person)) {
            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);
    boolean runScript = externalUpdateUserService.isEnabled();
    if (update) {
        try {
            if (runScript) {
                externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
            }
            personService.updatePerson(this.person);
            if (runScript) {
                externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
            }
        } catch (BaseMappingException ex) {
            log.error("Failed to update person {}", inum, ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update person '#{updatePersonAction.person.displayName}'");
            return OxTrustConstants.RESULT_FAILURE;
        }
        facesMessages.add(FacesMessage.SEVERITY_INFO, "Person '#{updatePersonAction.person.displayName}' updated successfully");
    } else {
        if (personService.getPersonByUid(this.person.getUid()) != null) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Person with the uid '#{updatePersonAction.person.uid}' already exist'");
            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 (runScript) {
                externalUpdateUserService.executeExternalAddUserMethods(this.person);
            }
            personService.addPerson(this.person);
            if (runScript) {
                externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
            }
        } catch (Exception ex) {
            log.error("Failed to add new person {}", this.person.getInum(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person'");
            return OxTrustConstants.RESULT_FAILURE;
        }
        facesMessages.add(FacesMessage.SEVERITY_INFO, "New person '#{updatePersonAction.person.displayName}' added successfully");
        conversationService.endConversation();
        this.update = true;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) ArrayList(java.util.ArrayList) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 38 with GluuCustomAttribute

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

the class UserProfileAction method update.

public String update() {
    try {
        if (this.imapData != null) {
            List<GluuCustomAttribute> customAttributes = this.person.getCustomAttributes();
            for (GluuCustomAttribute gluuCustomAttribute : customAttributes) {
                if (gluuCustomAttribute.getName().equals("gluuIMAPData")) {
                    gluuCustomAttribute.setValue(imapDataService.getJsonStringFromImap(this.imapData));
                }
            }
        }
        GluuCustomPerson person = this.person;
        // TODO: Reffactor
        person.setGluuOptOuts(optOuts.size() == 0 ? null : optOuts);
        boolean runScript = externalUpdateUserService.isEnabled();
        if (runScript) {
            externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
        }
        personService.updatePerson(this.person);
        if (runScript) {
            externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
        }
    } catch (BaseMappingException ex) {
        log.error("Failed to update profile {}", person.getInum(), ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update profile '#{userProfileAction.person.displayName}'");
        return OxTrustConstants.RESULT_FAILURE;
    }
    customAttributeAction.savePhotos();
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Profile '#{userProfileAction.person.displayName}' updated successfully");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException)

Example 39 with GluuCustomAttribute

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

the class AttributeService method setAttributeMetadata.

/**
 * Set metadata for every custom attribute
 *
 * @param customAttributes
 *            List of custom attributes
 * @param attributes
 *            List of attributes
 */
public void setAttributeMetadata(List<GluuCustomAttribute> customAttributes, List<GluuAttribute> attributes) {
    if ((customAttributes == null) || (attributes == null)) {
        return;
    }
    for (GluuCustomAttribute personAttribute : customAttributes) {
        GluuAttribute tmpAttribute = getAttributeByName(personAttribute.getName(), attributes);
        if (tmpAttribute == null) {
            log.error("Failed to find attribute '{}' metadata", personAttribute.getName());
        }
        personAttribute.setMetadata(tmpAttribute);
    }
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.xdi.model.GluuAttribute)

Example 40 with GluuCustomAttribute

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

the class AttributeService method getCustomAttributesByAttributeDNs.

/**
 * Get custom attributes by attribute DNs
 *
 * @param customAttributes
 *            List of attribute DNs
 * @param attributes
 *            List of custom attributes
 */
public List<GluuCustomAttribute> getCustomAttributesByAttributeDNs(List<String> attributeDNs, HashMap<String, GluuAttribute> attributesByDNs) {
    List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
    if (attributeDNs == null) {
        return customAttributes;
    }
    for (String releasedAttributeDn : attributeDNs) {
        GluuAttribute attribute = attributesByDNs.get(releasedAttributeDn);
        if (attribute != null) {
            GluuCustomAttribute customAttribute = new GluuCustomAttribute(attribute.getName(), releasedAttributeDn);
            customAttribute.setMetadata(attribute);
            customAttributes.add(customAttribute);
        }
    }
    return customAttributes;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) GluuAttribute(org.xdi.model.GluuAttribute)

Aggregations

GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)44 ArrayList (java.util.ArrayList)19 GluuAttribute (org.xdi.model.GluuAttribute)15 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)14 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)5 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 HashSet (java.util.HashSet)4 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)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 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)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