示例#1
0
  /**
   * {@inheritDoc}
   *
   * @since 3.2
   */
  public void deleteAuditEntries(String applicationName, Long fromTime, Long toTime) {
    ParameterCheck.mandatory("applicationName", applicationName);
    AlfrescoTransactionSupport.checkTransactionReadState(true);

    AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName);
    if (application == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("No audit application named '" + applicationName + "' has been registered.");
      }
      return;
    }

    Long applicationId = application.getApplicationId();

    auditDAO.deleteAuditEntries(applicationId, fromTime, toTime);
    // Done
    if (logger.isDebugEnabled()) {
      logger.debug(
          "Delete audit entries for " + applicationName + " (" + fromTime + " to " + toTime);
    }
  }
示例#2
0
  /**
   * Audit values for a given application. No path checking is done.
   *
   * @param application the audit application to audit to
   * @param disabledPaths the application's disabled paths
   * @param values the values to store keyed by <b>full paths</b>.
   * @return Returns all values as audited
   */
  private Map<String, Serializable> audit(
      final AuditApplication application,
      Set<String> disabledPaths,
      final Map<String, Serializable> values) {
    // Get the model ID for the application
    Long applicationId = application.getApplicationId();
    if (applicationId == null) {
      throw new AuditException(
          "No persisted instance exists for audit application: " + application);
    }

    // Eliminate any paths that have been disabled
    Iterator<String> pathedValuesKeyIterator = values.keySet().iterator();
    while (pathedValuesKeyIterator.hasNext()) {
      String pathedValueKey = pathedValuesKeyIterator.next();
      for (String disabledPath : disabledPaths) {
        if (pathedValueKey.startsWith(disabledPath)) {
          // The pathed value is excluded
          pathedValuesKeyIterator.remove();
        }
      }
    }
    // Check if there is anything left
    if (values.size() == 0) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Audit values have all been excluded by disabled paths: \n"
                + "   Application: "
                + application
                + "\n"
                + "   Values:      "
                + values);
      }
      return Collections.emptyMap();
    }

    // Generate data
    Map<String, DataGenerator> generators = application.getDataGenerators(values.keySet());
    Map<String, Serializable> auditData = generateData(generators);

    // Now extract values
    Map<String, Serializable> extractedData =
        AuthenticationUtil.runAs(
            new RunAsWork<Map<String, Serializable>>() {
              public Map<String, Serializable> doWork() throws Exception {
                return extractData(application, values);
              }
            },
            AuthenticationUtil.getSystemUserName());

    // Combine extracted and generated values (extracted data takes precedence)
    auditData.putAll(extractedData);

    // Time and username are intrinsic
    long time = System.currentTimeMillis();
    String username = AuthenticationUtil.getFullyAuthenticatedUser();

    Long entryId = null;
    if (!auditData.isEmpty()) {
      // Persist the values
      entryId = auditDAO.createAuditEntry(applicationId, time, username, auditData);
    }

    // Done
    if (logger.isDebugEnabled()) {
      logger.debug(
          "New audit entry: \n"
              + "   Application ID: "
              + applicationId
              + "\n"
              + "   Entry ID:       "
              + entryId
              + "\n"
              + "   Values:         "
              + values
              + "\n"
              + "   Audit Data:     "
              + auditData);
    }
    return auditData;
  }