use of password.pwm.config.PwmSetting 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.PwmSetting 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);
}
use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class StoredConfigurationImpl method validateValues.
public List<String> validateValues() {
final long startTime = System.currentTimeMillis();
final List<String> errorStrings = new ArrayList<>();
for (final PwmSetting loopSetting : PwmSetting.values()) {
if (loopSetting.getCategory().hasProfiles()) {
for (final String profile : profilesForSetting(loopSetting)) {
final StoredValue loopValue = readSetting(loopSetting, profile);
try {
final List<String> errors = loopValue.validateValue(loopSetting);
for (final String loopError : errors) {
errorStrings.add(loopSetting.toMenuLocationDebug(profile, PwmConstants.DEFAULT_LOCALE) + " - " + loopError);
}
} catch (Exception e) {
LOGGER.error("unexpected error during validate value for " + loopSetting.toMenuLocationDebug(profile, PwmConstants.DEFAULT_LOCALE) + ", error: " + e.getMessage(), e);
}
}
} else {
final StoredValue loopValue = readSetting(loopSetting);
try {
final List<String> errors = loopValue.validateValue(loopSetting);
for (final String loopError : errors) {
errorStrings.add(loopSetting.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE) + " - " + loopError);
}
} catch (Exception e) {
LOGGER.error("unexpected error during validate value for " + loopSetting.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE) + ", error: " + e.getMessage(), e);
}
}
}
LOGGER.trace("StoredConfiguration validator completed in " + TimeDuration.fromCurrent(startTime).asCompactString());
return errorStrings;
}
use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class StoredConfigurationUtil method profilesForProfileSetting.
private static List<String> profilesForProfileSetting(final PwmSetting pwmSetting, final StoredConfiguration storedConfiguration) {
if (!pwmSetting.getCategory().hasProfiles() && pwmSetting.getSyntax() != PwmSettingSyntax.PROFILE) {
throw new IllegalArgumentException("cannot build profile list for non-profile setting " + pwmSetting.toString());
}
final PwmSetting profileSetting;
if (pwmSetting.getSyntax() == PwmSettingSyntax.PROFILE) {
profileSetting = pwmSetting;
} else {
profileSetting = pwmSetting.getCategory().getProfileSetting();
}
final Object nativeObject = storedConfiguration.readSetting(profileSetting).toNativeObject();
final List<String> settingValues = (List<String>) nativeObject;
final LinkedList<String> profiles = new LinkedList<>();
profiles.addAll(settingValues);
for (final Iterator<String> iterator = profiles.iterator(); iterator.hasNext(); ) {
final String profile = iterator.next();
if (profile == null || profile.length() < 1) {
iterator.remove();
}
}
return Collections.unmodifiableList(profiles);
}
use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class CertificateChecker method doActionHealthCheck.
private static List<HealthRecord> doActionHealthCheck(final Configuration configuration) throws PwmUnrecoverableException {
final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
final List<HealthRecord> returnList = new ArrayList<>();
final List<StoredConfigReference> modifiedReferences = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
for (final StoredConfigReference storedConfigReference : modifiedReferences) {
if (storedConfigReference.getRecordType() == StoredConfigReference.RecordType.SETTING) {
final PwmSetting pwmSetting = PwmSetting.forKey(storedConfigReference.getRecordID());
if (pwmSetting != null && pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
final ActionValue value = (ActionValue) storedConfiguration.readSetting(pwmSetting, storedConfigReference.getProfileID());
for (final ActionConfiguration actionConfiguration : value.toNativeObject()) {
final List<X509Certificate> certificates = actionConfiguration.getCertificates();
returnList.addAll(doHealthCheck(configuration, pwmSetting, storedConfigReference.getProfileID(), certificates));
}
}
}
}
return Collections.unmodifiableList(returnList);
}
Aggregations