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