Search in sources :

Example 16 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ConfigResetHttpsCommand method doCommand.

public void doCommand() throws Exception {
    final File configurationFile = cliEnvironment.getConfigurationFile();
    if (configurationFile == null || !configurationFile.exists()) {
        out("configuration file is not present");
        return;
    }
    if (!promptForContinue("Proceeding will reset all https server settings to their default")) {
        return;
    }
    final ConfigurationReader configurationReader = new ConfigurationReader(cliEnvironment.getConfigurationFile());
    final StoredConfigurationImpl storedConfiguration = configurationReader.getStoredConfiguration();
    for (final PwmSetting setting : PwmSettingCategory.HTTPS_SERVER.getSettings()) {
        storedConfiguration.resetSetting(setting, null, null);
    }
    configurationReader.saveConfiguration(storedConfiguration, cliEnvironment.getPwmApplication(), SessionLabel.CLI_SESSION_LABEL);
    out("success");
}
Also used : PwmSetting(password.pwm.config.PwmSetting) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) File(java.io.File) ConfigurationReader(password.pwm.config.stored.ConfigurationReader)

Example 17 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ConfigUnlockCommand method doCommand.

public void doCommand() throws Exception {
    final ConfigurationReader configurationReader = cliEnvironment.getConfigurationReader();
    final StoredConfigurationImpl storedConfiguration = configurationReader.getStoredConfiguration();
    if (Boolean.parseBoolean(storedConfiguration.readConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE))) {
        out("configuration is already unlocked");
        return;
    }
    storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, Boolean.toString(true));
    configurationReader.saveConfiguration(storedConfiguration, cliEnvironment.getPwmApplication(), SessionLabel.CLI_SESSION_LABEL);
    out("success");
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ConfigurationReader(password.pwm.config.stored.ConfigurationReader)

Example 18 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ContextManager method checkConfigForSaveOnRestart.

private void checkConfigForSaveOnRestart(final ConfigurationReader configReader, final PwmApplication pwmApplication) {
    if (configReader == null || configReader.getStoredConfiguration() == null) {
        return;
    }
    final String saveConfigOnRestartStrValue = configReader.getStoredConfiguration().readConfigProperty(ConfigurationProperty.CONFIG_ON_START);
    if (saveConfigOnRestartStrValue == null || !Boolean.parseBoolean(saveConfigOnRestartStrValue)) {
        return;
    }
    LOGGER.warn("configuration file contains property \"" + ConfigurationProperty.CONFIG_ON_START + "\"=true, will save configuration and set property to false.");
    try {
        final StoredConfigurationImpl newConfig = StoredConfigurationImpl.copy(configReader.getStoredConfiguration());
        newConfig.writeConfigProperty(ConfigurationProperty.CONFIG_ON_START, "false");
        configReader.saveConfiguration(newConfig, pwmApplication, null);
        restartRequestedFlag = true;
    } catch (Exception e) {
        LOGGER.error("error while saving configuration file commanded by property \"" + ConfigurationProperty.CONFIG_ON_START + "\"=true, error: " + e.getMessage());
    }
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException)

Example 19 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl 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)

Example 20 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl 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

StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)34 PwmException (password.pwm.error.PwmException)11 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)11 IOException (java.io.IOException)9 ServletException (javax.servlet.ServletException)9 PwmSetting (password.pwm.config.PwmSetting)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 LinkedHashMap (java.util.LinkedHashMap)8 ConfigurationReader (password.pwm.config.stored.ConfigurationReader)7 ErrorInformation (password.pwm.error.ErrorInformation)7 PwmOperationalException (password.pwm.error.PwmOperationalException)7 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)7 ConfigGuideBean (password.pwm.http.bean.ConfigGuideBean)6 ArrayList (java.util.ArrayList)5 PwmApplication (password.pwm.PwmApplication)5 StoredValue (password.pwm.config.StoredValue)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 RestResultBean (password.pwm.ws.server.RestResultBean)5 Instant (java.time.Instant)4 List (java.util.List)4