Search in sources :

Example 1 with TokenDestinationDisplayMasker

use of password.pwm.svc.token.TokenDestinationDisplayMasker in project pwm by pwm-project.

the class TokenDestinationItem method allFromConfig.

public static List<TokenDestinationItem> allFromConfig(final PwmApplication pwmApplication, final UserInfo userInfo) throws PwmUnrecoverableException {
    final Configuration configuration = pwmApplication.getConfig();
    final SecureService secureService = pwmApplication.getSecureService();
    final TokenDestinationDisplayMasker tokenDestinationDisplayMasker = new TokenDestinationDisplayMasker(configuration);
    final Map<String, TokenDestinationItem> results = new LinkedHashMap<>();
    for (final String emailValue : new String[] { userInfo.getUserEmailAddress(), userInfo.getUserEmailAddress2(), userInfo.getUserEmailAddress3() }) {
        if (!StringUtil.isEmpty(emailValue)) {
            final String idHash = secureService.hash(emailValue + Type.email.name());
            final TokenDestinationItem item = TokenDestinationItem.builder().id(idHash).display(tokenDestinationDisplayMasker.maskEmail(emailValue)).value(emailValue).type(Type.email).build();
            results.put(idHash, item);
        }
    }
    for (final String smsValue : new String[] { userInfo.getUserSmsNumber(), userInfo.getUserSmsNumber2(), userInfo.getUserSmsNumber3() }) {
        if (!StringUtil.isEmpty(smsValue)) {
            final String idHash = secureService.hash(smsValue + Type.sms.name());
            final TokenDestinationItem item = TokenDestinationItem.builder().id(idHash).display(tokenDestinationDisplayMasker.maskPhone(smsValue)).value(smsValue).type(Type.sms).build();
            results.put(idHash, item);
        }
    }
    return Collections.unmodifiableList(new ArrayList<>(results.values()));
}
Also used : SecureService(password.pwm.util.secure.SecureService) Configuration(password.pwm.config.Configuration) TokenDestinationDisplayMasker(password.pwm.svc.token.TokenDestinationDisplayMasker) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with TokenDestinationDisplayMasker

use of password.pwm.svc.token.TokenDestinationDisplayMasker in project pwm by pwm-project.

the class RestTokenDataClient method builtInService.

private TokenDestinationData builtInService(final TokenDestinationData tokenDestinationData) {
    final TokenDestinationDisplayMasker tokenDestinationDisplayMasker = new TokenDestinationDisplayMasker(pwmApplication.getConfig());
    final StringBuilder tokenSendDisplay = new StringBuilder();
    if (!StringUtil.isEmpty(tokenDestinationData.getEmail())) {
        tokenSendDisplay.append(tokenDestinationDisplayMasker.maskEmail(tokenDestinationData.getEmail()));
    }
    if (!StringUtil.isEmpty(tokenDestinationData.getSms())) {
        if (tokenSendDisplay.length() > 0) {
            tokenSendDisplay.append(" / ");
        }
        tokenSendDisplay.append(tokenDestinationDisplayMasker.maskPhone(tokenDestinationData.getSms()));
    }
    return new TokenDestinationData(tokenDestinationData.getEmail(), tokenDestinationData.getSms(), tokenSendDisplay.toString());
}
Also used : TokenDestinationDisplayMasker(password.pwm.svc.token.TokenDestinationDisplayMasker)

Aggregations

TokenDestinationDisplayMasker (password.pwm.svc.token.TokenDestinationDisplayMasker)2 LinkedHashMap (java.util.LinkedHashMap)1 Configuration (password.pwm.config.Configuration)1 SecureService (password.pwm.util.secure.SecureService)1