Search in sources :

Example 1 with ChaiChallenge

use of com.novell.ldapchai.cr.ChaiChallenge in project ldapchai by ldapchai.

the class NmasResponseSet method parseNmasPolicyXML.

static List<Challenge> parseNmasPolicyXML(final String str, final Locale locale) throws IOException, JDOMException {
    final List<Challenge> returnList = new ArrayList<Challenge>();
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build(xmlreader);
    final boolean required = doc.getRootElement().getName().equals("RequiredQuestions");
    for (final Iterator questionIterator = doc.getDescendants(new ElementFilter("Question")); questionIterator.hasNext(); ) {
        final Element loopQ = (Element) questionIterator.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final String challengeText = readDisplayString(loopQ, locale);
        final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, true, 0, false);
        returnList.add(challenge);
    }
    for (Iterator iter = doc.getDescendants(new ElementFilter("UserDefined")); iter.hasNext(); ) {
        final Element loopQ = (Element) iter.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final Challenge challenge = new ChaiChallenge(required, null, minLength, maxLength, false, 0, false);
        returnList.add(challenge);
    }
    return returnList;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Document(org.jdom2.Document) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Example 2 with ChaiChallenge

use of com.novell.ldapchai.cr.ChaiChallenge in project pwm by pwm-project.

the class CrService method applyPwmPolicyToNmasChallenges.

private static ChallengeSet applyPwmPolicyToNmasChallenges(final ChallengeSet challengeSet, final Configuration configuration) throws PwmUnrecoverableException {
    final List<Challenge> newChallenges = new ArrayList<>();
    final boolean applyWordlist = configuration.readSettingAsBoolean(PwmSetting.EDIRECTORY_CR_APPLY_WORDLIST);
    final int questionsInAnswer = (int) configuration.readSettingAsLong(PwmSetting.EDIRECTORY_CR_MAX_QUESTION_CHARS_IN__ANSWER);
    for (final Challenge challenge : challengeSet.getChallenges()) {
        newChallenges.add(new ChaiChallenge(challenge.isRequired(), challenge.getChallengeText(), challenge.getMinLength(), challenge.getMaxLength(), challenge.isAdminDefined(), questionsInAnswer, applyWordlist));
    }
    try {
        return new ChaiChallengeSet(newChallenges, challengeSet.getMinRandomRequired(), challengeSet.getLocale(), challengeSet.getIdentifier());
    } catch (ChaiValidationException e) {
        final String errorMsg = "unexpected error applying policies to nmas challengeset: " + e.getMessage();
        LOGGER.error(errorMsg, e);
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ArrayList(java.util.ArrayList) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Example 3 with ChaiChallenge

use of com.novell.ldapchai.cr.ChaiChallenge 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)

Example 4 with ChaiChallenge

use of com.novell.ldapchai.cr.ChaiChallenge in project ldapchai by ldapchai.

the class NmasResponseSet method parseNmasUserResponseXML.

static ChallengeSet parseNmasUserResponseXML(final String str) throws IOException, JDOMException, ChaiValidationException {
    final List<Challenge> returnList = new ArrayList<Challenge>();
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build(xmlreader);
    final Element rootElement = doc.getRootElement();
    final int minRandom = StringHelper.convertStrToInt(rootElement.getAttributeValue("RandomQuestions"), 0);
    final String guidValue;
    {
        final Attribute guidAttribute = rootElement.getAttribute("GUID");
        guidValue = guidAttribute == null ? null : guidAttribute.getValue();
    }
    for (Iterator iter = doc.getDescendants(new ElementFilter("Challenge")); iter.hasNext(); ) {
        final Element loopQ = (Element) iter.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 2);
        final String defineStrValue = loopQ.getAttributeValue("Define");
        final boolean adminDefined = "Admin".equalsIgnoreCase(defineStrValue);
        final String typeStrValue = loopQ.getAttributeValue("Type");
        final boolean required = "Required".equalsIgnoreCase(typeStrValue);
        final String challengeText = loopQ.getText();
        final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, adminDefined, 0, false);
        returnList.add(challenge);
    }
    return new ChaiChallengeSet(returnList, minRandom, null, guidValue);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Document(org.jdom2.Document) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Aggregations

ChaiChallenge (com.novell.ldapchai.cr.ChaiChallenge)4 Challenge (com.novell.ldapchai.cr.Challenge)4 ArrayList (java.util.ArrayList)4 ChaiChallengeSet (com.novell.ldapchai.cr.ChaiChallengeSet)3 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Iterator (java.util.Iterator)2 Document (org.jdom2.Document)2 Element (org.jdom2.Element)2 ElementFilter (org.jdom2.filter.ElementFilter)2 SAXBuilder (org.jdom2.input.SAXBuilder)2 ErrorInformation (password.pwm.error.ErrorInformation)2 Attribute (org.jdom2.Attribute)1 ChallengeItemConfiguration (password.pwm.config.value.data.ChallengeItemConfiguration)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1