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;
}
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;
}
Aggregations