Search in sources :

Example 1 with Log4JAuditDestination

use of org.apache.ranger.audit.destination.Log4JAuditDestination in project ranger by apache.

the class AuditProviderFactory method getProviderFromConfig.

private AuditHandler getProviderFromConfig(Properties props, String propPrefix, String providerName, AuditHandler consumer) {
    AuditHandler provider = null;
    String className = MiscUtil.getStringProperty(props, propPrefix + "." + BaseAuditHandler.PROP_CLASS_NAME);
    if (className != null && !className.isEmpty()) {
        try {
            Class<?> handlerClass = Class.forName(className);
            if (handlerClass.isAssignableFrom(AuditQueue.class)) {
                // Queue class needs consumer
                handlerClass.getDeclaredConstructor(AuditHandler.class).newInstance(consumer);
            } else {
                provider = (AuditHandler) Class.forName(className).newInstance();
            }
        } catch (Exception e) {
            LOG.fatal("Can't instantiate audit class for providerName=" + providerName + ", className=" + className + ", propertyPrefix=" + propPrefix, e);
        }
    } else {
        if (providerName.equals("file")) {
            provider = new FileAuditDestination();
        } else if (providerName.equalsIgnoreCase("hdfs")) {
            provider = new HDFSAuditDestination();
        } else if (providerName.equals("solr")) {
            provider = new SolrAuditDestination();
        } else if (providerName.equals("kafka")) {
            provider = new KafkaAuditProvider();
        } else if (providerName.equals("db")) {
            provider = new DBAuditDestination();
        } else if (providerName.equals("log4j")) {
            provider = new Log4JAuditDestination();
        } else if (providerName.equals("batch")) {
            provider = new AuditBatchQueue(consumer);
        } else if (providerName.equals("async")) {
            provider = new AuditAsyncQueue(consumer);
        } else {
            LOG.error("Provider name doesn't have any class associated with it. providerName=" + providerName + ", propertyPrefix=" + propPrefix);
        }
    }
    if (provider != null && provider instanceof AuditQueue) {
        if (consumer == null) {
            LOG.fatal("consumer can't be null for AuditQueue. queue=" + provider.getName() + ", propertyPrefix=" + propPrefix);
            provider = null;
        }
    }
    return provider;
}
Also used : AuditBatchQueue(org.apache.ranger.audit.queue.AuditBatchQueue) HDFSAuditDestination(org.apache.ranger.audit.destination.HDFSAuditDestination) KafkaAuditProvider(org.apache.ranger.audit.provider.kafka.KafkaAuditProvider) AuditAsyncQueue(org.apache.ranger.audit.queue.AuditAsyncQueue) Log4JAuditDestination(org.apache.ranger.audit.destination.Log4JAuditDestination) AuditQueue(org.apache.ranger.audit.queue.AuditQueue) DBAuditDestination(org.apache.ranger.audit.destination.DBAuditDestination) SolrAuditDestination(org.apache.ranger.audit.destination.SolrAuditDestination) FileAuditDestination(org.apache.ranger.audit.destination.FileAuditDestination)

Aggregations

DBAuditDestination (org.apache.ranger.audit.destination.DBAuditDestination)1 FileAuditDestination (org.apache.ranger.audit.destination.FileAuditDestination)1 HDFSAuditDestination (org.apache.ranger.audit.destination.HDFSAuditDestination)1 Log4JAuditDestination (org.apache.ranger.audit.destination.Log4JAuditDestination)1 SolrAuditDestination (org.apache.ranger.audit.destination.SolrAuditDestination)1 KafkaAuditProvider (org.apache.ranger.audit.provider.kafka.KafkaAuditProvider)1 AuditAsyncQueue (org.apache.ranger.audit.queue.AuditAsyncQueue)1 AuditBatchQueue (org.apache.ranger.audit.queue.AuditBatchQueue)1 AuditQueue (org.apache.ranger.audit.queue.AuditQueue)1