Search in sources :

Example 16 with StoredValue

use of password.pwm.config.StoredValue 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 17 with StoredValue

use of password.pwm.config.StoredValue in project pwm by pwm-project.

the class StoredConfigurationImpl method isDefaultValue.

public boolean isDefaultValue(final PwmSetting setting, final String profileID) {
    domModifyLock.readLock().lock();
    try {
        final StoredValue currentValue = readSetting(setting, profileID);
        if (setting.getSyntax() == PwmSettingSyntax.PASSWORD) {
            return currentValue == null || currentValue.toNativeObject() == null;
        }
        final StoredValue defaultValue = defaultValue(setting, this.getTemplateSet());
        final String currentJsonValue = JsonUtil.serialize((Serializable) currentValue.toNativeObject());
        final String defaultJsonValue = JsonUtil.serialize((Serializable) defaultValue.toNativeObject());
        return defaultJsonValue.equalsIgnoreCase(currentJsonValue);
    } finally {
        domModifyLock.readLock().unlock();
    }
}
Also used : StoredValue(password.pwm.config.StoredValue)

Example 18 with StoredValue

use of password.pwm.config.StoredValue in project pwm by pwm-project.

the class NGStoredConfiguration method isDefaultValue.

public boolean isDefaultValue(final PwmSetting setting, final String profileID) {
    final StoredConfigReference storedConfigReference = new StoredConfigReferenceBean(StoredConfigReference.RecordType.SETTING, setting.getKey(), profileID);
    final StoredValue value = engine.read(storedConfigReference);
    return value == null;
}
Also used : StoredValue(password.pwm.config.StoredValue)

Example 19 with StoredValue

use of password.pwm.config.StoredValue in project pwm by pwm-project.

the class NGStoredConfiguration method writeConfigProperty.

public void writeConfigProperty(final ConfigurationProperty configurationProperty, final String value) {
    final StoredConfigReference storedConfigReference = new StoredConfigReferenceBean(StoredConfigReference.RecordType.PROPERTY, configurationProperty.getKey(), null);
    final StoredValue storedValue = new StringValue(value);
    engine.write(storedConfigReference, storedValue, null);
}
Also used : StoredValue(password.pwm.config.StoredValue) StringValue(password.pwm.config.value.StringValue)

Example 20 with StoredValue

use of password.pwm.config.StoredValue in project pwm by pwm-project.

the class ConfigGuideForm method generateStoredConfig.

