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