Search in sources :

Example 1 with UserEventStorageMethod

use of password.pwm.config.option.UserEventStorageMethod in project pwm by pwm-project.

the class AuditService method init.

public void init(final PwmApplication pwmApplication) throws PwmException {
    this.status = STATUS.OPENING;
    this.pwmApplication = pwmApplication;
    settings = new AuditSettings(pwmApplication.getConfig());
    if (pwmApplication.getApplicationMode() == null || pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) {
        this.status = STATUS.CLOSED;
        LOGGER.warn("unable to start - Application is in read-only mode");
        return;
    }
    if (pwmApplication.getLocalDB() == null || pwmApplication.getLocalDB().status() != LocalDB.Status.OPEN) {
        this.status = STATUS.CLOSED;
        LOGGER.warn("unable to start - LocalDB is not available");
        return;
    }
    final List<String> syslogConfigString = pwmApplication.getConfig().readSettingAsStringArray(PwmSetting.AUDIT_SYSLOG_SERVERS);
    if (syslogConfigString != null && !syslogConfigString.isEmpty()) {
        try {
            syslogManager = new SyslogAuditService(pwmApplication);
        } catch (Exception e) {
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SYSLOG_WRITE_ERROR, "startup error: " + e.getMessage());
            LOGGER.error(errorInformation.toDebugStr());
        }
    }
    {
        final UserEventStorageMethod userEventStorageMethod = pwmApplication.getConfig().readSettingAsEnum(PwmSetting.EVENTS_USER_STORAGE_METHOD, UserEventStorageMethod.class);
        final String debugMsg;
        final DataStorageMethod storageMethodUsed;
        switch(userEventStorageMethod) {
            case AUTO:
                if (pwmApplication.getConfig().hasDbConfigured()) {
                    debugMsg = "starting using auto-configured data store, Remote Database selected";
                    this.userHistoryStore = new DatabaseUserHistory(pwmApplication);
                    storageMethodUsed = DataStorageMethod.DB;
                } else {
                    debugMsg = "starting using auto-configured data store, LDAP selected";
                    this.userHistoryStore = new LdapXmlUserHistory(pwmApplication);
                    storageMethodUsed = DataStorageMethod.LDAP;
                }
                break;
            case DATABASE:
                this.userHistoryStore = new DatabaseUserHistory(pwmApplication);
                debugMsg = "starting using Remote Database data store";
                storageMethodUsed = DataStorageMethod.DB;
                break;
            case LDAP:
                this.userHistoryStore = new LdapXmlUserHistory(pwmApplication);
                debugMsg = "starting using LocalDB data store";
                storageMethodUsed = DataStorageMethod.LDAP;
                break;
            default:
                lastError = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unknown storageMethod selected: " + userEventStorageMethod);
                status = STATUS.CLOSED;
                return;
        }
        LOGGER.info(debugMsg);
        serviceInfo = new ServiceInfoBean(Collections.singletonList(storageMethodUsed));
    }
    {
        final TimeDuration maxRecordAge = new TimeDuration(pwmApplication.getConfig().readSettingAsLong(PwmSetting.EVENTS_AUDIT_MAX_AGE) * 1000);
        final long maxRecords = pwmApplication.getConfig().readSettingAsLong(PwmSetting.EVENTS_AUDIT_MAX_EVENTS);
        final AuditVault.Settings settings = new AuditVault.Settings(maxRecords, maxRecordAge);
        if (pwmApplication.getLocalDB() != null && pwmApplication.getApplicationMode() != PwmApplicationMode.READ_ONLY) {
            if (maxRecords < 1) {
                LOGGER.debug("localDB audit vault will remain closed due to max records setting");
                pwmApplication.getLocalDB().truncate(LocalDB.DB.AUDIT_EVENTS);
            } else {
                auditVault = new LocalDbAuditVault();
                auditVault.init(pwmApplication, pwmApplication.getLocalDB(), settings);
            }
        } else {
            LOGGER.debug("localDB audit vault will remain closed due to application mode");
        }
    }
    this.status = STATUS.OPEN;
}
Also used : UserEventStorageMethod(password.pwm.config.option.UserEventStorageMethod) DataStorageMethod(password.pwm.config.option.DataStorageMethod) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) ErrorInformation(password.pwm.error.ErrorInformation) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

IOException (java.io.IOException)1 DataStorageMethod (password.pwm.config.option.DataStorageMethod)1 UserEventStorageMethod (password.pwm.config.option.UserEventStorageMethod)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmException (password.pwm.error.PwmException)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 TimeDuration (password.pwm.util.java.TimeDuration)1