public static StoredConfigurationImpl generateStoredConfig(final ConfigGuideBean configGuideBean) throws PwmUnrecoverableException {
    final Map<ConfigGuideFormField, String> formData = configGuideBean.getFormData();
    final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl.newStoredConfiguration();
    // templates
    updateStoredConfigTemplateValue(formData, storedConfiguration, PwmSetting.TEMPLATE_LDAP, ConfigGuideFormField.PARAM_TEMPLATE_LDAP, PwmSettingTemplate.Type.LDAP_VENDOR);
    updateStoredConfigTemplateValue(formData, storedConfiguration, PwmSetting.TEMPLATE_STORAGE, ConfigGuideFormField.PARAM_TEMPLATE_STORAGE, PwmSettingTemplate.Type.STORAGE);
    updateStoredConfigTemplateValue(formData, storedConfiguration, PwmSetting.DB_VENDOR_TEMPLATE, ConfigGuideFormField.PARAM_DB_VENDOR, PwmSettingTemplate.Type.DB_VENDOR);
    // establish a default ldap profile
    storedConfiguration.writeSetting(PwmSetting.LDAP_PROFILE_LIST, null, new StringArrayValue(Collections.singletonList(LDAP_PROFILE_NAME)), null);
    {
        final String newLdapURI = figureLdapUrlFromFormConfig(formData);
        final StringArrayValue newValue = new StringArrayValue(Collections.singletonList(newLdapURI));
        storedConfiguration.writeSetting(PwmSetting.LDAP_SERVER_URLS, LDAP_PROFILE_NAME, newValue, null);
    }
    if (configGuideBean.isUseConfiguredCerts()) {
        final StoredValue newStoredValue = new X509CertificateValue(configGuideBean.getLdapCertificates());
        storedConfiguration.writeSetting(PwmSetting.LDAP_SERVER_CERTS, LDAP_PROFILE_NAME, newStoredValue, null);
    }
    {
        // proxy/admin account
        final String ldapAdminDN = formData.get(ConfigGuideFormField.PARAM_LDAP_PROXY_DN);
        final String ldapAdminPW = formData.get(ConfigGuideFormField.PARAM_LDAP_PROXY_PW);
        storedConfiguration.writeSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_NAME, new StringValue(ldapAdminDN), null);
        final PasswordValue passwordValue = new PasswordValue(PasswordData.forStringValue(ldapAdminPW));
        storedConfiguration.writeSetting(PwmSetting.LDAP_PROXY_USER_PASSWORD, LDAP_PROFILE_NAME, passwordValue, null);
    }
    storedConfiguration.writeSetting(PwmSetting.LDAP_CONTEXTLESS_ROOT, LDAP_PROFILE_NAME, new StringArrayValue(Collections.singletonList(formData.get(ConfigGuideFormField.PARAM_LDAP_CONTEXT))), null);
    {
        final String ldapContext = formData.get(ConfigGuideFormField.PARAM_LDAP_CONTEXT);
        storedConfiguration.writeSetting(PwmSetting.LDAP_CONTEXTLESS_ROOT, LDAP_PROFILE_NAME, new StringArrayValue(Collections.singletonList(ldapContext)), null);
    }
    {
        final boolean testuserEnabled = Boolean.parseBoolean(formData.get(ConfigGuideFormField.PARAM_LDAP_TEST_USER_ENABLED));
        if (testuserEnabled) {
            final String ldapTestUserDN = formData.get(ConfigGuideFormField.PARAM_LDAP_TEST_USER);
            storedConfiguration.writeSetting(PwmSetting.LDAP_TEST_USER_DN, LDAP_PROFILE_NAME, new StringValue(ldapTestUserDN), null);
        } else {
            storedConfiguration.resetSetting(PwmSetting.LDAP_TEST_USER_DN, LDAP_PROFILE_NAME, null);
        }
    }
    {
        // set admin query
        final String groupDN = formData.get(ConfigGuideFormField.PARAM_LDAP_ADMIN_GROUP);
        final List<UserPermission> userPermissions = Collections.singletonList(new UserPermission(UserPermission.Type.ldapGroup, null, null, groupDN));
        storedConfiguration.writeSetting(PwmSetting.QUERY_MATCH_PWM_ADMIN, new UserPermissionValue(userPermissions), null);
    }
    {
        // database
        final String dbClass = formData.get(ConfigGuideFormField.PARAM_DB_CLASSNAME);
        storedConfiguration.writeSetting(PwmSetting.DATABASE_CLASS, null, new StringValue(dbClass), null);
        final String dbUrl = formData.get(ConfigGuideFormField.PARAM_DB_CONNECT_URL);
        storedConfiguration.writeSetting(PwmSetting.DATABASE_URL, null, new StringValue(dbUrl), null);
        final String dbUser = formData.get(ConfigGuideFormField.PARAM_DB_USERNAME);
        storedConfiguration.writeSetting(PwmSetting.DATABASE_USERNAME, null, new StringValue(dbUser), null);
        final String dbPassword = formData.get(ConfigGuideFormField.PARAM_DB_PASSWORD);
        final PasswordValue passwordValue = new PasswordValue(PasswordData.forStringValue(dbPassword));
        storedConfiguration.writeSetting(PwmSetting.DATABASE_PASSWORD, null, passwordValue, null);
        final FileValue jdbcDriver = configGuideBean.getDatabaseDriver();
        if (jdbcDriver != null) {
            storedConfiguration.writeSetting(PwmSetting.DATABASE_JDBC_DRIVER, null, jdbcDriver, null);
        }
    }
    {
        // telemetry
        final boolean telemetryEnabled = Boolean.parseBoolean(formData.get(ConfigGuideFormField.PARAM_TELEMETRY_ENABLE));
        storedConfiguration.writeSetting(PwmSetting.PUBLISH_STATS_ENABLE, null, new BooleanValue(telemetryEnabled), null);
        final String siteDescription = formData.get(ConfigGuideFormField.PARAM_TELEMETRY_DESCRIPTION);
        storedConfiguration.writeSetting(PwmSetting.PUBLISH_STATS_SITE_DESCRIPTION, null, new StringValue(siteDescription), null);
    }
    // cr policy
    if (formData.containsKey(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA)) {
        final String stringValue = formData.get(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA);
        final StoredValue challengeValue = ChallengeValue.factory().fromJson(stringValue);
        storedConfiguration.writeSetting(PwmSetting.CHALLENGE_RANDOM_CHALLENGES, "default", challengeValue, null);
    }
    // set site url
    storedConfiguration.writeSetting(PwmSetting.PWM_SITE_URL, new StringValue(formData.get(ConfigGuideFormField.PARAM_APP_SITEURL)), null);
    // enable debug mode
    storedConfiguration.writeSetting(PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS, null, new BooleanValue(true), null);
    return storedConfiguration;
}
Also used : FileValue(password.pwm.config.value.FileValue) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) StoredValue(password.pwm.config.StoredValue) UserPermissionValue(password.pwm.config.value.UserPermissionValue) X509CertificateValue(password.pwm.config.value.X509CertificateValue) PasswordValue(password.pwm.config.value.PasswordValue) BooleanValue(password.pwm.config.value.BooleanValue) List(java.util.List) StringValue(password.pwm.config.value.StringValue) StringArrayValue(password.pwm.config.value.StringArrayValue) UserPermission(password.pwm.config.value.data.UserPermission)

Aggregations

StoredValue (password.pwm.config.StoredValue)21 PwmSetting (password.pwm.config.PwmSetting)11 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 PwmSettingCategory (password.pwm.config.PwmSettingCategory)4 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StringValue (password.pwm.config.value.StringValue)3 PwmException (password.pwm.error.PwmException)3 PwmOperationalException (password.pwm.error.PwmOperationalException)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 X509Certificate (java.security.cert.X509Certificate)2 ServletException (javax.servlet.ServletException)2 StringArrayValue (password.pwm.config.value.StringArrayValue)2 VerificationMethodValue (password.pwm.config.value.VerificationMethodValue)2 Serializable (java.io.Serializable)1 URISyntaxException (java.net.URISyntaxException)1