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();
}
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");
}
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");
}
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");
}
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");
}
Aggregations