made urls for password reset configurable
This commit is contained in:
@ -1,15 +1,13 @@
|
|||||||
package de.muehlencord.shared.account.business.mail;
|
package de.muehlencord.shared.account.business.mail;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.configuration.AccountConfigurationKey;
|
||||||
import de.muehlencord.shared.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.entity.AccountEntity;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.faces.context.ExternalContext;
|
import javax.inject.Inject;
|
||||||
import javax.faces.context.FacesContext;
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.Multipart;
|
import javax.mail.Multipart;
|
||||||
@ -21,6 +19,7 @@ import javax.mail.internet.MimeMessage;
|
|||||||
import javax.mail.internet.MimeMultipart;
|
import javax.mail.internet.MimeMultipart;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import de.muehlencord.shared.account.configuration.AccountConfigurationValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -34,6 +33,15 @@ public class MailService {
|
|||||||
@EJB
|
@EJB
|
||||||
private MailTemplateService mailTemplateService;
|
private MailTemplateService mailTemplateService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@AccountConfigurationValue(key = AccountConfigurationKey.BaseUrl)
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@AccountConfigurationValue(key = AccountConfigurationKey.PasswordResetUrl)
|
||||||
|
private String passwordResetUrl;
|
||||||
|
|
||||||
|
// TODO make this configurable by injection from the application it uses it, fall back to defaul mail setup if not available
|
||||||
@Resource(lookup = "java:jboss/mail/ssgMail")
|
@Resource(lookup = "java:jboss/mail/ssgMail")
|
||||||
private Session mailSession;
|
private Session mailSession;
|
||||||
|
|
||||||
@ -97,6 +105,7 @@ public class MailService {
|
|||||||
public String sendPasswortResetStartEmail(AccountEntity account, String token) throws MailException {
|
public String sendPasswortResetStartEmail(AccountEntity account, String token) throws MailException {
|
||||||
MailDatamodel model = new MailDatamodel(account);
|
MailDatamodel model = new MailDatamodel(account);
|
||||||
|
|
||||||
|
/* old aproach via FacesContext - add this back as fallback if injection point if not configured
|
||||||
try {
|
try {
|
||||||
// String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
|
// String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
|
||||||
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
|
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
|
||||||
@ -113,7 +122,13 @@ public class MailService {
|
|||||||
} catch (MalformedURLException ex) {
|
} catch (MalformedURLException ex) {
|
||||||
throw new MailException("Error while sending email.", ex);
|
throw new MailException("Error while sending email.", ex);
|
||||||
}
|
}
|
||||||
|
String baseUrl = configService.getConfigValue(configKey);
|
||||||
|
String resetUrlWithToken = baseUrl + "/login.xhtml?token=" + token;
|
||||||
|
*/
|
||||||
|
|
||||||
|
String resetUrlWithToken = passwordResetUrl + "?token=" + token;
|
||||||
|
model.addParameter("url", baseUrl);
|
||||||
|
model.addParameter("resetUrl", resetUrlWithToken);
|
||||||
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html");
|
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.account.configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
*/
|
||||||
|
public enum AccountConfigurationKey {
|
||||||
|
// the base path of the application
|
||||||
|
BaseUrl,
|
||||||
|
// the full pass to the reset password page
|
||||||
|
PasswordResetUrl,
|
||||||
|
// injection handler
|
||||||
|
Producer;
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.account.configuration;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import javax.enterprise.util.Nonbinding;
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Qualifier
|
||||||
|
public @interface AccountConfigurationValue {
|
||||||
|
|
||||||
|
@Nonbinding
|
||||||
|
AccountConfigurationKey key();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user