use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class DbCrOperator method writeResponses.
@Override
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 remote database, user " + theUser.getEntryDN() + " does not have a guid"));
}
LOGGER.trace("attempting to save responses for " + theUser.getEntryDN() + " in remote database (key=" + userGUID + ")");
try {
final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(responseInfoBean.getCrMap(), responseInfoBean.getHelpdeskCrMap(), responseInfoBean.getLocale(), responseInfoBean.getMinRandoms(), theUser.getChaiProvider().getChaiConfiguration(), responseInfoBean.getCsIdentifier());
final DatabaseAccessor databaseAccessor = pwmApplication.getDatabaseService().getAccessor();
databaseAccessor.put(DatabaseTable.PWM_RESPONSES, userGUID, responseSet.stringValue());
LOGGER.info("saved responses for " + theUser.getEntryDN() + " in remote database (key=" + userGUID + ")");
} catch (ChaiException e) {
throw PwmUnrecoverableException.fromChaiException(e);
} catch (DatabaseException e) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_RESPONSES, "unexpected error saving responses for " + theUser.getEntryDN() + " in remote database: " + e.getMessage());
final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
LOGGER.error(errorInfo.toDebugStr());
pwmOE.initCause(e);
throw pwmOE;
}
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class DbCrOperator method clearResponses.
public void clearResponses(final UserIdentity userIdentity, final ChaiUser theUser, final String userGUID) throws PwmUnrecoverableException {
if (userGUID == null || userGUID.length() < 1) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot clear responses to remote database, user " + theUser.getEntryDN() + " does not have a guid"));
}
try {
final DatabaseAccessor databaseAccessor = pwmApplication.getDatabaseService().getAccessor();
databaseAccessor.remove(DatabaseTable.PWM_RESPONSES, userGUID);
LOGGER.info("cleared responses for user " + theUser.getEntryDN() + " in remote database");
} catch (DatabaseException e) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_CLEARING_RESPONSES, "unexpected error clearing responses for " + theUser.getEntryDN() + " in remote database, error: " + e.getMessage());
final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
pwmOE.initCause(e);
throw pwmOE;
}
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class LocalDbCrOperator method clearResponses.
public void clearResponses(final UserIdentity userIdentity, final ChaiUser theUser, final String userGUID) throws PwmUnrecoverableException {
if (userGUID == null || userGUID.length() < 1) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot clear responses to localDB, user does not have a pwmGUID"));
}
if (localDB == null) {
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 {
localDB.remove(LocalDB.DB.RESPONSE_STORAGE, userGUID);
LOGGER.info("cleared responses for user " + theUser.getEntryDN() + " in local LocalDB");
} catch (LocalDBException e) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_CLEARING_RESPONSES, "unexpected LocalDB error clearing responses: " + e.getMessage());
final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
pwmOE.initCause(e);
throw pwmOE;
}
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class AbstractOtpOperator method composeOtpAttribute.
/**
* Compose a single line of OTP information.
*
* @param otpUserRecord input user record
* @return A string formatted record
*/
public String composeOtpAttribute(final OTPUserRecord otpUserRecord) throws PwmUnrecoverableException {
String value = "";
if (otpUserRecord != null) {
final Configuration config = pwmApplication.getConfig();
final OTPStorageFormat format = config.readSettingAsEnum(PwmSetting.OTP_SECRET_STORAGEFORMAT, OTPStorageFormat.class);
switch(format) {
case PWM:
value = JsonUtil.serialize(otpUserRecord);
break;
case OTPURL:
value = OTPUrlUtil.composeOtpUrl(otpUserRecord);
break;
case BASE32SECRET:
value = otpUserRecord.getSecret();
break;
case PAM:
value = OTPPamUtil.composePamData(otpUserRecord);
break;
default:
final String errorStr = String.format("Unsupported storage format: %s", format.toString());
final ErrorInformation error = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, errorStr);
throw new PwmUnrecoverableException(error);
}
}
return value;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class PwmLogger method doPwmSessionLogEvent.
private void doPwmSessionLogEvent(final PwmLogLevel level, final PwmSession pwmSession, final Object message, final Throwable e) {
final SessionLabel sessionLabel = pwmSession != null ? pwmSession.getLabel() : null;
Object cleanedMessage = message;
if (pwmSession != null && message != null) {
try {
cleanedMessage = PwmLogger.removeUserDataFromString(pwmSession.getLoginInfoBean(), message.toString());
} catch (PwmUnrecoverableException e1) {
/* can't be logged */
}
}
doLogEvent(level, sessionLabel, cleanedMessage, e);
}
Aggregations