Search in sources :

Example 1 with ChallengeItemConfiguration

use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.

the class ChallengeProfile method valueToChallengeItemArray.

static List<ChallengeItemConfiguration> valueToChallengeItemArray(final StoredValue value, final Locale locale) {
    if (!(value instanceof ChallengeValue)) {
        throw new IllegalArgumentException("may not read ChallengeValue value");
    }
    final Map<String, List<ChallengeItemConfiguration>> storedValues = (Map<String, List<ChallengeItemConfiguration>>) value.toNativeObject();
    final Map<Locale, List<ChallengeItemConfiguration>> availableLocaleMap = new LinkedHashMap<>();
    for (final Map.Entry<String, List<ChallengeItemConfiguration>> entry : storedValues.entrySet()) {
        final String localeStr = entry.getKey();
        availableLocaleMap.put(LocaleHelper.parseLocaleString(localeStr), entry.getValue());
    }
    final Locale matchedLocale = LocaleHelper.localeResolver(locale, availableLocaleMap.keySet());
    return availableLocaleMap.get(matchedLocale);
}
Also used : Locale(java.util.Locale) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) ChallengeValue(password.pwm.config.value.ChallengeValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ChallengeItemConfiguration

use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.

the class ChallengeValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public ChallengeValue fromJson(final String input) {
            if (input == null) {
                return new ChallengeValue(Collections.<String, List<ChallengeItemConfiguration>>emptyMap());
            } else {
                Map<String, List<ChallengeItemConfiguration>> srcMap = JsonUtil.deserialize(input, new TypeToken<Map<String, List<ChallengeItemConfiguration>>>() {
                });
                srcMap = srcMap == null ? Collections.<String, List<ChallengeItemConfiguration>>emptyMap() : new TreeMap<>(srcMap);
                return new ChallengeValue(Collections.unmodifiableMap(srcMap));
            }
        }

        public ChallengeValue fromXmlElement(final Element settingElement, final PwmSecurityKey input) {
            final List valueElements = settingElement.getChildren("value");
            final Map<String, List<ChallengeItemConfiguration>> values = new TreeMap<>();
            final boolean oldStyle = "LOCALIZED_STRING_ARRAY".equals(settingElement.getAttributeValue("syntax"));
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String localeString = loopValueElement.getAttributeValue("locale") == null ? "" : loopValueElement.getAttributeValue("locale");
                final String value = loopValueElement.getText();
                if (!values.containsKey(localeString)) {
                    values.put(localeString, new ArrayList<ChallengeItemConfiguration>());
                }
                final ChallengeItemConfiguration challengeItemBean;
                if (oldStyle) {
                    challengeItemBean = parseOldVersionString(value);
                } else {
                    challengeItemBean = JsonUtil.deserialize(value, ChallengeItemConfiguration.class);
                }
                if (challengeItemBean != null) {
                    values.get(localeString).add(challengeItemBean);
                }
            }
            return new ChallengeValue(values);
        }
    };
}
Also used : Element(org.jdom2.Element) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) TreeMap(java.util.TreeMap) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with ChallengeItemConfiguration

use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.

the class LocaleHelper method getConfigLocaleStats.

