Search in sources :

Example 11 with StoredConfigurationImpl

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

the class ConfigManagerCertificatesServlet method makeCertificateDebugData.

List<CertificateDebugDataItem> makeCertificateDebugData(final Configuration configuration) throws PwmUnrecoverableException {
    final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
    final List<StoredConfigReference> modifiedSettings = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
    final List<CertificateDebugDataItem> certificateDebugDataItems = new ArrayList<>();
    for (final StoredConfigReference ref : modifiedSettings) {
        if (ref.getRecordType() == StoredConfigReference.RecordType.SETTING) {
            final PwmSetting pwmSetting = PwmSetting.forKey(ref.getRecordID());
            if (pwmSetting.getSyntax() == PwmSettingSyntax.X509CERT) {
                final StoredValue storedValue;
                if (pwmSetting.getCategory().hasProfiles()) {
                    storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
                } else {
                    storedValue = storedConfiguration.readSetting(pwmSetting);
                }
                final X509Certificate[] arrayCerts = (X509Certificate[]) storedValue.toNativeObject();
                final List<X509Certificate> certificates = arrayCerts == null ? Collections.emptyList() : Arrays.asList(arrayCerts);
                certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
            } else if (pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
                final StoredValue storedValue;
                if (pwmSetting.getCategory().hasProfiles()) {
                    storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
                } else {
                    storedValue = storedConfiguration.readSetting(pwmSetting);
                }
                final List<ActionConfiguration> actionConfigurations = (List) storedValue.toNativeObject();
                for (final ActionConfiguration actionConfiguration : actionConfigurations) {
                    final List<X509Certificate> certificates = actionConfiguration.getCertificates();
                    certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
                }
            }
        }
    }
    Collections.sort(certificateDebugDataItems);
    return Collections.unmodifiableList(certificateDebugDataItems);
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ArrayList(java.util.ArrayList) StoredValue(password.pwm.config.StoredValue) X509Certificate(java.security.cert.X509Certificate) StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 12 with StoredConfigurationImpl

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

the class ConfigNewCommand method doCommand.

public void doCommand() throws Exception {
    final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl.newStoredConfiguration();
    storedConfiguration.initNewRandomSecurityKey();
    storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, Boolean.toString(true));
    storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_EPOCH, String.valueOf(0));
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile, false)) {
        storedConfiguration.toXml(fileOutputStream);
    }
    out("success");
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 13 with StoredConfigurationImpl

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

the class ConfigSetPasswordCommand method doCommand.

public void doCommand() throws Exception {
    final ConfigurationReader configurationReader = cliEnvironment.getConfigurationReader();
    final StoredConfigurationImpl storedConfiguration = configurationReader.getStoredConfiguration();
    final String password = getOptionalPassword();
    storedConfiguration.setPassword(password);
    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 14 with StoredConfigurationImpl

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

the class ImportHttpsKeyStoreCommand method doCommand.

@Override
void doCommand() throws Exception {
    final File inputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_EXISTING_INPUT_FILE.getName());
    if (inputFile == null || !inputFile.exists()) {
        out(CliParameters.REQUIRED_EXISTING_INPUT_FILE.getName() + " does not exist");
        return;
    }
    final String formatString = (String) cliEnvironment.getOptions().get(FORMAT_OPTIONNAME);
    final HttpsServerCertificateManager.KeyStoreFormat format;
    try {
        format = HttpsServerCertificateManager.KeyStoreFormat.valueOf(formatString);
    } catch (IllegalArgumentException e) {
        out("unknown format '" + formatString + "', must be one of " + StringUtil.join(HttpsServerCertificateManager.KeyStoreFormat.values(), ","));
        return;
    }
    final String keyStorePassword = getOptionalPassword();
    final String inputAliasName = (String) cliEnvironment.getOptions().get(ALIAS_OPTIONNAME);
    final ConfigurationReader configurationReader = new ConfigurationReader(cliEnvironment.getConfigurationFile());
    final StoredConfigurationImpl storedConfiguration = configurationReader.getStoredConfiguration();
    try (FileInputStream fileInputStream = new FileInputStream(inputFile)) {
        HttpsServerCertificateManager.importKey(storedConfiguration, format, fileInputStream, new PasswordData(keyStorePassword), inputAliasName);
    } catch (Exception e) {
        out("unable to load configured https certificate: " + e.getMessage());
        return;
    }
    configurationReader.saveConfiguration(storedConfiguration, cliEnvironment.getPwmApplication(), SessionLabel.CLI_SESSION_LABEL);
    out("success");
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PasswordData(password.pwm.util.PasswordData) HttpsServerCertificateManager(password.pwm.util.secure.HttpsServerCertificateManager) File(java.io.File) ConfigurationReader(password.pwm.config.stored.ConfigurationReader) FileInputStream(java.io.FileInputStream)

Example 15 with StoredConfigurationImpl

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

the class ConfigLockCommand 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 locked");
        return;
    }
    storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, Boolean.toString(false));
    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)

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