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;
}
Aggregations