Search in sources :

Example 6 with ChallengeItemConfiguration

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()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) ArrayList(java.util.ArrayList) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

ChallengeItemConfiguration (password.pwm.config.value.data.ChallengeItemConfiguration)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 List (java.util.List)4 TreeMap (java.util.TreeMap)4 LinkedHashMap (java.util.LinkedHashMap)2 Locale (java.util.Locale)2 Element (org.jdom2.Element)2 ChaiChallenge (com.novell.ldapchai.cr.ChaiChallenge)1 ChaiChallengeSet (com.novell.ldapchai.cr.ChaiChallengeSet)1 Challenge (com.novell.ldapchai.cr.Challenge)1 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)1 CDATA (org.jdom2.CDATA)1 PwmSetting (password.pwm.config.PwmSetting)1 StoredValue (password.pwm.config.StoredValue)1 ChallengeValue (password.pwm.config.value.ChallengeValue)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 Percent (password.pwm.util.java.Percent)1 PwmSecurityKey (password.pwm.util.secure.PwmSecurityKey)1