Search in sources :

Example 21 with PwmSetting

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;
}
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 22 with PwmSetting

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);
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmSettingCategory(password.pwm.config.PwmSettingCategory) ArrayList(java.util.ArrayList) Collection(java.util.Collection) StoredValue(password.pwm.config.StoredValue) StringArrayValue(password.pwm.config.value.StringArrayValue)

Example 23 with PwmSetting

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ArrayList(java.util.ArrayList) StoredValue(password.pwm.config.StoredValue) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 24 with PwmSetting

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);
}
Also used : PwmSetting(password.pwm.config.PwmSetting) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 25 with PwmSetting

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);
}
Also used : StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ActionValue(password.pwm.config.value.ActionValue) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) X509Certificate(java.security.cert.X509Certificate)

Aggregations

PwmSetting (password.pwm.config.PwmSetting)32 ArrayList (java.util.ArrayList)15 StoredValue (password.pwm.config.StoredValue)12 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)11 LinkedHashMap (java.util.LinkedHashMap)9 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)9 PwmSettingCategory (password.pwm.config.PwmSettingCategory)8 PwmException (password.pwm.error.PwmException)8 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)7 IOException (java.io.IOException)6 TreeMap (java.util.TreeMap)6 PwmOperationalException (password.pwm.error.PwmOperationalException)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)4 List (java.util.List)4 StringTokenizer (java.util.StringTokenizer)4 ServletException (javax.servlet.ServletException)4 UserIdentity (password.pwm.bean.UserIdentity)4 Configuration (password.pwm.config.Configuration)4 ErrorInformation (password.pwm.error.ErrorInformation)4