use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class StoredConfigurationUtil method toJsonDebugObject.
public static Serializable toJsonDebugObject(final StoredConfiguration storedConfiguration) {
final TreeMap<String, Object> outputObject = new TreeMap<>();
for (final StoredConfigReference storedConfigReference : modifiedSettings(storedConfiguration)) {
final PwmSetting setting = PwmSetting.forKey(storedConfigReference.getRecordID());
if (setting != null) {
final StoredValue value = storedConfiguration.readSetting(setting, storedConfigReference.getProfileID());
outputObject.put(setting.getKey(), value.toDebugJsonObject(null));
}
}
return outputObject;
}
use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class ConfigGuideServlet method restWriteSetting.
@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
final String profileID = "default";
final String key = pwmRequest.readParameterAsString("key");
final String bodyString = pwmRequest.readRequestBodyAsString();
final PwmSetting setting = PwmSetting.forKey(key);
final ConfigGuideBean configGuideBean = getBean(pwmRequest);
final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
try {
final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
final List<String> errorMsgs = storedValue.validateValue(setting);
if (errorMsgs != null && !errorMsgs.isEmpty()) {
returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
}
if (setting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES) {
configGuideBean.getFormData().put(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA, JsonUtil.serialize((Serializable) storedValue.toNativeObject()));
}
} catch (Exception e) {
final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
LOGGER.error(errorMsg, e);
throw new IllegalStateException(errorMsg, e);
}
returnMap.put("key", key);
returnMap.put("category", setting.getCategory().toString());
returnMap.put("syntax", setting.getSyntax().toString());
returnMap.put("isDefault", storedConfigurationImpl.isDefaultValue(setting, profileID));
pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
return ProcessStatus.Halt;
}
use of password.pwm.config.StoredValue 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.StoredValue in project pwm by pwm-project.
the class HttpsServerCertificateManager method importKey.
public static void importKey(final StoredConfiguration storedConfiguration, final KeyStoreFormat keyStoreFormat, final InputStream inputStream, final PasswordData password, final String alias) throws PwmUnrecoverableException {
final char[] charPassword = password == null ? new char[0] : password.getStringValue().toCharArray();
final PrivateKeyCertificate privateKeyCertificate;
try {
final KeyStore keyStore = KeyStore.getInstance(keyStoreFormat.toString());
keyStore.load(inputStream, charPassword);
final String effectiveAlias;
{
final List<String> allAliases = new ArrayList<>();
for (final Enumeration enu = keyStore.aliases(); enu.hasMoreElements(); ) {
final String value = (String) enu.nextElement();
allAliases.add(value);
}
effectiveAlias = allAliases.size() == 1 ? allAliases.iterator().next() : alias;
}
final KeyStore.PasswordProtection passwordProtection = new KeyStore.PasswordProtection(charPassword);
final KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(effectiveAlias, passwordProtection);
if (entry == null) {
final String errorMsg = "unable to import https key entry with alias '" + alias + "'";
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_CERTIFICATE_ERROR, errorMsg, new String[] { "no key entry alias '" + alias + "' in keystore" }));
}
final PrivateKey key = entry.getPrivateKey();
final List<X509Certificate> certificates = Arrays.asList((X509Certificate[]) entry.getCertificateChain());
LOGGER.debug("importing certificate chain: " + JsonUtil.serializeCollection(X509Utils.makeDebugInfoMap(certificates)));
privateKeyCertificate = new PrivateKeyCertificate(certificates, key);
} catch (Exception e) {
final String errorMsg = "unable to load configured https certificate: " + e.getMessage();
final String[] errorDetail = new String[] { e.getMessage() };
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_CERTIFICATE_ERROR, errorMsg, errorDetail));
}
final StoredValue storedValue = new PrivateKeyValue(privateKeyCertificate);
storedConfiguration.writeSetting(PwmSetting.HTTPS_CERT, storedValue, null);
}
use of password.pwm.config.StoredValue in project pwm by pwm-project.
the class NGStoredConfiguration method readConfigProperty.
public String readConfigProperty(final ConfigurationProperty configurationProperty) {
final StoredConfigReference storedConfigReference = new StoredConfigReferenceBean(StoredConfigReference.RecordType.PROPERTY, configurationProperty.getKey(), null);
final StoredValue storedValue = engine.read(storedConfigReference);
if (storedValue == null | !(storedValue instanceof StringValue)) {
return null;
}
return (String) storedValue.toNativeObject();
}
Aggregations