Search in sources :

Example 6 with StoredValue

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) TreeMap(java.util.TreeMap) StoredValue(password.pwm.config.StoredValue)

Example 7 with StoredValue

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Serializable(java.io.Serializable) StoredValue(password.pwm.config.StoredValue) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with StoredValue

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);
}
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 9 with StoredValue

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);
}
Also used : PrivateKeyValue(password.pwm.config.value.PrivateKeyValue) Enumeration(java.util.Enumeration) PrivateKey(java.security.PrivateKey) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PrivateKeyCertificate(password.pwm.bean.PrivateKeyCertificate) StoredValue(password.pwm.config.StoredValue) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException) ErrorInformation(password.pwm.error.ErrorInformation) List(java.util.List) ArrayList(java.util.ArrayList)

Example 10 with StoredValue

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();
}
Also used : StoredValue(password.pwm.config.StoredValue) StringValue(password.pwm.config.value.StringValue)

Aggregations

StoredValue (password.pwm.config.StoredValue)21 PwmSetting (password.pwm.config.PwmSetting)11 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 PwmSettingCategory (password.pwm.config.PwmSettingCategory)4 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StringValue (password.pwm.config.value.StringValue)3 PwmException (password.pwm.error.PwmException)3 PwmOperationalException (password.pwm.error.PwmOperationalException)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 X509Certificate (java.security.cert.X509Certificate)2 ServletException (javax.servlet.ServletException)2 StringArrayValue (password.pwm.config.value.StringArrayValue)2 VerificationMethodValue (password.pwm.config.value.VerificationMethodValue)2 Serializable (java.io.Serializable)1 URISyntaxException (java.net.URISyntaxException)1