Search in sources :

Example 1 with DatabaseException

use of password.pwm.util.db.DatabaseException in project pwm by pwm-project.

the class DatabaseUserHistory method updateUserHistory.

@Override
public void updateUserHistory(final UserAuditRecord auditRecord) throws PwmUnrecoverableException {
    // user info
    final UserIdentity userIdentity;
    if (auditRecord instanceof HelpdeskAuditRecord && auditRecord.getType() == AuditEvent.Type.HELPDESK) {
        final HelpdeskAuditRecord helpdeskAuditRecord = (HelpdeskAuditRecord) auditRecord;
        userIdentity = new UserIdentity(helpdeskAuditRecord.getTargetDN(), helpdeskAuditRecord.getTargetLdapProfile());
    } else {
        userIdentity = new UserIdentity(auditRecord.getPerpetratorDN(), auditRecord.getPerpetratorLdapProfile());
    }
    final String guid;
    try {
        guid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, null, userIdentity, false);
    } catch (ChaiUnavailableException e) {
        LOGGER.error("unable to read guid for user '" + userIdentity + "', cannot update user history, error: " + e.getMessage());
        return;
    }
    try {
        final StoredHistory storedHistory;
        storedHistory = readStoredHistory(guid);
        storedHistory.getRecords().add(auditRecord);
        writeStoredHistory(guid, storedHistory);
    } catch (DatabaseException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, e.getMessage()));
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseException(password.pwm.util.db.DatabaseException)

Example 2 with DatabaseException

use of password.pwm.util.db.DatabaseException in project pwm by pwm-project.

the class PwNotifyDbStorageService method readStoredState.

@Override
public StoredNotificationState readStoredState(final UserIdentity userIdentity, final SessionLabel sessionLabel) throws PwmUnrecoverableException {
    final String guid;
    try {
        guid = LdapOperationsHelper.readLdapGuidValue(pwmApplication, sessionLabel, userIdentity, true);
    } catch (ChaiUnavailableException e) {
        throw new PwmUnrecoverableException(PwmUnrecoverableException.fromChaiException(e).getErrorInformation());
    }
    if (StringUtil.isEmpty(guid)) {
        throw new PwmUnrecoverableException(PwmError.ERROR_MISSING_GUID);
    }
    final String rawDbValue;
    try {
        rawDbValue = pwmApplication.getDatabaseAccessor().get(TABLE, guid);
    } catch (DatabaseException e) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, e.getMessage()));
    }
    return JsonUtil.deserialize(rawDbValue, StoredNotificationState.class);
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseException(password.pwm.util.db.DatabaseException)

Example 3 with DatabaseException

use of password.pwm.util.db.DatabaseException 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;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor) ChaiException(com.novell.ldapchai.exception.ChaiException) DatabaseException(password.pwm.util.db.DatabaseException)

Example 4 with DatabaseException

use of password.pwm.util.db.DatabaseException 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;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor) DatabaseException(password.pwm.util.db.DatabaseException)

Example 5 with DatabaseException

use of password.pwm.util.db.DatabaseException in project pwm by pwm-project.

the class DbOtpOperator method clearOtpUserConfiguration.

@Override
public void clearOtpUserConfiguration(final PwmSession pwmSession, final UserIdentity theUser, final String userGUID) throws PwmUnrecoverableException {
    if (userGUID == null || userGUID.length() < 1) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_GUID, "cannot save OTP secret to remote database, user " + theUser + " does not have a guid"));
    }
    LOGGER.trace("attempting to clear OTP secret for " + theUser + " in remote database (key=" + userGUID + ")");
    try {
        final DatabaseAccessor databaseAccessor = pwmApplication.getDatabaseAccessor();
        databaseAccessor.remove(DatabaseTable.OTP, userGUID);
        LOGGER.info("cleared OTP secret for " + theUser + " in remote database (key=" + userGUID + ")");
    } catch (DatabaseException ex) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, "unexpected error saving otp to db: " + ex.getMessage());
        final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
        pwmOE.initCause(ex);
        throw pwmOE;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor) DatabaseException(password.pwm.util.db.DatabaseException)

Aggregations

ErrorInformation (password.pwm.error.ErrorInformation)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 DatabaseException (password.pwm.util.db.DatabaseException)6 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)3 DatabaseAccessor (password.pwm.util.db.DatabaseAccessor)3 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)1 ChaiException (com.novell.ldapchai.exception.ChaiException)1 UserIdentity (password.pwm.bean.UserIdentity)1