Search in sources :

Example 1 with PasswordResetRequest

use of org.gluu.oxtrust.model.PasswordResetRequest 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 2 with PasswordResetRequest

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

the class PasswordReminderAction method requestReminder.

public String requestReminder() throws Exception {
    if (enabled()) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        ExternalContext externalContext = facesContext.getExternalContext();
        if (externalContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
        GluuCustomPerson person = new GluuCustomPerson();
        person.setMail(email);
        List<GluuCustomPerson> matchedPersons = personService.findPersons(person, 0);
        if (matchedPersons != null && matchedPersons.size() > 0) {
            GluuAppliance appliance = applianceService.getAppliance();
            OrganizationalUnit requests = new OrganizationalUnit();
            requests.setOu("resetPasswordRequests");
            requests.setDn("ou=resetPasswordRequests," + appliance.getDn());
            if (!ldapEntryManager.contains(requests)) {
                ldapEntryManager.persist(requests);
            }
            PasswordResetRequest request = new PasswordResetRequest();
            do {
                request.setCreationDate(Calendar.getInstance().getTime());
                request.setPersonInum(matchedPersons.get(0).getInum());
                request.setOxGuid(StringHelper.getRandomString(16));
                request.setBaseDn("oxGuid=" + request.getOxGuid() + ", ou=resetPasswordRequests," + appliance.getDn());
            } while (ldapEntryManager.contains(request));
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            mail.sendMail(appliance.getSmtpFromName() + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_FOUND, matchedPersons.get(0).getGivenName(), organizationService.getOrganization().getDisplayName(), appConfiguration.getApplianceUrl() + httpServletRequest.getContextPath() + "/resetPassword/" + request.getOxGuid()));
            ldapEntryManager.persist(request);
        } else {
            GluuAppliance appliance = applianceService.getAppliance();
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            String fromName = appliance.getSmtpFromName();
            if (fromName == null) {
                fromName = String.format("%1$s identity server", organizationService.getOrganization().getDisplayName());
            }
            mail.sendMail(fromName + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_NOT_FOUND, organizationService.getOrganization().getDisplayName()));
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) FacesContext(javax.faces.context.FacesContext) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) OrganizationalUnit(org.gluu.oxtrust.model.OrganizationalUnit) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) ExternalContext(javax.faces.context.ExternalContext) MailUtils(org.gluu.oxtrust.util.MailUtils)

Example 3 with PasswordResetRequest

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

the class PasswordReminderAction method requestReminderImpl.

public String requestReminderImpl() throws Exception {
    if (enabled()) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        ExternalContext externalContext = facesContext.getExternalContext();
        if (externalContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
        GluuCustomPerson person = new GluuCustomPerson();
        person.setMail(email);
        List<GluuCustomPerson> matchedPersons = personService.findPersons(person, 0);
        if (matchedPersons != null && matchedPersons.size() > 0) {
            GluuAppliance appliance = applianceService.getAppliance();
            OrganizationalUnit requests = new OrganizationalUnit();
            requests.setOu("resetPasswordRequests");
            requests.setDn("ou=resetPasswordRequests," + appliance.getDn());
            if (!ldapEntryManager.contains(requests)) {
                ldapEntryManager.persist(requests);
            }
            PasswordResetRequest request = new PasswordResetRequest();
            do {
                request.setCreationDate(Calendar.getInstance().getTime());
                request.setPersonInum(matchedPersons.get(0).getInum());
                request.setOxGuid(StringHelper.getRandomString(16));
                request.setBaseDn("oxGuid=" + request.getOxGuid() + ", ou=resetPasswordRequests," + appliance.getDn());
            } while (ldapEntryManager.contains(request));
            rendererParameters.setParameter("givenName", matchedPersons.get(0).getGivenName());
            rendererParameters.setParameter("organizationName", organizationService.getOrganization().getDisplayName());
            rendererParameters.setParameter("resetLink", appConfiguration.getApplianceUrl() + httpServletRequest.getContextPath() + "/resetPassword/" + request.getOxGuid());
            String subj = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.subject']}");
            String messagePlain = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.plain.body']}");
            String messageHtml = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.html.body']}");
            // rendererParameters.setParameter("mail_body", messageHtml);
            // String mailHtml = renderService.renderView("/WEB-INF/mail/reset_password.xhtml");
            mailService.sendMail(email, null, subj, messagePlain, messageHtml);
            ldapEntryManager.persist(request);
        } else {
            GluuAppliance appliance = applianceService.getAppliance();
            SmtpConfiguration smtpConfiguration = appliance.getSmtpConfiguration();
            rendererParameters.setParameter("organizationName", organizationService.getOrganization().getDisplayName());
            String fromName = smtpConfiguration.getFromName();
            if (fromName == null) {
                fromName = String.format("%1$s identity server", organizationService.getOrganization().getDisplayName());
            }
            String subj = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.subject']}");
            String messagePlain = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.plain.body']}");
            String messageHtml = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.html.body']}");
            // rendererParameters.setParameter("mail_body", messageHtml);
            // String mailHtml = renderService.renderView("/WEB-INF/mail/reset_password.xhtml");
            mailService.sendMail(null, fromName, email, null, subj, messagePlain, messageHtml);
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) FacesContext(javax.faces.context.FacesContext) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) OrganizationalUnit(org.gluu.oxtrust.model.OrganizationalUnit) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) SmtpConfiguration(org.xdi.model.SmtpConfiguration) ExternalContext(javax.faces.context.ExternalContext)

Aggregations

GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)3 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)3 PasswordResetRequest (org.gluu.oxtrust.model.PasswordResetRequest)3 ExternalContext (javax.faces.context.ExternalContext)2 FacesContext (javax.faces.context.FacesContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 OrganizationalUnit (org.gluu.oxtrust.model.OrganizationalUnit)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)1 MailUtils (org.gluu.oxtrust.util.MailUtils)1 SmtpConfiguration (org.xdi.model.SmtpConfiguration)1