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