Search in sources :

Example 1 with DatabaseAccessor

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

the class DatabaseStatusChecker method checkDatabaseStatus.

private static List<HealthRecord> checkDatabaseStatus(final PwmApplication pwmApplication, final Configuration config) {
    if (!config.hasDbConfigured()) {
        return Collections.singletonList(new HealthRecord(HealthStatus.INFO, HealthTopic.Database, "Database not configured"));
    }
    PwmApplication runtimeInstance = null;
    try {
        final PwmEnvironment runtimeEnvironment = pwmApplication.getPwmEnvironment().makeRuntimeInstance(config);
        runtimeInstance = new PwmApplication(runtimeEnvironment);
        final DatabaseAccessor accessor = runtimeInstance.getDatabaseService().getAccessor();
        accessor.get(DatabaseTable.PWM_META, "test");
        return runtimeInstance.getDatabaseService().healthCheck();
    } catch (PwmException e) {
        LOGGER.error("error during healthcheck: " + e.getMessage());
        e.printStackTrace();
        return runtimeInstance.getDatabaseService().healthCheck();
    } finally {
        if (runtimeInstance != null) {
            runtimeInstance.shutdown();
        }
    }
}
Also used : PwmException(password.pwm.error.PwmException) PwmApplication(password.pwm.PwmApplication) PwmEnvironment(password.pwm.PwmEnvironment) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor)

Example 2 with DatabaseAccessor

use of password.pwm.util.db.DatabaseAccessor 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 3 with DatabaseAccessor

use of password.pwm.util.db.DatabaseAccessor 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 4 with DatabaseAccessor

use of password.pwm.util.db.DatabaseAccessor 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)

Example 5 with DatabaseAccessor

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

the class DbCrOperator 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 = "user " + theUser.getEntryDN() + " does not have a guid, unable to search for responses in remote database";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_GUID, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    try {
        final DatabaseAccessor databaseAccessor = pwmApplication.getDatabaseService().getAccessor();
        final String responseStringBlob = databaseAccessor.get(DatabaseTable.PWM_RESPONSES, userGUID);
        if (responseStringBlob != null && responseStringBlob.length() > 0) {
            final ResponseSet userResponseSet = ChaiResponseSet.parseChaiResponseSetXML(responseStringBlob, theUser);
            LOGGER.debug("found responses for " + theUser.getEntryDN() + " in remote database: " + userResponseSet.toString());
            return userResponseSet;
        } else {
            LOGGER.trace("user guid for " + theUser.getEntryDN() + " not found in remote database (key=" + userGUID + ")");
        }
    } catch (ChaiValidationException e) {
        final String errorMsg = "unexpected error reading responses for " + theUser.getEntryDN() + " from remote database: " + 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 for " + theUser.getEntryDN() + " from remote database: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(e.getErrorInformation().getError(), errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    return null;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChaiResponseSet(com.novell.ldapchai.cr.ChaiResponseSet) ResponseSet(com.novell.ldapchai.cr.ResponseSet) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

DatabaseAccessor (password.pwm.util.db.DatabaseAccessor)7 ErrorInformation (password.pwm.error.ErrorInformation)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 PwmOperationalException (password.pwm.error.PwmOperationalException)3 DatabaseException (password.pwm.util.db.DatabaseException)3 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)2 ResponseSet (com.novell.ldapchai.cr.ResponseSet)1 ChaiException (com.novell.ldapchai.exception.ChaiException)1 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)1 PwmApplication (password.pwm.PwmApplication)1 PwmEnvironment (password.pwm.PwmEnvironment)1 PwmException (password.pwm.error.PwmException)1 LocalDBException (password.pwm.util.localdb.LocalDBException)1