use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class PasswordValue method factory.
public static StoredValueFactory factory() {
return new StoredValueFactory() {
public PasswordValue fromJson(final String value) {
final String strValue = JsonUtil.deserialize(value, String.class);
if (strValue != null && !strValue.isEmpty()) {
try {
return new PasswordValue(new PasswordData(strValue));
} catch (PwmUnrecoverableException e) {
throw new IllegalStateException("PasswordValue can not be json de-serialized: " + e.getMessage());
}
}
return new PasswordValue();
}
public PasswordValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException, PwmUnrecoverableException {
final Element valueElement = settingElement.getChild("value");
final String rawValue = valueElement.getText();
final PasswordValue newPasswordValue = new PasswordValue();
if (rawValue == null || rawValue.isEmpty()) {
return newPasswordValue;
}
final boolean plainTextSetting;
{
final String plainTextAttributeStr = valueElement.getAttributeValue("plaintext");
plainTextSetting = plainTextAttributeStr != null && Boolean.parseBoolean(plainTextAttributeStr);
}
if (plainTextSetting) {
newPasswordValue.value = new PasswordData(rawValue);
newPasswordValue.requiresStoredUpdate = true;
} else {
try {
newPasswordValue.value = new PasswordData(SecureEngine.decryptStringValue(rawValue, key, PwmBlockAlgorithm.CONFIG));
return newPasswordValue;
} 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 newPasswordValue;
}
};
}
use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class FormValue method factory.
public static StoredValueFactory factory() {
return new StoredValueFactory() {
public FormValue fromJson(final String input) {
if (input == null) {
return new FormValue(Collections.<FormConfiguration>emptyList());
} else {
List<FormConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<FormConfiguration>>() {
});
srcList = srcList == null ? Collections.<FormConfiguration>emptyList() : srcList;
while (srcList.contains(null)) {
srcList.remove(null);
}
return new FormValue(Collections.unmodifiableList(srcList));
}
}
public FormValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException {
final boolean oldType = PwmSettingSyntax.LOCALIZED_STRING_ARRAY.toString().equals(settingElement.getAttributeValue("syntax"));
final List valueElements = settingElement.getChildren("value");
final List<FormConfiguration> values = new ArrayList<>();
for (final Object loopValue : valueElements) {
final Element loopValueElement = (Element) loopValue;
final String value = loopValueElement.getText();
if (value != null && value.length() > 0 && loopValueElement.getAttribute("locale") == null) {
if (oldType) {
values.add(FormConfiguration.parseOldConfigString(value));
} else {
values.add(JsonUtil.deserialize(value, FormConfiguration.class));
}
}
}
final FormValue formValue = new FormValue(values);
formValue.needsXmlUpdate = oldType;
return formValue;
}
};
}
use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class LocalizedStringValue method factory.
public static StoredValueFactory factory() {
return new StoredValueFactory() {
public LocalizedStringValue fromJson(final String input) {
if (input == null) {
return new LocalizedStringValue(Collections.emptyMap());
} else {
Map<String, String> srcMap = JsonUtil.deserialize(input, new TypeToken<Map<String, String>>() {
});
srcMap = srcMap == null ? Collections.emptyMap() : new TreeMap<>(srcMap);
return new LocalizedStringValue(Collections.unmodifiableMap(srcMap));
}
}
public LocalizedStringValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) {
final List elements = settingElement.getChildren("value");
final Map<String, String> values = new TreeMap<>();
for (final Object loopValue : elements) {
final Element loopValueElement = (Element) loopValue;
final String localeString = loopValueElement.getAttributeValue("locale");
final String value = loopValueElement.getText();
values.put(localeString == null ? "" : localeString, value);
}
return new LocalizedStringValue(values);
}
};
}
use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class UserPermissionValue method factory.
public static StoredValueFactory factory() {
return new StoredValueFactory() {
public UserPermissionValue fromJson(final String input) {
if (input == null) {
return new UserPermissionValue(Collections.<UserPermission>emptyList());
} else {
List<UserPermission> srcList = JsonUtil.deserialize(input, new TypeToken<List<UserPermission>>() {
});
srcList = srcList == null ? Collections.<UserPermission>emptyList() : srcList;
while (srcList.contains(null)) {
srcList.remove(null);
}
return new UserPermissionValue(Collections.unmodifiableList(srcList));
}
}
public UserPermissionValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException {
final boolean newType = "2".equals(settingElement.getAttributeValue(StoredConfigurationImpl.XML_ATTRIBUTE_SYNTAX_VERSION));
final List valueElements = settingElement.getChildren("value");
final List<UserPermission> values = new ArrayList<>();
for (final Object loopValue : valueElements) {
final Element loopValueElement = (Element) loopValue;
final String value = loopValueElement.getText();
if (value != null && !value.isEmpty()) {
if (newType) {
final UserPermission userPermission = JsonUtil.deserialize(value, UserPermission.class);
values.add(userPermission);
} else {
values.add(new UserPermission(UserPermission.Type.ldapQuery, null, value, null));
}
}
}
final UserPermissionValue userPermissionValue = new UserPermissionValue(values);
userPermissionValue.needsXmlUpdate = !newType;
return userPermissionValue;
}
};
}
use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class VerificationMethodValue method factory.
public static StoredValueFactory factory() {
return new StoredValueFactory() {
public VerificationMethodValue fromJson(final String input) {
if (input == null) {
return new VerificationMethodValue();
} else {
final VerificationMethodSettings settings = JsonUtil.deserialize(input, VerificationMethodSettings.class);
return new VerificationMethodValue(settings);
}
}
public VerificationMethodValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException {
final Element valueElement = settingElement.getChild("value");
final String inputStr = valueElement.getText();
final VerificationMethodSettings settings = JsonUtil.deserialize(inputStr, VerificationMethodSettings.class);
return new VerificationMethodValue(settings);
}
};
}
Aggregations