|
@@ -29,8 +29,8 @@ import password.pwm.PwmConstants;
|
|
import password.pwm.bean.EmailItemBean;
|
|
import password.pwm.bean.EmailItemBean;
|
|
import password.pwm.bean.SessionLabel;
|
|
import password.pwm.bean.SessionLabel;
|
|
import password.pwm.bean.SmsItemBean;
|
|
import password.pwm.bean.SmsItemBean;
|
|
|
|
+import password.pwm.bean.TokenDestinationItem;
|
|
import password.pwm.bean.UserIdentity;
|
|
import password.pwm.bean.UserIdentity;
|
|
-import password.pwm.ldap.UserInfo;
|
|
|
|
import password.pwm.config.Configuration;
|
|
import password.pwm.config.Configuration;
|
|
import password.pwm.config.PwmSetting;
|
|
import password.pwm.config.PwmSetting;
|
|
import password.pwm.config.option.DataStorageMethod;
|
|
import password.pwm.config.option.DataStorageMethod;
|
|
@@ -46,6 +46,7 @@ import password.pwm.error.PwmUnrecoverableException;
|
|
import password.pwm.health.HealthMessage;
|
|
import password.pwm.health.HealthMessage;
|
|
import password.pwm.health.HealthRecord;
|
|
import password.pwm.health.HealthRecord;
|
|
import password.pwm.http.PwmSession;
|
|
import password.pwm.http.PwmSession;
|
|
|
|
+import password.pwm.ldap.UserInfo;
|
|
import password.pwm.ldap.auth.SessionAuthenticator;
|
|
import password.pwm.ldap.auth.SessionAuthenticator;
|
|
import password.pwm.svc.PwmService;
|
|
import password.pwm.svc.PwmService;
|
|
import password.pwm.svc.event.AuditEvent;
|
|
import password.pwm.svc.event.AuditEvent;
|
|
@@ -55,6 +56,7 @@ import password.pwm.svc.intruder.RecordType;
|
|
import password.pwm.svc.stats.Statistic;
|
|
import password.pwm.svc.stats.Statistic;
|
|
import password.pwm.svc.stats.StatisticsManager;
|
|
import password.pwm.svc.stats.StatisticsManager;
|
|
import password.pwm.util.DataStore;
|
|
import password.pwm.util.DataStore;
|
|
|
|
+import password.pwm.util.ValueObfuscator;
|
|
import password.pwm.util.db.DatabaseDataStore;
|
|
import password.pwm.util.db.DatabaseDataStore;
|
|
import password.pwm.util.db.DatabaseTable;
|
|
import password.pwm.util.db.DatabaseTable;
|
|
import password.pwm.util.java.JavaHelper;
|
|
import password.pwm.util.java.JavaHelper;
|
|
@@ -612,7 +614,7 @@ public class TokenService implements PwmService {
|
|
}
|
|
}
|
|
|
|
|
|
public static class TokenSender {
|
|
public static class TokenSender {
|
|
- public static void sendToken(
|
|
|
|
|
|
+ public static List<TokenDestinationItem.Type> sendToken(
|
|
final PwmApplication pwmApplication,
|
|
final PwmApplication pwmApplication,
|
|
final UserInfo userInfo,
|
|
final UserInfo userInfo,
|
|
final MacroMachine macroMachine,
|
|
final MacroMachine macroMachine,
|
|
@@ -627,6 +629,8 @@ public class TokenService implements PwmService {
|
|
{
|
|
{
|
|
final boolean success;
|
|
final boolean success;
|
|
|
|
|
|
|
|
+ final List<TokenDestinationItem.Type> sentTypes = new ArrayList<>();
|
|
|
|
+
|
|
try {
|
|
try {
|
|
switch (tokenSendMethod) {
|
|
switch (tokenSendMethod) {
|
|
case NONE:
|
|
case NONE:
|
|
@@ -636,27 +640,49 @@ public class TokenService implements PwmService {
|
|
case BOTH:
|
|
case BOTH:
|
|
// Send both email and SMS, success if one of both succeeds
|
|
// Send both email and SMS, success if one of both succeeds
|
|
final boolean suc1 = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
final boolean suc1 = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
|
|
+ if (suc1) {
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.email);
|
|
|
|
+ }
|
|
final boolean suc2 = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
final boolean suc2 = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
|
|
+ if (suc2) {
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.sms);
|
|
|
|
+ }
|
|
success = suc1 || suc2;
|
|
success = suc1 || suc2;
|
|
break;
|
|
break;
|
|
case EMAILFIRST:
|
|
case EMAILFIRST:
|
|
// Send email first, try SMS if email is not available
|
|
// Send email first, try SMS if email is not available
|
|
- success = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey) ||
|
|
|
|
- sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
|
|
|
|
+ final boolean emailSuccess = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
|
|
+ if (emailSuccess) {
|
|
|
|
+ success = true;
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.email);
|
|
|
|
+ } else {
|
|
|
|
+ success = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
|
|
+ if (success) {
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.sms);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case SMSFIRST:
|
|
case SMSFIRST:
|
|
// Send SMS first, try email if SMS is not available
|
|
// Send SMS first, try email if SMS is not available
|
|
- success = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey) ||
|
|
|
|
- sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
|
|
|
|
+ final boolean smsSuccess = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
|
|
+ if (smsSuccess) {
|
|
|
|
+ success = true;
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.sms);
|
|
|
|
+ } else {
|
|
|
|
+ success = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.email);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case SMSONLY:
|
|
case SMSONLY:
|
|
// Only try SMS
|
|
// Only try SMS
|
|
success = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
success = sendSmsToken(pwmApplication, userInfo, macroMachine, smsNumber, smsMessage, tokenKey);
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.sms);
|
|
break;
|
|
break;
|
|
case EMAILONLY:
|
|
case EMAILONLY:
|
|
default:
|
|
default:
|
|
// Only try email
|
|
// Only try email
|
|
success = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
success = sendEmailToken(pwmApplication, userInfo, macroMachine, configuredEmailSetting, emailAddress, tokenKey);
|
|
|
|
+ sentTypes.add(TokenDestinationItem.Type.email);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
} catch (ChaiUnavailableException e) {
|
|
} catch (ChaiUnavailableException e) {
|
|
@@ -667,6 +693,8 @@ public class TokenService implements PwmService {
|
|
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_TOKEN_MISSING_CONTACT));
|
|
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_TOKEN_MISSING_CONTACT));
|
|
}
|
|
}
|
|
pwmApplication.getStatisticsManager().incrementValue(Statistic.TOKENS_SENT);
|
|
pwmApplication.getStatisticsManager().incrementValue(Statistic.TOKENS_SENT);
|
|
|
|
+
|
|
|
|
+ return sentTypes;
|
|
}
|
|
}
|
|
|
|
|
|
public static boolean sendEmailToken(
|
|
public static boolean sendEmailToken(
|
|
@@ -720,5 +748,28 @@ public class TokenService implements PwmService {
|
|
LOGGER.debug("token SMS added to send queue for " + smsNumber);
|
|
LOGGER.debug("token SMS added to send queue for " + smsNumber);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static String figureDisplayString(
|
|
|
|
+ final Configuration configuration,
|
|
|
|
+ final List<TokenDestinationItem.Type> sentTypes,
|
|
|
|
+ final String email,
|
|
|
|
+ final String sms
|
|
|
|
+ ) {
|
|
|
|
+ final ValueObfuscator valueObfuscator = new ValueObfuscator(configuration);
|
|
|
|
+ final StringBuilder displayDestAddress = new StringBuilder();
|
|
|
|
+ {
|
|
|
|
+ if (sentTypes.contains(TokenDestinationItem.Type.email)) {
|
|
|
|
+ displayDestAddress.append(valueObfuscator.maskEmail(email));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sentTypes.contains(TokenDestinationItem.Type.sms)) {
|
|
|
|
+ if (displayDestAddress.length() > 0) {
|
|
|
|
+ displayDestAddress.append(" & ");
|
|
|
|
+ }
|
|
|
|
+ displayDestAddress.append(valueObfuscator.maskPhone(sms));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return displayDestAddress.toString();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|