Search in sources :

Example 1 with ChaiChallengeSet

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

the class NmasCrFactory method readNmasAssignedChallengeSetPolicy.

private static ChallengeSet readNmasAssignedChallengeSetPolicy(final ChaiProvider provider, final String challengeSetDN, final Locale locale, final String identifer) throws ChaiUnavailableException, ChaiOperationException, ChaiValidationException {
    if (challengeSetDN == null || challengeSetDN.length() < 1) {
        LOGGER.trace("challengeSetDN is null, return null for readNmasAssignedChallengeSetPolicy()");
        return null;
    }
    final List<Challenge> challenges = new ArrayList<>();
    final ChaiEntry csSetEntry = provider.getEntryFactory().newChaiEntry(challengeSetDN);
    final Map<String, String> allValues = csSetEntry.readStringAttributes(Collections.emptySet());
    final String requiredQuestions = allValues.get("nsimRequiredQuestions");
    final String randomQuestions = allValues.get("nsimRandomQuestions");
    try {
        if (requiredQuestions != null && requiredQuestions.length() > 0) {
            challenges.addAll(NmasResponseSet.parseNmasPolicyXML(requiredQuestions, locale));
        }
        if (randomQuestions != null && randomQuestions.length() > 0) {
            challenges.addAll(NmasResponseSet.parseNmasPolicyXML(randomQuestions, locale));
        }
    } catch (JDOMException e) {
        LOGGER.debug(e);
    } catch (IOException e) {
        LOGGER.debug(e);
    }
    final int minRandQuestions = StringHelper.convertStrToInt(allValues.get("nsimNumberRandomQuestions"), 0);
    return new ChaiChallengeSet(challenges, minRandQuestions, locale, identifer);
}
Also used : ArrayList(java.util.ArrayList) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) ChaiEntry(com.novell.ldapchai.ChaiEntry) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) Challenge(com.novell.ldapchai.cr.Challenge)

Example 2 with ChaiChallengeSet

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

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

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

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