Search in sources :

Example 1 with LocalDBException

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

Example 2 with LocalDBException

use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.

the class LocalDbOtpOperator method writeOtpUserConfiguration.

@Override
public void writeOtpUserConfiguration(final PwmSession pwmSession, final UserIdentity theUser, final String userGUID, final OTPUserRecord otpConfig) throws PwmUnrecoverableException {
    LOGGER.trace(pwmSession, String.format("Enter: writeOtpUserConfiguration(%s, %s, %s)", theUser, userGUID, otpConfig));
    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 {
        final Configuration config = this.getPwmApplication().getConfig();
        String value = composeOtpAttribute(otpConfig);
        if (config.readSettingAsBoolean(PwmSetting.OTP_SECRET_ENCRYPT)) {
            LOGGER.debug(pwmSession, "Encrypting OTP secret for storage");
            value = encryptAttributeValue(value);
        }
        localDB.put(LocalDB.DB.OTP_SECRET, userGUID, value);
        LOGGER.info(pwmSession, "saved OTP secret for user in LocalDB");
    } catch (LocalDBException ex) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_WRITING_OTP_SECRET, "unexpected LocalDB error saving otp to localDB: " + ex.getMessage());
        final PwmUnrecoverableException pwmOE = new PwmUnrecoverableException(errorInfo);
        pwmOE.initCause(ex);
        throw pwmOE;
    } catch (PwmOperationalException 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;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LocalDBException(password.pwm.util.localdb.LocalDBException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 3 with LocalDBException

use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.

the class SharedHistoryManager method init.

private void init(final PwmApplication pwmApplication, final long maxAgeMs) {
    status = STATUS.OPENING;
    final long startTime = System.currentTimeMillis();
    try {
        checkDbVersion();
    } catch (Exception e) {
        LOGGER.error("error checking db version", e);
        status = STATUS.CLOSED;
        return;
    }
    try {
        final String oldestEntryStr = localDB.get(META_DB, KEY_OLDEST_ENTRY);
        if (oldestEntryStr == null || oldestEntryStr.length() < 1) {
            oldestEntry = 0;
            LOGGER.trace("no oldestEntry timestamp stored, will rescan");
        } else {
            oldestEntry = Long.parseLong(oldestEntryStr);
            LOGGER.trace("oldest timestamp loaded from localDB, age is " + TimeDuration.fromCurrent(oldestEntry).asCompactString());
        }
    } catch (LocalDBException e) {
        LOGGER.error("unexpected error loading oldest-entry meta record, will remain closed: " + e.getMessage(), e);
        status = STATUS.CLOSED;
        return;
    }
    try {
        final int size = localDB.size(WORDS_DB);
        final StringBuilder sb = new StringBuilder();
        sb.append("open with ").append(size).append(" words (");
        sb.append(new TimeDuration(System.currentTimeMillis(), startTime).asCompactString()).append(")");
        sb.append(", maxAgeMs=").append(new TimeDuration(maxAgeMs).asCompactString());
        sb.append(", oldestEntry=").append(new TimeDuration(System.currentTimeMillis(), oldestEntry).asCompactString());
        LOGGER.info(sb.toString());
    } catch (LocalDBException e) {
        LOGGER.error("unexpected error examining size of DB, will remain closed: " + e.getMessage(), e);
        status = STATUS.CLOSED;
        return;
    }
    status = STATUS.OPEN;
    if (pwmApplication.getApplicationMode() == PwmApplicationMode.RUNNING || pwmApplication.getApplicationMode() == PwmApplicationMode.CONFIGURATION) {
        long frequencyMs = maxAgeMs > MAX_CLEANER_FREQUENCY ? MAX_CLEANER_FREQUENCY : maxAgeMs;
        frequencyMs = frequencyMs < MIN_CLEANER_FREQUENCY ? MIN_CLEANER_FREQUENCY : frequencyMs;
        LOGGER.debug("scheduling cleaner task to run once every " + new TimeDuration(frequencyMs).asCompactString());
        final String threadName = JavaHelper.makeThreadName(pwmApplication, this.getClass()) + " timer";
        cleanerTimer = new Timer(threadName, true);
        cleanerTimer.schedule(new CleanerTask(), 1000, frequencyMs);
    }
}
Also used : Timer(java.util.Timer) TimeDuration(password.pwm.util.java.TimeDuration) LocalDBException(password.pwm.util.localdb.LocalDBException) LocalDBException(password.pwm.util.localdb.LocalDBException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PwmException(password.pwm.error.PwmException)

Example 4 with LocalDBException

use of password.pwm.util.localdb.LocalDBException in project pwm by pwm-project.

the class AbstractWordlist method startup.

protected final void startup() {
    wlStatus = STATUS.OPENING;
    if (localDB == null) {
        final String errorMsg = "LocalDB is not available, " + debugLabel + " will remain closed";
        logger.warn(errorMsg);
        lastError = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, errorMsg);
        close();
        return;
    }
    try {
        populationManager.checkPopulation();
    } catch (Exception e) {
        final String errorMsg = "unexpected error while examining wordlist db: " + e.getMessage();
        if ((e instanceof PwmUnrecoverableException) || (e instanceof NullPointerException) || (e instanceof LocalDBException)) {
            logger.warn(errorMsg);
        } else {
            logger.warn(errorMsg, e);
        }
        lastError = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, errorMsg);
        populator = null;
        close();
        return;
    }
    // read stored size
    storedSize = readMetadata().getSize();
    wlStatus = STATUS.OPEN;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LocalDBException(password.pwm.util.localdb.LocalDBException) LocalDBException(password.pwm.util.localdb.LocalDBException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with LocalDBException

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

Aggregations

LocalDBException (password.pwm.util.localdb.LocalDBException)11 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)9 ErrorInformation (password.pwm.error.ErrorInformation)8 PwmOperationalException (password.pwm.error.PwmOperationalException)3 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)2 ChaiException (com.novell.ldapchai.exception.ChaiException)2 Configuration (password.pwm.config.Configuration)2 PwmException (password.pwm.error.PwmException)2 ResponseSet (com.novell.ldapchai.cr.ResponseSet)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedHashMap (java.util.LinkedHashMap)1 Timer (java.util.Timer)1 DatabaseAccessor (password.pwm.util.db.DatabaseAccessor)1 PwmNumberFormat (password.pwm.util.java.PwmNumberFormat)1 TimeDuration (password.pwm.util.java.TimeDuration)1 LocalDB (password.pwm.util.localdb.LocalDB)1 RestResultBean (password.pwm.ws.server.RestResultBean)1