Search in sources :

Example 41 with PwmOperationalException

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;
}
Also used : RemoteWebServiceConfiguration(password.pwm.config.value.data.RemoteWebServiceConfiguration) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 42 with PwmOperationalException

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);
        }
    };
}
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 43 with PwmOperationalException

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PwmApplication(password.pwm.PwmApplication) UserIdentity(password.pwm.bean.UserIdentity) URI(java.net.URI) X509Certificate(java.security.cert.X509Certificate) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException) X509CertificateValue(password.pwm.config.value.X509CertificateValue) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmSession(password.pwm.http.PwmSession) StringArrayValue(password.pwm.config.value.StringArrayValue)

Example 44 with PwmOperationalException

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ActionValue(password.pwm.config.value.ActionValue) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 45 with PwmOperationalException

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

PwmOperationalException (password.pwm.error.PwmOperationalException)134 ErrorInformation (password.pwm.error.ErrorInformation)104 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)57 UserIdentity (password.pwm.bean.UserIdentity)39 PwmApplication (password.pwm.PwmApplication)27 PwmSession (password.pwm.http.PwmSession)26 ChaiUser (com.novell.ldapchai.ChaiUser)20 Configuration (password.pwm.config.Configuration)19 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)17 UserSearchEngine (password.pwm.ldap.search.UserSearchEngine)17 FormConfiguration (password.pwm.config.value.data.FormConfiguration)16 PwmException (password.pwm.error.PwmException)16 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)15 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)14 Instant (java.time.Instant)13 LinkedHashMap (java.util.LinkedHashMap)13 MacroMachine (password.pwm.util.macro.MacroMachine)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 UserInfo (password.pwm.ldap.UserInfo)11