Search in sources :

Example 6 with ConfigurationReader

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

the class MainClass method createEnv.

private static CliEnvironment createEnv(final CliParameters parameters, final List<String> args) throws Exception {
    final Map<String, Object> options = parseCommandOptions(parameters, args);
    final File applicationPath = figureApplicationPath(mainOptions);
    out("applicationPath=" + applicationPath.getAbsolutePath());
    PwmEnvironment.verifyApplicationPath(applicationPath);
    final File configurationFile = locateConfigurationFile(applicationPath);
    final ConfigurationReader configReader = loadConfiguration(configurationFile);
    final Configuration config = configReader.getConfiguration();
    final PwmApplication pwmApplication;
    final LocalDB localDB;
    if (parameters.needsPwmApplication) {
        pwmApplication = loadPwmApplication(applicationPath, mainOptions.getApplicationFlags(), config, configurationFile, parameters.readOnly);
        localDB = pwmApplication.getLocalDB();
    } else if (parameters.needsLocalDB) {
        pwmApplication = null;
        localDB = loadPwmDB(config, parameters.readOnly, applicationPath);
    } else {
        pwmApplication = null;
        localDB = null;
    }
    out("environment initialized");
    out("");
    final Writer outputStream = new OutputStreamWriter(System.out, PwmConstants.DEFAULT_CHARSET);
    return CliEnvironment.builder().configurationReader(configReader).configurationFile(configurationFile).config(config).applicationPath(applicationPath).pwmApplication(pwmApplication).localDB(localDB).debugWriter(outputStream).options(options).mainOptions(mainOptions).build();
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) LocalDB(password.pwm.util.localdb.LocalDB) ConfigurationReader(password.pwm.config.stored.ConfigurationReader) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 7 with ConfigurationReader

use of password.pwm.config.stored.ConfigurationReader 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 8 with ConfigurationReader

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

Example 9 with ConfigurationReader

use of password.pwm.config.stored.ConfigurationReader 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 10 with ConfigurationReader

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

Aggregations

ConfigurationReader (password.pwm.config.stored.ConfigurationReader)13 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)7 File (java.io.File)5 PwmApplication (password.pwm.PwmApplication)4 ErrorInformation (password.pwm.error.ErrorInformation)3 PwmException (password.pwm.error.PwmException)3 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 IOException (java.io.IOException)2 Instant (java.time.Instant)2 ServletException (javax.servlet.ServletException)2 Configuration (password.pwm.config.Configuration)2 FileInputStream (java.io.FileInputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Timer (java.util.Timer)1 PwmApplicationMode (password.pwm.PwmApplicationMode)1 PwmEnvironment (password.pwm.PwmEnvironment)1 PwmSetting (password.pwm.config.PwmSetting)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 ContextManager (password.pwm.http.ContextManager)1