Search in sources :

Example 6 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class RemoteWebServiceValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public RemoteWebServiceValue fromJson(final String input) {
            if (input == null) {
                return new RemoteWebServiceValue(Collections.emptyList());
            } else {
                List<RemoteWebServiceConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<RemoteWebServiceConfiguration>>() {
                });
                srcList = srcList == null ? Collections.emptyList() : srcList;
                srcList.removeIf(Objects::isNull);
                return new RemoteWebServiceValue(Collections.unmodifiableList(srcList));
            }
        }

        public RemoteWebServiceValue fromXmlElement(final Element settingElement, final PwmSecurityKey pwmSecurityKey) throws PwmOperationalException {
            final List valueElements = settingElement.getChildren("value");
            final List<RemoteWebServiceConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0) {
                    final RemoteWebServiceConfiguration parsedValue = JsonUtil.deserialize(value, RemoteWebServiceConfiguration.class);
                    parsedValue.setPassword(decryptPwValue(parsedValue.getPassword(), pwmSecurityKey));
                    values.add(parsedValue);
                }
            }
            return new RemoteWebServiceValue(values);
        }
    };
}
Also used : RemoteWebServiceConfiguration(password.pwm.config.value.data.RemoteWebServiceConfiguration) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) Objects(java.util.Objects) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class StringArrayValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public StringArrayValue fromJson(final String input) {
            if (input == null) {
                return new StringArrayValue(Collections.<String>emptyList());
            } else {
                List<String> srcList = JsonUtil.deserializeStringList(input);
                srcList = srcList == null ? Collections.<String>emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new StringArrayValue(Collections.unmodifiableList(srcList));
            }
        }

        public StringArrayValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) {
            final List valueElements = settingElement.getChildren("value");
            final List<String> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                values.add(value);
            }
            return new StringArrayValue(values);
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class LocalizedStringArrayValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public LocalizedStringArrayValue fromJson(final String input) {
            if (input == null) {
                return new LocalizedStringArrayValue(Collections.<String, List<String>>emptyMap());
            } else {
                Map<String, List<String>> srcMap = JsonUtil.deserialize(input, new TypeToken<Map<String, List<String>>>() {
                });
                srcMap = srcMap == null ? Collections.<String, List<String>>emptyMap() : new TreeMap<>(srcMap);
                return new LocalizedStringArrayValue(Collections.unmodifiableMap(srcMap));
            }
        }

        public LocalizedStringArrayValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) {
            final List valueElements = settingElement.getChildren("value");
            final Map<String, List<String>> values = new TreeMap<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String localeString = loopValueElement.getAttributeValue("locale") == null ? "" : loopValueElement.getAttributeValue("locale");
                final String value = loopValueElement.getText();
                List<String> valueList = values.get(localeString);
                if (valueList == null) {
                    valueList = new ArrayList<>();
                    values.put(localeString, valueList);
                }
                valueList.add(value);
            }
            return new LocalizedStringArrayValue(values);
        }
    };
}
Also used : Element(org.jdom2.Element) TreeMap(java.util.TreeMap) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 9 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class NamedSecretValue method factory.

public static StoredValue.StoredValueFactory factory() {
    return new StoredValue.StoredValueFactory() {

        public NamedSecretValue fromJson(final String value) {
            try {
                final Map<String, NamedSecretData> values = JsonUtil.deserialize(value, new TypeToken<Map<String, NamedSecretData>>() {
                }.getType());
                final Map<String, NamedSecretData> linkedValues = new LinkedHashMap<>(values);
                return new NamedSecretValue(linkedValues);
            } catch (Exception e) {
                throw new IllegalStateException("NamedPasswordValue can not be json de-serialized: " + e.getMessage());
            }
        }

        public NamedSecretValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException, PwmUnrecoverableException {
            final Map<String, NamedSecretData> values = new LinkedHashMap<>();
            final List<Element> valueElements = settingElement.getChildren("value");
            try {
                if (valueElements != null) {
                    for (final Element value : valueElements) {
                        if (value.getChild(ELEMENT_NAME) != null && value.getChild(ELEMENT_PASSWORD) != null) {
                            final String name = value.getChild(ELEMENT_NAME).getText();
                            final String encodedValue = value.getChild(ELEMENT_PASSWORD).getText();
                            final PasswordData passwordData = new PasswordData(SecureEngine.decryptStringValue(encodedValue, key, PwmBlockAlgorithm.CONFIG));
                            final List<Element> usages = value.getChildren(ELEMENT_USAGE);
                            final List<String> strUsages = new ArrayList<>();
                            if (usages != null) {
                                for (final Element usageElement : usages) {
                                    strUsages.add(usageElement.getText());
                                }
                            }
                            values.put(name, new NamedSecretData(passwordData, Collections.unmodifiableList(strUsages)));
                        }
                    }
                }
            } catch (Exception e) {
                final String errorMsg = "unable to decode encrypted password value for setting: " + e.getMessage();
                final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, errorMsg);
                throw new PwmOperationalException(errorInfo);
            }
            return new NamedSecretValue(values);
        }
    };
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) ErrorInformation(password.pwm.error.ErrorInformation) NamedSecretData(password.pwm.config.value.data.NamedSecretData) PasswordData(password.pwm.util.PasswordData) TypeToken(com.google.gson.reflect.TypeToken)

Example 10 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class ActionValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public ActionValue fromJson(final String input) {
            if (input == null) {
                return new ActionValue(Collections.emptyList());
            } else {
                List<ActionConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<ActionConfiguration>>() {
                });
                srcList = srcList == null ? Collections.emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new ActionValue(Collections.unmodifiableList(srcList));
            }
        }

        public ActionValue fromXmlElement(final Element settingElement, final PwmSecurityKey pwmSecurityKey) throws PwmOperationalException {
            final boolean oldType = PwmSettingSyntax.STRING_ARRAY.toString().equals(settingElement.getAttributeValue("syntax"));
            final List valueElements = settingElement.getChildren("value");
            final List<ActionConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0) {
                    if (oldType) {
                        if (loopValueElement.getAttribute("locale") == null) {
                            values.add(ActionConfiguration.parseOldConfigString(value));
                        }
                    } else {
                        final ActionConfiguration parsedAc = JsonUtil.deserialize(value, ActionConfiguration.class);
                        parsedAc.setPassword(decryptPwValue(parsedAc.getPassword(), pwmSecurityKey));
                        values.add(parsedAc);
                    }
                }
            }
            return new ActionValue(values);
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Aggregations

PwmSecurityKey (password.pwm.util.secure.PwmSecurityKey)26 Element (org.jdom2.Element)19 ArrayList (java.util.ArrayList)15 List (java.util.List)11 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 Map (java.util.Map)4 ErrorInformation (password.pwm.error.ErrorInformation)4 PasswordData (password.pwm.util.PasswordData)4 TreeMap (java.util.TreeMap)3 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 LinkedHashMap (java.util.LinkedHashMap)2 PwmException (password.pwm.error.PwmException)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PwmSessionBean (password.pwm.http.bean.PwmSessionBean)2 PwmBlockAlgorithm (password.pwm.util.secure.PwmBlockAlgorithm)2 TypeToken (com.google.gson.reflect.TypeToken)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivateKey (java.security.PrivateKey)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1