Search in sources :

Example 6 with LocalDBException

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

Example 7 with LocalDBException

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

Example 8 with LocalDBException

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

Example 9 with LocalDBException

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;
}
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 10 with LocalDBException

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);
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) LocalDBException(password.pwm.util.localdb.LocalDBException) LocalDB(password.pwm.util.localdb.LocalDB) LocalDB(password.pwm.util.localdb.LocalDB) LinkedHashMap(java.util.LinkedHashMap)

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