Search in sources :

Example 16 with GluuCustomAttribute

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

the class CustomAttributeAction method removeMultiValuesInAttributes.

public void removeMultiValuesInAttributes(String inum, boolean mandatory, String removeValue) {
    if (StringHelper.isEmpty(inum)) {
        return;
    }
    GluuAttribute tmpAttribute = this.attributeInums.get(inum);
    if (tmpAttribute == null) {
        return;
    }
    String id = this.attributeIds.get(tmpAttribute);
    this.availableAttributeIds.remove(id);
    String[] values = null;
    String[] newValues = null;
    int index = 0;
    for (GluuCustomAttribute customAttribute : this.customAttributes) {
        if (tmpAttribute.equals(customAttribute.getMetadata())) {
            values = customAttribute.getValues();
            newValues = removeElementFromArray(values, removeValue);
            break;
        }
        index++;
    }
    removeCustomAttribute(inum);
    GluuCustomAttribute tmpGluuPersonAttribute = new GluuCustomAttribute(tmpAttribute.getName(), newValues, true, mandatory);
    tmpGluuPersonAttribute.setMetadata(tmpAttribute);
    this.customAttributes.add(index, tmpGluuPersonAttribute);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.xdi.model.GluuAttribute)

Example 17 with GluuCustomAttribute

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

the class PasswordResetAction method updateImpl.

