use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.
the class RemoteWebServiceValue method toXmlValues.
public List<Element> toXmlValues(final String valueElementName, final PwmSecurityKey pwmSecurityKey) {
final List<Element> returnList = new ArrayList<>();
for (final RemoteWebServiceConfiguration value : values) {
final Element valueElement = new Element(valueElementName);
final RemoteWebServiceConfiguration clonedValue = JsonUtil.cloneUsingJson(value, RemoteWebServiceConfiguration.class);
try {
clonedValue.setPassword(encryptPwValue(clonedValue.getPassword(), pwmSecurityKey));
} catch (PwmOperationalException e) {
LOGGER.warn("error decoding stored pw value: " + e.getMessage());
}
valueElement.addContent(JsonUtil.serialize(clonedValue));
returnList.add(valueElement);
}
return returnList;
}
use of password.pwm.error.PwmOperationalException 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.error.PwmOperationalException in project pwm by pwm-project.
the class LdapCertImportFunction method provideFunction.
@Override
public String provideFunction(final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration, final PwmSetting setting, final String profile, final String extraData) throws PwmOperationalException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final StringArrayValue ldapUrlsValue = (StringArrayValue) storedConfiguration.readSetting(PwmSetting.LDAP_SERVER_URLS, profile);
final Set<X509Certificate> resultCertificates = new LinkedHashSet<>();
try {
if (ldapUrlsValue != null && ldapUrlsValue.toNativeObject() != null) {
final List<String> ldapUrlStrings = ldapUrlsValue.toNativeObject();
for (final String ldapUrlString : ldapUrlStrings) {
final URI ldapURI = new URI(ldapUrlString);
final List<X509Certificate> certs = X509Utils.readRemoteCertificates(ldapURI);
if (certs != null) {
resultCertificates.addAll(certs);
}
}
}
} catch (Exception e) {
if (e instanceof PwmException) {
throw new PwmOperationalException(((PwmException) e).getErrorInformation());
}
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error importing certificates: " + e.getMessage());
throw new PwmOperationalException(errorInformation);
}
final UserIdentity userIdentity = pwmSession.isAuthenticated() ? pwmSession.getUserInfo().getUserIdentity() : null;
storedConfiguration.writeSetting(setting, profile, new X509CertificateValue(resultCertificates), userIdentity);
return Message.getLocalizedMessage(pwmSession.getSessionStateBean().getLocale(), Message.Success_Unknown, pwmApplication.getConfig());
}
use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.
the class ActionCertImportFunction method getUri.
@Override
String getUri(final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData) throws PwmOperationalException {
final ActionValue actionValue = (ActionValue) storedConfiguration.readSetting(pwmSetting, profile);
final String actionName = actionNameFromExtraData(extraData);
final ActionConfiguration action = actionValue.forName(actionName);
final String uriString = action.getUrl();
if (uriString == null || uriString.isEmpty()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " must first be configured");
throw new PwmOperationalException(errorInformation);
}
try {
URI.create(uriString);
} catch (IllegalArgumentException e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " has an invalid URL syntax");
throw new PwmOperationalException(errorInformation);
}
return uriString;
}
use of password.pwm.error.PwmOperationalException in project pwm by pwm-project.
the class OAuthCertImportFunction method getUri.
@Override
String getUri(final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData) throws PwmOperationalException {
final String uriString;
final String menuDebugLocation;
switch(pwmSetting) {
case OAUTH_ID_CERTIFICATE:
uriString = (String) storedConfiguration.readSetting(PwmSetting.OAUTH_ID_CODERESOLVE_URL).toNativeObject();
menuDebugLocation = PwmSetting.OAUTH_ID_CODERESOLVE_URL.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
break;
case RECOVERY_OAUTH_ID_CERTIFICATE:
uriString = (String) storedConfiguration.readSetting(PwmSetting.RECOVERY_OAUTH_ID_CODERESOLVE_URL, profile).toNativeObject();
menuDebugLocation = PwmSetting.RECOVERY_OAUTH_ID_CERTIFICATE.toMenuLocationDebug(profile, PwmConstants.DEFAULT_LOCALE);
break;
default:
JavaHelper.unhandledSwitchStatement(pwmSetting);
return null;
}
if (uriString.isEmpty()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + menuDebugLocation + " must first be configured");
throw new PwmOperationalException(errorInformation);
}
try {
URI.create(uriString);
} catch (IllegalArgumentException e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + menuDebugLocation + " has an invalid URL syntax");
throw new PwmOperationalException(errorInformation);
}
return uriString;
}
Aggregations