use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class DisplayTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
PwmRequest pwmRequest = null;
try {
pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
} catch (PwmException e) {
/* noop */
}
final Locale locale = pwmRequest == null ? PwmConstants.DEFAULT_LOCALE : pwmRequest.getLocale();
final Class bundle = readBundle();
String displayMessage = figureDisplayMessage(locale, pwmRequest == null ? null : pwmRequest.getConfig(), bundle);
if (pwmRequest != null) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
displayMessage = macroMachine.expandMacros(displayMessage);
}
pageContext.getOut().write(displayMessage);
} catch (PwmUnrecoverableException e) {
{
LOGGER.debug("error while executing jsp display tag: " + e.getMessage());
return EVAL_PAGE;
}
} catch (Exception e) {
LOGGER.debug("error while executing jsp display tag: " + e.getMessage(), e);
throw new JspTagException(e.getMessage(), e);
}
return EVAL_PAGE;
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class AuditService method sendAsEmail.
private static void sendAsEmail(final PwmApplication pwmApplication, final AuditRecord record, final String toAddress, final String fromAddress) throws PwmUnrecoverableException {
final MacroMachine macroMachine = MacroMachine.forNonUserSpecific(pwmApplication, SessionLabel.AUDITING_SESSION_LABEL);
String subject = macroMachine.expandMacros(pwmApplication.getConfig().readAppProperty(AppProperty.AUDIT_EVENTS_EMAILSUBJECT));
subject = subject.replace("%EVENT%", record.getEventCode().getLocalizedString(pwmApplication.getConfig(), PwmConstants.DEFAULT_LOCALE));
final String body;
{
final String jsonRecord = JsonUtil.serialize(record);
final Map<String, Object> mapRecord = JsonUtil.deserializeMap(jsonRecord);
body = StringUtil.mapToString(mapRecord, "=", "\n");
}
final EmailItemBean emailItem = new EmailItemBean(toAddress, fromAddress, subject, body, null);
pwmApplication.getEmailQueue().submitEmail(emailItem, null, macroMachine);
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class IntruderManager method sendIntruderNoticeEmail.
private static void sendIntruderNoticeEmail(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final UserIdentity userIdentity) {
final Locale locale = LocaleHelper.getLocaleForSessionID(pwmApplication, sessionLabel.getSessionID());
final Configuration config = pwmApplication.getConfig();
final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_INTRUDERNOTICE, locale);
if (configuredEmailSetting == null) {
return;
}
try {
final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, SessionLabel.SYSTEM_LABEL, userIdentity, locale);
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, sessionLabel, userInfo, null);
pwmApplication.getEmailQueue().submitEmail(configuredEmailSetting, userInfo, macroMachine);
} catch (PwmUnrecoverableException e) {
LOGGER.error("error reading user info while sending intruder notice for user " + userIdentity + ", error: " + e.getMessage());
}
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class PwNotifyEngine method sendNoticeEmail.
private void sendNoticeEmail(final UserIdentity userIdentity) throws PwmUnrecoverableException {
final Locale userLocale = PwmConstants.DEFAULT_LOCALE;
final EmailItemBean emailItemBean = pwmApplication.getConfig().readSettingAsEmail(PwmSetting.EMAIL_PW_EXPIRATION_NOTICE, userLocale);
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, userLocale, SESSION_LABEL, userIdentity);
final UserInfo userInfoBean = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, SESSION_LABEL, userIdentity, userLocale);
StatisticsManager.incrementStat(pwmApplication, Statistic.PWNOTIFY_EMAILS_SENT);
pwmApplication.getEmailQueue().submitEmail(emailItemBean, userInfoBean, macroMachine);
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class PasswordUtility method sendNewPassword.
public static String sendNewPassword(final UserInfo userInfo, final PwmApplication pwmApplication, final PasswordData newPassword, final Locale userLocale, final MessageSendMethod messageSendMethod) throws PwmOperationalException, PwmUnrecoverableException {
final String emailAddress = userInfo.getUserEmailAddress();
final String smsNumber = userInfo.getUserSmsNumber();
String returnToAddress = emailAddress;
final MacroMachine macroMachine;
{
final LoginInfoBean loginInfoBean = new LoginInfoBean();
loginInfoBean.setUserCurrentPassword(newPassword);
loginInfoBean.setUserIdentity(userInfo.getUserIdentity());
macroMachine = MacroMachine.forUser(pwmApplication, null, userInfo, loginInfoBean);
}
final ErrorInformation error;
switch(messageSendMethod) {
case SMSONLY:
// Only try SMS
error = sendNewPasswordSms(userInfo, pwmApplication, macroMachine, newPassword, smsNumber, userLocale);
returnToAddress = smsNumber;
break;
case EMAILONLY:
default:
// Only try email
error = sendNewPasswordEmail(userInfo, pwmApplication, macroMachine, newPassword, emailAddress, userLocale);
break;
}
if (error != null) {
throw new PwmOperationalException(error);
}
return returnToAddress;
}
Aggregations