public String updateImpl() throws ParseException {
    boolean valid = true;
    if (recaptchaService.isEnabled()) {
        valid = recaptchaService.verifyRecaptchaResponse();
    }
    if (valid) {
        GluuAppliance appliance = applianceService.getAppliance();
        this.request = ldapEntryManager.find(PasswordResetRequest.class, "oxGuid=" + this.guid + ", ou=resetPasswordRequests," + appliance.getDn());
        Calendar requestCalendarExpiry = Calendar.getInstance();
        Calendar currentCalendar = Calendar.getInstance();
        if (request != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
            requestCalendarExpiry.setTime((request.getCreationDate()));
            requestCalendarExpiry.add(Calendar.HOUR, 2);
        }
        GluuCustomPerson person = personService.getPersonByInum(request.getPersonInum());
        GluuCustomAttribute question = null;
        GluuCustomAttribute answer = null;
        if (person != null) {
            question = person.getGluuCustomAttribute("secretQuestion");
            answer = person.getGluuCustomAttribute("secretAnswer");
        }
        if (request != null && requestCalendarExpiry.after(currentCalendar)) /*&& question != null && answer != null*/
        {
            PasswordResetRequest removeRequest = new PasswordResetRequest();
            removeRequest.setBaseDn(request.getBaseDn());
            ldapEntryManager.remove(removeRequest);
            if (question != null && answer != null) {
                String correctAnswer = answer.getValue();
                Boolean securityQuestionAnswered = (securityAnswer != null) && securityAnswer.equals(correctAnswer);
                if (securityQuestionAnswered) {
                    person.setUserPassword(password);
                    personService.updatePerson(person);
                    return OxTrustConstants.RESULT_SUCCESS;
                }
            } else {
                person.setUserPassword(password);
                personService.updatePerson(person);
                return OxTrustConstants.RESULT_SUCCESS;
            }
        }
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with GluuCustomAttribute

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

the class RegisterPersonAction method registerImpl.

public String registerImpl() throws CloneNotSupportedException {
    boolean registrationFormValid = StringHelper.equals(password, repeatPassword);
    if (!captchaDisabled) {
        boolean reCaptchaResponse = recaptchaService.verifyRecaptchaResponse();
        registrationFormValid &= reCaptchaResponse;
    }
    if (registrationFormValid) {
        GluuCustomPerson archivedPerson = (GluuCustomPerson) person.clone();
        String customObjectClass = attributeService.getCustomOrigin();
        this.person.setCustomObjectClasses(new String[] { customObjectClass });
        // Save person
        if (person.getInum() == null) {
            String inum = personService.generateInumForNewPerson();
            this.person.setInum(inum);
        }
        if (person.getIname() == null) {
            String iname = personService.generateInameForNewPerson(this.person.getUid());
            this.person.setIname(iname);
        }
        if (person.getDn() == null) {
            String dn = personService.getDnForPerson(this.person.getInum());
            this.person.setDn(dn);
        }
        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.getSurname()));
            this.person.setCustomAttributes(changedAttributes);
        } else {
            this.person.setCommonName(this.person.getCommonName());
        }
        // save password
        this.person.setUserPassword(password);
        this.person.setCreationDate(new Date());
        this.person.setMail(email);
        try {
            // Set default message
            this.postRegistrationInformation = "You have successfully registered with oxTrust. Login to begin your session.";
            boolean result = false;
            result = externalUserRegistrationService.executeExternalPreRegistrationMethods(this.person, requestParameters);
            if (!result) {
                this.person = archivedPerson;
                return OxTrustConstants.RESULT_FAILURE;
            }
            if ((this.inum != null) && !this.inum.isEmpty()) {
                personService.updatePerson(this.person);
            } else {
                personService.addPerson(this.person);
            }
            result = externalUserRegistrationService.executeExternalPostRegistrationMethods(this.person, requestParameters);
            if (!result) {
                this.person = archivedPerson;
                return OxTrustConstants.RESULT_FAILURE;
            }
            if (GluuStatus.INACTIVE.equals(person.getStatus())) {
                return OxTrustConstants.RESULT_DISABLED;
            }
        } catch (Exception ex) {
            log.error("Failed to add new person {}", this.person.getInum(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person");
            this.person = archivedPerson;
            return OxTrustConstants.RESULT_FAILURE;
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_CAPTCHA_VALIDATION_FAILED;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) Date(java.util.Date) ValidatorException(javax.faces.validator.ValidatorException)

Example 19 with GluuCustomAttribute

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

the class Shibboleth3ConfService method initAttributeParamMap.

private HashMap<String, Object> initAttributeParamMap(List<GluuSAMLTrustRelationship> trustRelationships) {
    HashMap<String, Object> attrParams = new HashMap<String, Object>();
    // Collect attributes
    List<GluuAttribute> attributes = new ArrayList<GluuAttribute>();
    List<String> attributeNames = new ArrayList<String>();
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        for (GluuCustomAttribute customAttribute : trustRelationship.getReleasedCustomAttributes()) {
            GluuAttribute metadata = customAttribute.getMetadata();
            if (!attributes.contains(metadata)) {
                attributes.add(metadata);
                String attributeName = metadata.getName();
                attributeNames.add(attributeName);
            }
        }
    }
    SchemaEntry schemaEntry = shemaService.getSchema();
    List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    Map<String, String> attributeSAML1Strings = new HashMap<String, String>();
    Map<String, String> attributeSAML2Strings = new HashMap<String, String>();
    for (GluuAttribute metadata : attributes) {
        String attributeName = metadata.getName();
        AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
        if (attributeTypeDefinition == null) {
            log.error("Failed to get OID for attribute name {}", attributeName);
            return null;
        }
        // 
        // urn::dir:attribute-def:$attribute.name
        // urn:oid:$attrParams.attributeOids.get($attribute.name)
        String saml1String = metadata.getSaml1Uri();
        if (StringHelper.isEmpty(saml1String)) {
            boolean standard = metadata.isCustom() || StringHelper.isEmpty(metadata.getUrn()) || (!StringHelper.isEmpty(metadata.getUrn()) && metadata.getUrn().startsWith("urn:gluu:dir:attribute-def:"));
            saml1String = String.format("urn:%s:dir:attribute-def:%s", standard ? "gluu" : "mace", attributeName);
        }
        attributeSAML1Strings.put(attributeName, saml1String);
        String saml2String = metadata.getSaml2Uri();
        if (StringHelper.isEmpty(saml2String)) {
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSAML2Strings.put(attributeName, saml2String);
    }
    attrParams.put("attributes", attributes);
    attrParams.put("attributeSAML1Strings", attributeSAML1Strings);
    attrParams.put("attributeSAML2Strings", attributeSAML2Strings);
    return attrParams;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaEntry(org.xdi.model.SchemaEntry) GluuAttribute(org.xdi.model.GluuAttribute) AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)

Example 20 with GluuCustomAttribute

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

the class UserProfileAction method getPhotoThumbData.

public byte[] getPhotoThumbData() {
    List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.USER);
    GluuAttribute photoAttribute = attributeService.getAttributeByName("photo1", attributes);
    GluuCustomAttribute customAttribute = new GluuCustomAttribute("photo1", this.person.getAttribute("photo1"));
    customAttribute.setMetadata(photoAttribute);
    GluuImage image = imageService.getImage(customAttribute);
    if (image == null) {
        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)

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