Search in sources :

Example 21 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project pwm by pwm-project.

the class FormUtility method populateFormMapFromLdap.

public static Map<FormConfiguration, List<String>> populateFormMapFromLdap(final List<FormConfiguration> formFields, final SessionLabel sessionLabel, final UserInfo userInfo, final Flag... flags) throws PwmUnrecoverableException {
    final boolean includeNulls = JavaHelper.enumArrayContainsValue(flags, Flag.ReturnEmptyValues);
    final List<String> formFieldNames = FormConfiguration.convertToListOfNames(formFields);
    LOGGER.trace(sessionLabel, "preparing to load form data from ldap for fields " + JsonUtil.serializeCollection(formFieldNames));
    final Map<String, List<String>> dataFromLdap = new LinkedHashMap<>();
    try {
        for (final FormConfiguration formConfiguration : formFields) {
            if (formConfiguration.getSource() == FormConfiguration.Source.ldap || formConfiguration.getSource() == null) {
                final String attribute = formConfiguration.getName();
                if (formConfiguration.isMultivalue()) {
                    final List<String> values = userInfo.readMultiStringAttribute(attribute);
                    if (includeNulls || (values != null && !values.isEmpty())) {
                        dataFromLdap.put(attribute, values);
                    }
                } else {
                    final String value = userInfo.readStringAttribute(attribute);
                    if (includeNulls || (value != null)) {
                        dataFromLdap.put(attribute, Collections.singletonList(value));
                    }
                }
            }
        }
    } catch (Exception e) {
        PwmError error = null;
        if (e instanceof ChaiException) {
            error = PwmError.forChaiError(((ChaiException) e).getErrorCode());
        }
        if (error == null || error == PwmError.ERROR_UNKNOWN) {
            error = PwmError.ERROR_LDAP_DATA_ERROR;
        }
        final ErrorInformation errorInformation = new ErrorInformation(error, "error reading current profile values: " + e.getMessage());
        LOGGER.error(sessionLabel, errorInformation.getDetailedErrorMsg());
        throw new PwmUnrecoverableException(errorInformation);
    }
    final Map<FormConfiguration, List<String>> returnMap = new LinkedHashMap<>();
    for (final FormConfiguration formItem : formFields) {
        final String attrName = formItem.getName();
        if (dataFromLdap.containsKey(attrName)) {
            final List<String> values = new ArrayList<>();
            for (final String value : dataFromLdap.get(attrName)) {
                final String parsedValue = parseInputValueToFormValue(formItem, value);
                values.add(parsedValue);
                LOGGER.trace(sessionLabel, "loaded value for form item '" + attrName + "' with value=" + value);
            }
            returnMap.put(formItem, values);
        }
    }
    return returnMap;
}
Also used : PwmError(password.pwm.error.PwmError) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmDataValidationException(password.pwm.error.PwmDataValidationException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) LinkedHashMap(java.util.LinkedHashMap) ErrorInformation(password.pwm.error.ErrorInformation) ArrayList(java.util.ArrayList) List(java.util.List) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 22 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project pwm by pwm-project.

the class LdapTokenMachine method removeToken.

