Search in sources :

Example 1 with DuplicateEmailException

use of org.gluu.oxtrust.exception.DuplicateEmailException in project oxTrust by GluuFederation.

the class PasswordResetAction method updateImpl.

public String updateImpl() {
    boolean valid = true;
    if (captchaEnable()) {
        valid = recaptchaService.verifyRecaptchaResponse();
    }
    if (this.password != null && this.confirm != null) {
        if (!this.password.equalsIgnoreCase(this.confirm)) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Password mismatch.");
            return OxTrustConstants.RESULT_FAILURE;
        }
    } else {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Incorrect data send.");
        return OxTrustConstants.RESULT_FAILURE;
    }
    if (valid) {
        GluuOrganization organization = organizationService.getOrganization();
        try {
            this.request = ldapEntryManager.find(PasswordResetRequest.class, "oxGuid=" + getCode() + ",ou=resetPasswordRequests," + organization.getDn());
        } catch (Exception e) {
            log.error("=================", e);
            return OxTrustConstants.RESULT_FAILURE;
        }
        checkSecurityQuetion();
        Calendar requestCalendarExpiry = Calendar.getInstance();
        Calendar currentCalendar = Calendar.getInstance();
        if (request != null) {
            requestCalendarExpiry.setTime((request.getCreationDate()));
            requestCalendarExpiry.add(Calendar.HOUR, 2);
        }
        GluuCustomPerson person = personService.getPersonByInum(request.getPersonInum());
        if (securityAnswer == null) {
            securityAnswer = getResponse();
        }
        if (requestCalendarExpiry.after(currentCalendar)) {
            PasswordResetRequest removeRequest = new PasswordResetRequest();
            removeRequest.setBaseDn(request.getBaseDn());
            if (this.securityQuestion != null && this.answer != null) {
                Boolean securityQuestionAnswered = (this.securityAnswer != null) && this.securityAnswer.equalsIgnoreCase(answer.getValue());
                if (securityQuestionAnswered) {
                    person.setUserPassword(password);
                    try {
                        personService.updatePerson(person);
                        ldapEntryManager.remove(removeRequest);
                        return OxTrustConstants.RESULT_SUCCESS;
                    } catch (DuplicateEmailException e) {
                        facesMessages.add(FacesMessage.SEVERITY_ERROR, e.getMessage());
                        log.error("", e);
                    } catch (Exception e) {
                        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Error while processing the request");
                        log.error("", e);
                    }
                    return OxTrustConstants.RESULT_FAILURE;
                } else {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "The provided security answer is not correct. Please try again from the link!");
                    return OxTrustConstants.RESULT_FAILURE;
                }
            } else {
                person.setUserPassword(password);
                try {
                    personService.updatePerson(person);
                    ldapEntryManager.remove(removeRequest);
                    return OxTrustConstants.RESULT_SUCCESS;
                } catch (DuplicateEmailException e) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, e.getMessage());
                } catch (Exception e) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "Error while processing the request");
                }
                return OxTrustConstants.RESULT_FAILURE;
            }
        }
    } else {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, facesMessages.evalResourceAsString("#{msgs['person.passwordreset.catch.checkInputAndCaptcha']}"));
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) ParseException(java.text.ParseException) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) IOException(java.io.IOException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 2 with DuplicateEmailException

use of org.gluu.oxtrust.exception.DuplicateEmailException in project oxTrust by GluuFederation.

the class RegisterPersonAction method registerImpl.

public String registerImpl() throws CloneNotSupportedException {
    boolean registrationFormValid = StringHelper.equals(password, repeatPassword);
    if (!captchaDisabled) {
        String gRecaptchaRresponse = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("g-recaptcha-response");
        boolean reCaptchaResponse = recaptchaService.verifyRecaptchaResponse(gRecaptchaRresponse);
        registrationFormValid &= reCaptchaResponse;
    }
    if (registrationFormValid) {
        GluuCustomPerson archivedPerson = (GluuCustomPerson) person.clone();
        try {
            String customObjectClass = attributeService.getCustomOrigin();
            this.person.setCustomObjectClasses(new String[] { customObjectClass });
            if (person.getInum() == null) {
                String inum = personService.generateInumForNewPerson();
                this.person.setInum(inum);
            }
            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());
            }
            this.person.setUserPassword(password);
            this.person.setCreationDate(new Date());
            this.person.setMail(email);
            this.postRegistrationInformation = "You have successfully registered with oxTrust. Login to begin your session.";
            boolean result = false;
            result = externalUserRegistrationService.executeExternalPreRegistrationMethods(this.person, requestParameters);
            postRegistrationRedirectUri = getRegistrationRedirectUri();
            if (!result) {
                this.person = archivedPerson;
                return OxTrustConstants.RESULT_FAILURE;
            }
            if ((this.inum != null) && !this.inum.isEmpty()) {
                personService.updatePerson(this.person);
                try {
                    oxTrustAuditService.audit(this.person.getInum() + " **" + this.person.getDisplayName() + "** REGISTRATION UPDATED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
                } catch (Exception e) {
                }
            } else {
                personService.addPerson(this.person);
                try {
                    oxTrustAuditService.audit(this.person.getInum() + " **" + this.person.getDisplayName() + "** REGISTERED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
                } catch (Exception e) {
                }
            }
            requestParameters.put(HOST_NAME, new String[] { configurationService.getConfiguration().getHostname() });
            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 (DuplicateEmailException ex) {
            log.error("Failed to add new person {}", this.person.getInum(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, ex.getMessage());
            this.person = archivedPerson;
            return OxTrustConstants.RESULT_FAILURE;
        } 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) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) ArrayList(java.util.ArrayList) Date(java.util.Date) ValidatorException(javax.faces.validator.ValidatorException) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) IOException(java.io.IOException)

Example 3 with DuplicateEmailException

use of org.gluu.oxtrust.exception.DuplicateEmailException 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)

Example 4 with DuplicateEmailException

use of org.gluu.oxtrust.exception.DuplicateEmailException in project oxTrust by GluuFederation.

the class UserProfileAction method update.

public String update() {
    try {
        if (appConfiguration.getEnforceEmailUniqueness() && !dataSourceTypeService.isLDAP(personService.getDnForPerson(null))) {
            if (!userEmailIsUniqAtEditionTime(this.person.getAttribute("mail"))) {
                facesMessages.add(FacesMessage.SEVERITY_ERROR, "#{msgs['UpdatePersonAction.faileUpdateUserMailidExist']} %s", person.getMail());
                return OxTrustConstants.RESULT_FAILURE;
            }
        }
        GluuCustomPerson person = this.person;
        person.setGluuOptOuts(optOuts.size() == 0 ? null : optOuts);
        boolean runScript = externalUpdateUserService.isEnabled();
        if (runScript) {
            externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
        }
        personService.updatePerson(this.person);
        oxTrustAuditService.audit(this.person.getInum() + " **" + this.person.getDisplayName() + "** PROFILE UPDATED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
        if (runScript) {
            externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
        }
    } catch (DuplicateEmailException ex) {
        log.error("Failed to update profile {}", person.getInum(), ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, ex.getMessage());
        return OxTrustConstants.RESULT_FAILURE;
    } catch (BasePersistenceException 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;
    } catch (Exception 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;
    }
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Profile '#{userProfileAction.person.displayName}' updated successfully");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException)

Example 5 with DuplicateEmailException

use of org.gluu.oxtrust.exception.DuplicateEmailException 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 (!isValidPassword()) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "Password length must be between 3 and 60 characters");
            return OxTrustConstants.RESULT_FAILURE;
        }
        if (!userNameIsUniqAtCreationTime(this.person.getUid())) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "#{msgs['UpdatePersonAction.faileAddUserUidExist']} %s", this.person.getUid());
            return OxTrustConstants.RESULT_FAILURE;
        }
        if (appConfiguration.getEnforceEmailUniqueness()) {
            if (!userEmailIsUniqAtCreationTime(this.person.getAttribute(MAIL))) {
                facesMessages.add(FacesMessage.SEVERITY_ERROR, "#{msgs['UpdatePersonAction.faileUpdateUserMailidExist']} %s", this.person.getAttribute(MAIL));
                return OxTrustConstants.RESULT_FAILURE;
            }
        }
    } else {
        if (!userNameIsUniqAtEditionTime(this.person.getUid())) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "#{msgs['UpdatePersonAction.faileAddUserUidExist']} %s", this.person.getUid());
            return OxTrustConstants.RESULT_FAILURE;
        }
        if (appConfiguration.getEnforceEmailUniqueness()) {
            if (!userEmailIsUniqAtEditionTime(this.person.getAttribute(MAIL))) {
                facesMessages.add(FacesMessage.SEVERITY_ERROR, "#{msgs['UpdatePersonAction.faileUpdateUserMailidExist']} %s", this.person.getAttribute(MAIL));
                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);
            break;
        }
    }
    this.person.setCustomAttributes(customAttributeAction.getCustomAttributes());
    this.person.getCustomAttributes().addAll(removedAttributes);
    // Sync email, in reverse ("oxTrustEmail" <- "mail")
    this.person = syncEmailReverse(this.person, true);
    boolean runScript = externalUpdateUserService.isEnabled();
    if (update) {
        try {
            if (runScript) {
                externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
            }
            personService.updatePerson(this.person);
            oxTrustAuditService.audit("USER " + this.person.getInum() + " **" + this.person.getDisplayName() + "** UPDATED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
            if (runScript) {
                externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
            }
        } catch (DuplicateEmailException ex) {
            log.error("Failed to update person {}", inum, ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, ex.getMessage());
            return OxTrustConstants.RESULT_FAILURE;
        } catch (Exception 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 {
        this.inum = personService.generateInumForNewPerson();
        String dn = personService.getDnForPerson(this.inum);
        // Save person
        this.person.setDn(dn);
        this.person.setInum(this.inum);
        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);
            oxTrustAuditService.audit("USER " + this.person.getInum() + " **" + this.person.getDisplayName() + "** ADDED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
            if (runScript) {
                externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
            }
        } catch (DuplicateEmailException ex) {
            log.error("Failed to add new person {}", this.person.getInum(), ex);
            facesMessages.add(FacesMessage.SEVERITY_ERROR, ex.getMessage());
            return OxTrustConstants.RESULT_FAILURE;
        } 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) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) ArrayList(java.util.ArrayList) ValidatorException(javax.faces.validator.ValidatorException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) IOException(java.io.IOException)

Aggregations

DuplicateEmailException (org.gluu.oxtrust.exception.DuplicateEmailException)6 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)4 IOException (java.io.IOException)3 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 ValidatorException (javax.faces.validator.ValidatorException)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)2 DuplicateEntryException (org.gluu.persist.exception.operation.DuplicateEntryException)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 GluuOrganization (org.gluu.oxtrust.model.GluuOrganization)1 PasswordResetRequest (org.gluu.oxtrust.model.PasswordResetRequest)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1