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