public void removeToken(final TokenKey tokenKey) throws PwmOperationalException, PwmUnrecoverableException {
    final TokenPayload payload = retrieveToken(tokenKey);
    if (payload != null) {
        final UserIdentity userIdentity = payload.getUserIdentity();
        try {
            final ChaiUser chaiUser = pwmApplication.getProxiedChaiUser(userIdentity);
            chaiUser.deleteAttribute(tokenAttribute, null);
        } catch (ChaiException e) {
            final String errorMsg = "unexpected ldap error removing token: " + e.getMessage();
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
            throw new PwmOperationalException(errorInformation);
        }
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) UserIdentity(password.pwm.bean.UserIdentity) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 23 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project pwm by pwm-project.

the class LocalDbCrOperator method readResponseSet.

public ResponseSet readResponseSet(final ChaiUser theUser, final UserIdentity userIdentity, final String userGUID) throws PwmUnrecoverableException {
    if (userGUID == null || userGUID.length() < 1) {
        final String errorMsg = "unable to read guid for user " + userIdentity.toString() + ", unable to search for responses in LocalDB";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_GUID, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    if (localDB == null) {
        final String errorMsg = "LocalDB is not available, unable to search for user responses";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_LOCALDB_UNAVAILABLE, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    try {
        final String responseStringBlob = localDB.get(LocalDB.DB.RESPONSE_STORAGE, userGUID);
        if (responseStringBlob != null && responseStringBlob.length() > 0) {
            final ResponseSet userResponseSet = ChaiResponseSet.parseChaiResponseSetXML(responseStringBlob, theUser);
            LOGGER.debug("found user responses in LocalDB: " + userResponseSet.toString());
            return userResponseSet;
        }
    } catch (LocalDBException e) {
        final String errorMsg = "unexpected LocalDB error reading responses: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    } catch (ChaiException e) {
        final String errorMsg = "unexpected chai error reading responses from LocalDB: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    return null;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) ResponseSet(com.novell.ldapchai.cr.ResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LocalDBException(password.pwm.util.localdb.LocalDBException) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 24 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project pwm by pwm-project.

the class LocalDbCrOperator method writeResponses.

public void writeResponses(final UserIdentity userIdentity, final ChaiUser theUser, final String userGUID, final ResponseInfoBean responseInfoBean) throws PwmUnrecoverableException {
    if (userGUID == null || userGUID.length() < 1) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save responses to localDB, user does not have a pwmGUID"));
    }
    if (localDB == null || localDB.status() != LocalDB.Status.OPEN) {
        final String errorMsg = "LocalDB is not available, unable to write user responses";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_LOCALDB_UNAVAILABLE, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    try {
        final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(responseInfoBean.getCrMap(), responseInfoBean.getHelpdeskCrMap(), responseInfoBean.getLocale(), responseInfoBean.getMinRandoms(), theUser.getChaiProvider().getChaiConfiguration(), responseInfoBean.getCsIdentifier());
        localDB.put(LocalDB.DB.RESPONSE_STORAGE, userGUID, responseSet.stringValue());
        LOGGER.info("saved responses for user in LocalDB");
    } catch (LocalDBException e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_RESPONSES, "unexpected LocalDB error saving responses to localDB: " + e.getMessage());
        final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
        pwmOE.initCause(e);
        throw pwmOE;
    } catch (ChaiException e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_RESPONSES, "unexpected error saving responses to localDB: " + e.getMessage());
        final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
        pwmOE.initCause(e);
        throw pwmOE;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LocalDBException(password.pwm.util.localdb.LocalDBException) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 25 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project pwm by pwm-project.

the class LdapCrOperator method writeResponses.

public void writeResponses(final UserIdentity userIdentity, final ChaiUser theUser, final String userGuid, final ResponseInfoBean responseInfoBean) throws PwmUnrecoverableException {
    final LdapProfile ldapProfile = userIdentity.getLdapProfile(config);
    final String ldapStorageAttribute = ldapProfile.readSettingAsString(PwmSetting.CHALLENGE_USER_ATTRIBUTE);
    if (ldapStorageAttribute == null || ldapStorageAttribute.length() < 1) {
        final String errorMsg = "ldap storage attribute is not configured, unable to write user responses";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    try {
        final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(responseInfoBean.getCrMap(), responseInfoBean.getHelpdeskCrMap(), responseInfoBean.getLocale(), responseInfoBean.getMinRandoms(), theUser.getChaiProvider().getChaiConfiguration(), responseInfoBean.getCsIdentifier());
        ChaiCrFactory.writeChaiResponseSet(responseSet, theUser);
        LOGGER.info("saved responses for user to chai-ldap format");
    } catch (ChaiException e) {
        final String errorMsg;
        if (e.getErrorCode() == ChaiError.NO_ACCESS) {
            errorMsg = "permission error writing user responses to ldap attribute '" + ldapStorageAttribute + "', user does not appear to have correct permissions to save responses: " + e.getMessage();
        } else {
            errorMsg = "error writing user responses to ldap attribute '" + ldapStorageAttribute + "': " + e.getMessage();
        }
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_RESPONSES, errorMsg);
        final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
        pwmOE.initCause(e);
        throw pwmOE;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LdapProfile(password.pwm.config.profile.LdapProfile) ChaiException(com.novell.ldapchai.exception.ChaiException)

Aggregations

ChaiException (com.novell.ldapchai.exception.ChaiException)33 ErrorInformation (password.pwm.error.ErrorInformation)18 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)16 ChaiUser (com.novell.ldapchai.ChaiUser)15 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)9 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)6 UserIdentity (password.pwm.bean.UserIdentity)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 Instant (java.time.Instant)5 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)4 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)4 ArrayList (java.util.ArrayList)4 FormConfiguration (password.pwm.config.value.data.FormConfiguration)4 PasswordData (password.pwm.util.PasswordData)4 ResponseSet (com.novell.ldapchai.cr.ResponseSet)3 List (java.util.List)3 Map (java.util.Map)3 PwmApplication (password.pwm.PwmApplication)3 ChallengeSet (com.novell.ldapchai.cr.ChallengeSet)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2