Search in sources :

Example 1 with AuditEvent

use of org.apache.hadoop.crypto.key.kms.server.KMSAuditLogger.AuditEvent in project hadoop by apache.

the class KMSAudit method op.

/**
   * Logs to the audit service a single operation on the KMS or on a key.
   *
   * @param opStatus
   *          The outcome of the audited event
   * @param op
   *          The operation being audited (either {@link KMS.KMSOp} or
   *          {@link Type} N.B this is passed as an {@link Object} to allow
   *          either enum to be passed in.
   * @param ugi
   *          The user's security context
   * @param key
   *          The String name of the key if applicable
   * @param remoteHost
   *          The hostname of the requesting service
   * @param extraMsg
   *          Any extra details for auditing
   */
private void op(final OpStatus opStatus, final Object op, final UserGroupInformation ugi, final String key, final String remoteHost, final String extraMsg) {
    final String user = ugi == null ? null : ugi.getShortUserName();
    if (!Strings.isNullOrEmpty(user) && !Strings.isNullOrEmpty(key) && (op != null) && AGGREGATE_OPS_WHITELIST.contains(op)) {
        String cacheKey = createCacheKey(user, key, op);
        if (opStatus == OpStatus.UNAUTHORIZED) {
            cache.invalidate(cacheKey);
            logEvent(opStatus, new AuditEvent(op, ugi, key, remoteHost, extraMsg));
        } else {
            try {
                AuditEvent event = cache.get(cacheKey, new Callable<AuditEvent>() {

                    @Override
                    public AuditEvent call() throws Exception {
                        return new AuditEvent(op, ugi, key, remoteHost, extraMsg);
                    }
                });
                // incrementAndGet() == 0 implies first access)
                if (event.getAccessCount().incrementAndGet() == 0) {
                    event.getAccessCount().incrementAndGet();
                    logEvent(opStatus, event);
                }
            } catch (ExecutionException ex) {
                throw new RuntimeException(ex);
            }
        }
    } else {
        logEvent(opStatus, new AuditEvent(op, ugi, key, remoteHost, extraMsg));
    }
}
Also used : AuditEvent(org.apache.hadoop.crypto.key.kms.server.KMSAuditLogger.AuditEvent) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 AuditEvent (org.apache.hadoop.crypto.key.kms.server.KMSAuditLogger.AuditEvent)1