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