Search in sources :

Example 1 with MailUtils

use of org.gluu.oxtrust.util.MailUtils in project oxTrust by GluuFederation.

the class UpdateOrganizationAction method verifySmtpConfiguration.

public String verifySmtpConfiguration() {
    log.info("HostName: " + appliance.getSmtpHost() + " Port: " + appliance.getSmtpPort() + " RequireSSL: " + appliance.isRequiresSsl() + " RequireSSL: " + appliance.isRequiresAuthentication());
    log.info("UserName: " + appliance.getSmtpUserName() + " Password: " + applianceService.getDecryptedSmtpPassword(appliance));
    try {
        MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
        mail.sendMail(appliance.getSmtpFromName() + " <" + appliance.getSmtpFromEmailAddress() + ">", appliance.getSmtpFromEmailAddress(), "SMTP Server Configuration Verification", "SMTP Server Configuration Verification Successful.");
    } catch (AuthenticationFailedException ex) {
        log.error("SMTP Authentication Error: ", ex);
        return OxTrustConstants.RESULT_FAILURE;
    } catch (MessagingException ex) {
        log.error("SMTP Host Connection Error", ex);
        return OxTrustConstants.RESULT_FAILURE;
    }
    log.info("Connection Successful");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : AuthenticationFailedException(javax.mail.AuthenticationFailedException) MessagingException(javax.mail.MessagingException) MailUtils(org.gluu.oxtrust.util.MailUtils)

Example 2 with MailUtils

use of org.gluu.oxtrust.util.MailUtils 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)

Aggregations

MailUtils (org.gluu.oxtrust.util.MailUtils)2 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 AuthenticationFailedException (javax.mail.AuthenticationFailedException)1 MessagingException (javax.mail.MessagingException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)1 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)1 OrganizationalUnit (org.gluu.oxtrust.model.OrganizationalUnit)1 PasswordResetRequest (org.gluu.oxtrust.model.PasswordResetRequest)1