use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class AbstractProfile method readVerificationMethods.
Set<IdentityVerificationMethod> readVerificationMethods(final PwmSetting pwmSetting, final VerificationMethodValue.EnabledState enabledState) {
final Set<IdentityVerificationMethod> result = new LinkedHashSet<>();
final StoredValue configValue = storedValueMap.get(pwmSetting);
final VerificationMethodValue.VerificationMethodSettings verificationMethodSettings = (VerificationMethodValue.VerificationMethodSettings) configValue.toNativeObject();
for (final IdentityVerificationMethod recoveryVerificationMethods : IdentityVerificationMethod.availableValues()) {
if (verificationMethodSettings.getMethodSettings().containsKey(recoveryVerificationMethods)) {
if (verificationMethodSettings.getMethodSettings().get(recoveryVerificationMethods).getEnabledState() == enabledState) {
result.add(recoveryVerificationMethods);
}
}
}
return result;
}
use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class AbstractProfile method readSettingAsEnum.
@Override
public <E extends Enum<E>> E readSettingAsEnum(final PwmSetting setting, final Class<E> enumClass) {
final StoredValue value = storedValueMap.get(setting);
final E returnValue = Configuration.JavaTypeConverter.valueToEnum(setting, value, enumClass);
if (MessageSendMethod.class.equals(enumClass)) {
Configuration.deprecatedSettingException(setting, this.getIdentifier(), (MessageSendMethod) returnValue);
}
return returnValue;
}
use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class AbstractProfile method makeValueMap.
static Map<PwmSetting, StoredValue> makeValueMap(final StoredConfiguration storedConfiguration, final String identifier, final PwmSettingCategory pwmSettingCategory) {
final Map<PwmSetting, StoredValue> valueMap = new LinkedHashMap<>();
final List<PwmSettingCategory> categories = new ArrayList<>();
categories.add(pwmSettingCategory);
categories.addAll(pwmSettingCategory.getChildCategories());
for (final PwmSettingCategory category : categories) {
for (final PwmSetting setting : category.getSettings()) {
final StoredValue value = storedConfiguration.readSetting(setting, identifier);
valueMap.put(setting, value);
}
}
return valueMap;
}
use of password.pwm.config.StoredValue 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.StoredValue in project pwm by pwm-project.
the class StoredConfigurationImpl method copyProfileID.
public void copyProfileID(final PwmSettingCategory category, final String sourceID, final String destinationID, final UserIdentity userIdentity) throws PwmUnrecoverableException {
if (!category.hasProfiles()) {
throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category " + category + ", category does not have profiles");
}
final List<String> existingProfiles = this.profilesForSetting(category.getProfileSetting());
if (!existingProfiles.contains(sourceID)) {
throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, source profileID '" + sourceID + "' does not exist");
}
if (existingProfiles.contains(destinationID)) {
throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, destination profileID '" + destinationID + "' already exists");
}
{
final Collection<PwmSettingCategory> interestedCategories = PwmSettingCategory.associatedProfileCategories(category);
for (final PwmSettingCategory interestedCategory : interestedCategories) {
for (final PwmSetting pwmSetting : interestedCategory.getSettings()) {
if (!isDefaultValue(pwmSetting, sourceID)) {
final StoredValue value = readSetting(pwmSetting, sourceID);
writeSetting(pwmSetting, destinationID, value, userIdentity);
}
}
}
}
final List<String> newProfileIDList = new ArrayList<>();
newProfileIDList.addAll(existingProfiles);
newProfileIDList.add(destinationID);
writeSetting(category.getProfileSetting(), new StringArrayValue(newProfileIDList), userIdentity);
}
Aggregations