use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.
the class ChallengeProfile method readChallengeSet.
private static ChallengeSet readChallengeSet(final String profileID, final Locale locale, final StoredConfiguration storedConfiguration, final PwmSetting requiredChallenges, final PwmSetting randomChallenges, final int minimumRands) throws PwmOperationalException {
final List<ChallengeItemConfiguration> requiredQuestions = valueToChallengeItemArray(storedConfiguration.readSetting(requiredChallenges, profileID), locale);
final List<ChallengeItemConfiguration> randomQuestions = valueToChallengeItemArray(storedConfiguration.readSetting(randomChallenges, profileID), locale);
final List<Challenge> challenges = new ArrayList<>();
int randoms = minimumRands;
if (requiredQuestions != null) {
for (final ChallengeItemConfiguration item : requiredQuestions) {
if (item != null) {
final Challenge chaiChallenge = new ChaiChallenge(true, item.getText(), item.getMinLength(), item.getMaxLength(), item.isAdminDefined(), item.getMaxQuestionCharsInAnswer(), item.isEnforceWordlist());
challenges.add(chaiChallenge);
}
}
}
if (randomQuestions != null) {
for (final ChallengeItemConfiguration item : randomQuestions) {
if (item != null) {
final Challenge chaiChallenge = new ChaiChallenge(false, item.getText(), item.getMinLength(), item.getMaxLength(), item.isAdminDefined(), item.getMaxQuestionCharsInAnswer(), item.isEnforceWordlist());
challenges.add(chaiChallenge);
}
}
if (randoms > randomQuestions.size()) {
randoms = randomQuestions.size();
}
} else {
randoms = 0;
}
try {
return new ChaiChallengeSet(challenges, randoms, locale, PwmConstants.PWM_APP_NAME + "-defined " + PwmConstants.SERVLET_VERSION);
} catch (ChaiValidationException e) {
throw new PwmOperationalException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "invalid challenge set configuration: " + e.getMessage()));
}
}
Aggregations