Search in sources :

Example 36 with MacroMachine

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmException(password.pwm.error.PwmException) Locale(java.util.Locale) PwmRequest(password.pwm.http.PwmRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) MissingResourceException(java.util.MissingResourceException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmException(password.pwm.error.PwmException)

Example 37 with MacroMachine

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);
}
Also used : EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine) Map(java.util.Map)

Example 38 with 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());
    }
}
Also used : Locale(java.util.Locale) FormConfiguration(password.pwm.config.value.data.FormConfiguration) Configuration(password.pwm.config.Configuration) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 39 with MacroMachine

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);
}
Also used : Locale(java.util.Locale) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo)

Example 40 with 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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) LoginInfoBean(password.pwm.bean.LoginInfoBean) MacroMachine(password.pwm.util.macro.MacroMachine) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

MacroMachine (password.pwm.util.macro.MacroMachine)61 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)20 Locale (java.util.Locale)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Configuration (password.pwm.config.Configuration)13 UserInfo (password.pwm.ldap.UserInfo)13 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 PwmApplication (password.pwm.PwmApplication)12 FormConfiguration (password.pwm.config.value.data.FormConfiguration)12 ChaiUser (com.novell.ldapchai.ChaiUser)10 PwmException (password.pwm.error.PwmException)10 List (java.util.List)9 EmailItemBean (password.pwm.bean.EmailItemBean)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 Map (java.util.Map)8 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)8 PwmSession (password.pwm.http.PwmSession)8 Instant (java.time.Instant)7