Example #1
0
 public UserCacheRecord next() {
   try {
     UserCacheRecord returnBean = null;
     while (returnBean == null && this.storageKeyIterator.hasNext()) {
       UserCacheService.StorageKey key = this.storageKeyIterator.next();
       returnBean = userCacheService.readStorageKey(key);
       if (returnBean != null) {
         if (returnBean.getCacheTimestamp() == null) {
           LOGGER.debug(
               PwmConstants.REPORTING_SESSION_LABEL,
               "purging record due to missing cache timestamp: "
                   + JsonUtil.serialize(returnBean));
           userCacheService.removeStorageKey(key);
         } else if (TimeDuration.fromCurrent(returnBean.getCacheTimestamp())
             .isLongerThan(settings.getMaxCacheAge())) {
           LOGGER.debug(
               PwmConstants.REPORTING_SESSION_LABEL,
               "purging record due to old age timestamp: " + JsonUtil.serialize(returnBean));
           userCacheService.removeStorageKey(key);
         } else {
           return returnBean;
         }
       }
     }
   } catch (LocalDBException e) {
     throw new IllegalStateException(
         "unexpected iterator traversal error while reading LocalDB: " + e.getMessage());
   }
   return null;
 }
Example #2
0
  private void outputRecordRow(
      final Configuration config,
      final Locale locale,
      final UserCacheRecord userCacheRecord,
      final CSVPrinter csvPrinter)
      throws IOException {
    final String trueField = Display.getLocalizedMessage(locale, Display.Value_True, config);
    final String falseField = Display.getLocalizedMessage(locale, Display.Value_False, config);
    final String naField = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, config);
    final List<String> csvRow = new ArrayList<>();
    csvRow.add(userCacheRecord.getUserDN());
    csvRow.add(userCacheRecord.getLdapProfile());
    csvRow.add(userCacheRecord.getUsername());
    csvRow.add(userCacheRecord.getEmail());
    csvRow.add(userCacheRecord.getUserGUID());
    csvRow.add(
        userCacheRecord.getLastLoginTime() == null
            ? naField
            : PwmConstants.DEFAULT_DATETIME_FORMAT.format(userCacheRecord.getLastLoginTime()));
    csvRow.add(
        userCacheRecord.getPasswordExpirationTime() == null
            ? naField
            : PwmConstants.DEFAULT_DATETIME_FORMAT.format(
                userCacheRecord.getPasswordExpirationTime()));
    csvRow.add(
        userCacheRecord.getPasswordChangeTime() == null
            ? naField
            : PwmConstants.DEFAULT_DATETIME_FORMAT.format(userCacheRecord.getPasswordChangeTime()));
    csvRow.add(
        userCacheRecord.getResponseSetTime() == null
            ? naField
            : PwmConstants.DEFAULT_DATETIME_FORMAT.format(userCacheRecord.getResponseSetTime()));
    csvRow.add(userCacheRecord.isHasResponses() ? trueField : falseField);
    csvRow.add(userCacheRecord.isHasHelpdeskResponses() ? trueField : falseField);
    csvRow.add(
        userCacheRecord.getResponseStorageMethod() == null
            ? naField
            : userCacheRecord.getResponseStorageMethod().toString());
    csvRow.add(userCacheRecord.getPasswordStatus().isExpired() ? trueField : falseField);
    csvRow.add(userCacheRecord.getPasswordStatus().isPreExpired() ? trueField : falseField);
    csvRow.add(userCacheRecord.getPasswordStatus().isViolatesPolicy() ? trueField : falseField);
    csvRow.add(userCacheRecord.getPasswordStatus().isWarnPeriod() ? trueField : falseField);
    csvRow.add(userCacheRecord.isRequiresPasswordUpdate() ? trueField : falseField);
    csvRow.add(userCacheRecord.isRequiresResponseUpdate() ? trueField : falseField);
    csvRow.add(userCacheRecord.isRequiresProfileUpdate() ? trueField : falseField);
    csvRow.add(
        userCacheRecord.getCacheTimestamp() == null
            ? naField
            : PwmConstants.DEFAULT_DATETIME_FORMAT.format(userCacheRecord.getCacheTimestamp()));

    csvPrinter.printRecord(csvRow);
  }
Example #3
0
  private boolean updateCachedRecordFromLdap(
      final UserIdentity userIdentity,
      final UserInfoBean userInfoBean,
      final UserCacheService.StorageKey storageKey)
      throws ChaiUnavailableException, PwmUnrecoverableException, LocalDBException {
    final UserCacheRecord userCacheRecord = userCacheService.readStorageKey(storageKey);
    TimeDuration cacheAge = null;
    if (userCacheRecord != null && userCacheRecord.getCacheTimestamp() != null) {
      cacheAge = TimeDuration.fromCurrent(userCacheRecord.getCacheTimestamp());
    }

    boolean updateCache = false;
    if (userInfoBean != null) {
      updateCache = true;
    } else {
      if (cacheAge == null) {
        LOGGER.trace(
            PwmConstants.REPORTING_SESSION_LABEL,
            "stored cache for "
                + userIdentity
                + " is missing cache storage timestamp, will update");
        updateCache = true;
      } else if (cacheAge.isLongerThan(settings.getMinCacheAge())) {
        LOGGER.trace(
            PwmConstants.REPORTING_SESSION_LABEL,
            "stored cache for "
                + userIdentity
                + " is "
                + cacheAge.asCompactString()
                + " old, will update");
        updateCache = true;
      }
    }

    if (updateCache) {
      if (userCacheRecord != null) {
        if (summaryData != null
            && summaryData.getEpoch() != null
            && summaryData.getEpoch().equals(userCacheRecord.getSummaryEpoch())) {
          summaryData.remove(userCacheRecord);
        }
      }
      final UserInfoBean newUserBean;
      if (userInfoBean != null) {
        newUserBean = userInfoBean;
      } else {
        newUserBean = new UserInfoBean();
        final UserStatusReader.Settings readerSettings = new UserStatusReader.Settings();
        readerSettings.setSkipReportUpdate(true);
        final ChaiProvider chaiProvider =
            pwmApplication.getProxyChaiProvider(userIdentity.getLdapProfileID());
        final UserStatusReader userStatusReader =
            new UserStatusReader(
                pwmApplication, PwmConstants.REPORTING_SESSION_LABEL, readerSettings);
        userStatusReader.populateUserInfoBean(
            newUserBean, PwmConstants.DEFAULT_LOCALE, userIdentity, chaiProvider);
      }
      final UserCacheRecord newUserCacheRecord = userCacheService.updateUserCache(newUserBean);

      if (summaryData != null && summaryData.getEpoch() != null && newUserCacheRecord != null) {
        if (!summaryData.getEpoch().equals(newUserCacheRecord.getSummaryEpoch())) {
          newUserCacheRecord.setSummaryEpoch(summaryData.getEpoch());
          userCacheService.store(newUserCacheRecord);
        }
        summaryData.update(newUserCacheRecord);
      }
    }

    return updateCache;
  }