use of password.pwm.util.localdb.LocalDBException 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 password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.
the class DbOtpOperator method readOtpUserConfiguration.
@Override
public OTPUserRecord readOtpUserConfiguration(final UserIdentity theUser, final String userGUID) throws PwmUnrecoverableException {
LOGGER.trace(String.format("Enter: readOtpUserConfiguration(%s, %s)", theUser, userGUID));
if (userGUID == null || userGUID.length() < 1) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save otp to db, user does not have a GUID"));
}
OTPUserRecord otpConfig = null;
try {
final DatabaseAccessor databaseAccessor = pwmApplication.getDatabaseAccessor();
String value = databaseAccessor.get(DatabaseTable.OTP, userGUID);
if (value != null && value.length() > 0) {
if (getPwmApplication().getConfig().readSettingAsBoolean(PwmSetting.OTP_SECRET_ENCRYPT)) {
value = decryptAttributeValue(value);
}
if (value != null) {
otpConfig = decomposeOtpAttribute(value);
}
if (otpConfig != null) {
LOGGER.debug("found user OTP secret in db: " + otpConfig.toString());
}
}
} 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 (PwmOperationalException e) {
final String errorMsg = "unexpected error reading responses: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
return otpConfig;
}
use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.
the class LocalDbOtpOperator method clearOtpUserConfiguration.
@Override
public void clearOtpUserConfiguration(final PwmSession pwmSession, final UserIdentity theUser, final String userGUID) throws PwmUnrecoverableException {
LOGGER.trace(pwmSession, String.format("Enter: clearOtpUserConfiguration(%s, %s)", theUser, userGUID));
if (userGUID == null || userGUID.length() < 1) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save otp 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 OTP";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_LOCALDB_UNAVAILABLE, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
try {
localDB.remove(LocalDB.DB.OTP_SECRET, userGUID);
LOGGER.info(pwmSession, "cleared OTP secret for user in LocalDB");
} catch (LocalDBException ex) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, "unexpected error saving otp to localDB: " + ex.getMessage());
final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
pwmOE.initCause(ex);
throw pwmOE;
}
}
use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.
the class LocalDbOtpOperator method readOtpUserConfiguration.
@Override
public OTPUserRecord readOtpUserConfiguration(final UserIdentity theUser, final String userGUID) throws PwmUnrecoverableException {
LOGGER.trace(String.format("Enter: readOtpUserConfiguration(%s, %s)", theUser, userGUID));
if (userGUID == null || userGUID.length() < 1) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save otp to localDB, user does not have a GUID"));
}
if (localDB == null || localDB.status() != LocalDB.Status.OPEN) {
final String errorMsg = "LocalDB is not available, unable to write user otp";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_LOCALDB_UNAVAILABLE, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
OTPUserRecord otpConfig = null;
try {
final Configuration config = this.getPwmApplication().getConfig();
String value = localDB.get(LocalDB.DB.OTP_SECRET, userGUID);
if (value != null && value.length() > 0) {
if (config.readSettingAsBoolean(PwmSetting.OTP_SECRET_ENCRYPT)) {
value = decryptAttributeValue(value);
}
if (value != null) {
otpConfig = decomposeOtpAttribute(value);
}
if (otpConfig != null) {
LOGGER.debug("found user OTP secret in LocalDB: " + otpConfig.toString());
}
}
} catch (LocalDBException e) {
final String errorMsg = "unexpected LocalDB error reading otp: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
} catch (PwmOperationalException e) {
final String errorMsg = "unexpected error reading otp: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
return otpConfig;
}
use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.
the class AppDashboardData method makeLocalDbTableSizes.
private static Map<LocalDB.DB, String> makeLocalDbTableSizes(final PwmApplication pwmApplication, final Locale locale) {
final Map<LocalDB.DB, String> returnData = new LinkedHashMap<>();
final LocalDB localDB = pwmApplication.getLocalDB();
final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
try {
for (final LocalDB.DB db : LocalDB.DB.values()) {
returnData.put(db, numberFormat.format(localDB.size(db)));
}
} catch (LocalDBException e) {
LOGGER.error("error making localDB size bean: " + e.getMessage());
}
return Collections.unmodifiableMap(returnData);
}
Aggregations