public static ConfigLocaleStats getConfigLocaleStats() throws PwmUnrecoverableException, PwmOperationalException {
    final ConfigLocaleStats configLocaleStats = new ConfigLocaleStats();
    {
        final StoredValue storedValue = PwmSetting.CHALLENGE_RANDOM_CHALLENGES.getDefaultValue(PwmSettingTemplateSet.getDefault());
        final Map<String, List<ChallengeItemConfiguration>> value = ((ChallengeValue) storedValue).toNativeObject();
        for (final String localeStr : value.keySet()) {
            final Locale loopLocale = LocaleHelper.parseLocaleString(localeStr);
            configLocaleStats.getDefaultChallenges().add(loopLocale);
        }
    }
    for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
        configLocaleStats.descriptionPresentLocalizations.put(locale, 0);
        configLocaleStats.descriptionMissingLocalizations.put(locale, 0);
    }
    for (final PwmSetting pwmSetting : PwmSetting.values()) {
        final String defaultValue = pwmSetting.getDescription(PwmConstants.DEFAULT_LOCALE);
        configLocaleStats.descriptionPresentLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionPresentLocalizations.get(PwmConstants.DEFAULT_LOCALE) + 1);
        for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
            if (!PwmConstants.DEFAULT_LOCALE.equals(locale)) {
                final String localeValue = pwmSetting.getDescription(locale);
                if (defaultValue.equals(localeValue)) {
                    configLocaleStats.descriptionMissingLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionMissingLocalizations.get(locale) + 1);
                } else {
                    configLocaleStats.descriptionPresentLocalizations.put(PwmConstants.DEFAULT_LOCALE, configLocaleStats.descriptionPresentLocalizations.get(locale) + 1);
                }
            }
        }
    }
    for (final Locale locale : LocaleInfoGenerator.knownLocales()) {
        final int totalCount = PwmSetting.values().length;
        final int presentCount = configLocaleStats.getDescriptionPresentLocalizations().get(locale);
        final Percent percent = new Percent(presentCount, totalCount);
        configLocaleStats.getDescriptionPercentLocalizations().put(locale, percent.pretty());
    }
    return configLocaleStats;
}
Also used : Locale(java.util.Locale) PwmSetting(password.pwm.config.PwmSetting) Percent(password.pwm.util.java.Percent) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) StoredValue(password.pwm.config.StoredValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with ChallengeItemConfiguration

use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.

the class ChallengeValue method toDebugString.

public String toDebugString(final Locale locale) {
    if (values == null) {
        return "No Actions";
    }
    final StringBuilder sb = new StringBuilder();
    for (final Map.Entry<String, List<ChallengeItemConfiguration>> entry : values.entrySet()) {
        final String localeKey = entry.getKey();
        final List<ChallengeItemConfiguration> challengeItems = entry.getValue();
        sb.append("Locale: ").append(LocaleHelper.debugLabel(LocaleHelper.parseLocaleString(localeKey))).append("\n");
        for (final ChallengeItemConfiguration challengeItemBean : challengeItems) {
            sb.append(" ChallengeItem: [AdminDefined: ").append(challengeItemBean.isAdminDefined());
            sb.append(" MinLength:").append(challengeItemBean.getMinLength());
            sb.append(" MaxLength:").append(challengeItemBean.getMaxLength());
            sb.append(" MaxQuestionCharsInAnswer:").append(challengeItemBean.getMaxQuestionCharsInAnswer());
            sb.append(" EnforceWordlist:").append(challengeItemBean.isEnforceWordlist());
            sb.append("]\n");
            sb.append("  Text:").append(challengeItemBean.getText()).append("\n");
        }
    }
    return sb.toString();
}
Also used : ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 5 with ChallengeItemConfiguration

use of password.pwm.config.value.data.ChallengeItemConfiguration in project pwm by pwm-project.

the class ChallengeValue method toXmlValues.

public List<Element> toXmlValues(final String valueElementName, final PwmSecurityKey pwmSecurityKey) {
    final List<Element> returnList = new ArrayList<>();
    for (final Map.Entry<String, List<ChallengeItemConfiguration>> entry : values.entrySet()) {
        final String locale = entry.getKey();
        for (final ChallengeItemConfiguration value : entry.getValue()) {
            if (value != null) {
                final Element valueElement = new Element(valueElementName);
                valueElement.addContent(new CDATA(JsonUtil.serialize(value)));
                if (locale != null && locale.length() > 0) {
                    valueElement.setAttribute("locale", locale);
                }
                returnList.add(valueElement);
            }
        }
    }
    return returnList;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ChallengeItemConfiguration(password.pwm.config.value.data.ChallengeItemConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) CDATA(org.jdom2.CDATA)

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