Search in sources :

Example 1 with OTPStorageFormat

use of password.pwm.config.option.OTPStorageFormat in project pwm by pwm-project.

the class AbstractOtpOperator method composeOtpAttribute.

/**
 * Compose a single line of OTP information.
 *
 * @param otpUserRecord input user record
 * @return A string formatted record
 */
public String composeOtpAttribute(final OTPUserRecord otpUserRecord) throws PwmUnrecoverableException {
    String value = "";
    if (otpUserRecord != null) {
        final Configuration config = pwmApplication.getConfig();
        final OTPStorageFormat format = config.readSettingAsEnum(PwmSetting.OTP_SECRET_STORAGEFORMAT, OTPStorageFormat.class);
        switch(format) {
            case PWM:
                value = JsonUtil.serialize(otpUserRecord);
                break;
            case OTPURL:
                value = OTPUrlUtil.composeOtpUrl(otpUserRecord);
                break;
            case BASE32SECRET:
                value = otpUserRecord.getSecret();
                break;
            case PAM:
                value = OTPPamUtil.composePamData(otpUserRecord);
                break;
            default:
                final String errorStr = String.format("Unsupported storage format: %s", format.toString());
                final ErrorInformation error = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorStr);
                throw new PwmUnrecoverableException(error);
        }
    }
    return value;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) OTPStorageFormat(password.pwm.config.option.OTPStorageFormat)

Aggregations

Configuration (password.pwm.config.Configuration)1 OTPStorageFormat (password.pwm.config.option.OTPStorageFormat)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1