Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions audit-server/audit-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.ranger</groupId>
<artifactId>ranger</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>ranger-audit-server-common</artifactId>
<packaging>jar</packaging>
<name>Ranger Audit Server Common</name>
<description>Shared classes between audit ingestor and dispatcher</description>

<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ranger</groupId>
<artifactId>ranger-plugins-common</artifactId>
Comment thread
rameeshm marked this conversation as resolved.
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>

<build>
<finalName>ranger-audit-server-common-${project.version}</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,27 @@

package org.apache.ranger.audit.server;

import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;

/**
* Base configuration class for Ranger Audit Server services.
* Can be extended by specific services to load their custom configuration files.
*/
public class AuditConfig extends RangerConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(AuditConfig.class);
private static volatile AuditConfig sInstance;
public class AuditConfig extends Configuration {
private static final Logger LOG = LoggerFactory.getLogger(AuditConfig.class);

protected AuditConfig() {
public AuditConfig() {
super();
}

/**
* Get the singleton instance of AuditConfig.
* Subclasses should override this method to return their specific instance.
*/
public static AuditConfig getInstance() {
AuditConfig ret = AuditConfig.sInstance;

if (ret == null) {
synchronized (AuditConfig.class) {
ret = AuditConfig.sInstance;

if (ret == null) {
ret = new AuditConfig();
AuditConfig.sInstance = ret;
}
}
}

return ret;
}

public Properties getProperties() {
return this.getProps();
}
Expand All @@ -66,11 +48,11 @@ public Properties getProperties() {
* Add a resource file to the configuration.
* Subclasses can override to load their specific config files.
*
* @param resourcePath Path to the resource file (e.g., "conf/ranger-audit-server-site.xml")
* @param resourcePath Path to the resource file (e.g., "conf/ranger-audit-ingestor-site.xml")
* @param required Whether this resource is required
* @return true if resource was loaded successfully or is optional, false otherwise
*/
protected boolean addAuditResource(String resourcePath, boolean required) {
public boolean addAuditResource(String resourcePath, boolean required) {
LOG.debug("==> addAuditResource(path={}, required={})", resourcePath, required);

boolean success = addResourceIfReadable(resourcePath);
Expand All @@ -87,4 +69,58 @@ protected boolean addAuditResource(String resourcePath, boolean required) {

return success || !required;
}

public boolean addResourceIfReadable(String aResourceName) {
LOG.debug("==> addResourceIfReadable({})", aResourceName);

boolean ret = false;
URL fUrl = getFileLocation(aResourceName);

if (fUrl != null) {
LOG.debug("addResourceIfReadable({}): resource file is {}", aResourceName, fUrl);

try {
addResource(fUrl);

ret = true;
} catch (Exception e) {
LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", aResourceName, fUrl);

LOG.debug("Resource loading failed for {}", fUrl, e);
}
} else {
LOG.debug("addResourceIfReadable({}): couldn't find resource file location", aResourceName);
}

LOG.debug("<== addResourceIfReadable({}), result={}", aResourceName, ret);

return ret;
}

private URL getFileLocation(String fileName) {
URL lurl = null;

if (!StringUtils.isEmpty(fileName)) {
lurl = AuditConfig.class.getClassLoader().getResource(fileName);

if (lurl == null) {
lurl = AuditConfig.class.getClassLoader().getResource("/" + fileName);
}

if (lurl == null) {
File f = new File(fileName);
if (f.exists()) {
try {
lurl = f.toURI().toURL();
} catch (MalformedURLException e) {
LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", fileName, f.getPath());
}
} else {
LOG.debug("Conf file path {} does not exists", fileName);
}
}
}

return lurl;
}
}
Loading