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;
}
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");
}
}
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());
}
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);
}
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());
}
}
Aggregations