Search in sources :

Example 6 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class EmailValue method toXmlValues.

public List<Element> toXmlValues(final String valueElementName, final PwmSecurityKey pwmSecurityKey) {
    final List<Element> returnList = new ArrayList<>();
    for (final Map.Entry<String, EmailItemBean> entry : values.entrySet()) {
        final String localeValue = entry.getKey();
        final EmailItemBean emailItemBean = entry.getValue();
        final Element valueElement = new Element(valueElementName);
        if (localeValue.length() > 0) {
            valueElement.setAttribute("locale", localeValue);
        }
        valueElement.addContent(JsonUtil.serialize(emailItemBean));
        returnList.add(valueElement);
    }
    return returnList;
}
Also used : EmailItemBean(password.pwm.bean.EmailItemBean) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 7 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class UpdateProfileUtil method sendProfileUpdateEmailNotice.

static void sendProfileUpdateEmailNotice(final PwmApplication pwmApplication, final MacroMachine macroMachine, final UserInfo userInfo, final Locale locale, final SessionLabel sessionLabel) throws PwmUnrecoverableException, ChaiUnavailableException {
    final Configuration config = pwmApplication.getConfig();
    final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_UPDATEPROFILE, locale);
    pwmApplication.getEmailQueue().submitEmail(configuredEmailSetting, userInfo, macroMachine);
    if (configuredEmailSetting == null) {
        LOGGER.debug(sessionLabel, "skipping send profile update email for '" + userInfo.getUserIdentity().toDisplayString() + "' no email configured");
    }
}
Also used : Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) EmailItemBean(password.pwm.bean.EmailItemBean)

Example 8 with EmailItemBean

use of password.pwm.bean.EmailItemBean in project pwm by pwm-project.

the class TokenUtil method initializeAndSendToken.

public static void initializeAndSendToken(final PwmRequest pwmRequest, final TokenInitAndSendRequest tokenInitAndSendRequest) throws PwmUnrecoverableException {
    final Configuration config = pwmRequest.getConfig();
    final UserInfo userInfo = tokenInitAndSendRequest.getUserInfo();
    final Map<String, String> tokenMapData = new LinkedHashMap<>();
    final MacroMachine macroMachine;
    {
        if (tokenInitAndSendRequest.getMacroMachine() != null) {
            macroMachine = tokenInitAndSendRequest.getMacroMachine();
        } else if (tokenInitAndSendRequest.getUserInfo() != null) {
            macroMachine = MacroMachine.forUser(pwmRequest, userInfo.getUserIdentity(), makeTokenDestStringReplacer(tokenInitAndSendRequest.getTokenDestinationItem()));
        } else {
            macroMachine = null;
        }
    }
    if (userInfo != null) {
        final Instant userLastPasswordChange = userInfo.getPasswordLastModifiedTime();
        if (userLastPasswordChange != null) {
            final String userChangeString = JavaHelper.toIsoDate(userLastPasswordChange);
            tokenMapData.put(PwmConstants.TOKEN_KEY_PWD_CHG_DATE, userChangeString);
        }
    }
    if (tokenInitAndSendRequest.getInputTokenData() != null) {
        tokenMapData.putAll(tokenInitAndSendRequest.getInputTokenData());
    }
    final String tokenKey;
    final TokenPayload tokenPayload;
    {
        final TimeDuration tokenLifetime = tokenInitAndSendRequest.getTokenLifetime() == null ? new TimeDuration(config.readSettingAsLong(PwmSetting.TOKEN_LIFETIME), TimeUnit.SECONDS) : tokenInitAndSendRequest.getTokenLifetime();
        try {
            tokenPayload = pwmRequest.getPwmApplication().getTokenService().createTokenPayload(tokenInitAndSendRequest.getTokenType(), tokenLifetime, tokenMapData, userInfo == null ? null : userInfo.getUserIdentity(), tokenInitAndSendRequest.getTokenDestinationItem());
            tokenKey = pwmRequest.getPwmApplication().getTokenService().generateNewToken(tokenPayload, pwmRequest.getSessionLabel());
        } catch (PwmOperationalException e) {
            throw new PwmUnrecoverableException(e.getErrorInformation());
        }
    }
    final EmailItemBean emailItemBean = tokenInitAndSendRequest.getEmailToSend() == null ? null : config.readSettingAsEmail(tokenInitAndSendRequest.getEmailToSend(), pwmRequest.getLocale());
    final String smsMessage = tokenInitAndSendRequest.getSmsToSend() == null ? null : config.readSettingAsLocalizedString(tokenInitAndSendRequest.getSmsToSend(), pwmRequest.getLocale());
    TokenService.TokenSender.sendToken(TokenService.TokenSendInfo.builder().pwmApplication(pwmRequest.getPwmApplication()).userInfo(userInfo).macroMachine(macroMachine).configuredEmailSetting(emailItemBean).tokenDestinationItem(tokenInitAndSendRequest.getTokenDestinationItem()).smsMessage(smsMessage).tokenKey(tokenKey).sessionLabel(pwmRequest.getSessionLabel()).build());
}
Also used : Configuration(password.pwm.config.Configuration) EmailItemBean(password.pwm.bean.EmailItemBean) Instant(java.time.Instant) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) TimeDuration(password.pwm.util.java.TimeDuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 9 with EmailItemBean

use of password.pwm.bean.EmailItemBean 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 10 with EmailItemBean

use of password.pwm.bean.EmailItemBean 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)

Aggregations

EmailItemBean (password.pwm.bean.EmailItemBean)25 Configuration (password.pwm.config.Configuration)16 Locale (java.util.Locale)14 FormConfiguration (password.pwm.config.value.data.FormConfiguration)11 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)9 MacroMachine (password.pwm.util.macro.MacroMachine)9 UserInfo (password.pwm.ldap.UserInfo)8 Map (java.util.Map)5 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)5 TreeMap (java.util.TreeMap)4 PwmApplication (password.pwm.PwmApplication)4 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)3 PwmSession (password.pwm.http.PwmSession)3 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 UserIdentity (password.pwm.bean.UserIdentity)2 MessageSendMethod (password.pwm.config.option.MessageSendMethod)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 ArrayList (java.util.ArrayList)1