Search in sources :

Example 16 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class TestPolicyEngineForDeltas method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    pluginContext = new RangerPluginContext(new RangerPluginConfig("hive", null, "hive", "cl1", "on-prem", null));
    gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSSZ").setPrettyPrinting().registerTypeAdapter(RangerAccessRequest.class, new RangerAccessRequestDeserializer()).registerTypeAdapter(RangerAccessResource.class, new RangerResourceDeserializer()).create();
    // For setting up auditProvider
    Properties auditProperties = new Properties();
    String AUDIT_PROPERTIES_FILE = "xasecure-audit.properties";
    File propFile = new File(AUDIT_PROPERTIES_FILE);
    if (propFile.exists()) {
        System.out.println("Loading Audit properties file" + AUDIT_PROPERTIES_FILE);
        auditProperties.load(new FileInputStream(propFile));
    } else {
        System.out.println("Audit properties file missing: " + AUDIT_PROPERTIES_FILE);
        // Set this to true to enable audit logging
        auditProperties.setProperty("xasecure.audit.is.enabled", "false");
        auditProperties.setProperty("xasecure.audit.log4j.is.enabled", "false");
        auditProperties.setProperty("xasecure.audit.log4j.is.async", "false");
        auditProperties.setProperty("xasecure.audit.log4j.async.max.queue.size", "100000");
        auditProperties.setProperty("xasecure.audit.log4j.async.max.flush.interval.ms", "30000");
    }
    AuditProviderFactory factory = AuditProviderFactory.getInstance();
    // second parameter does not matter for v2
    factory.init(auditProperties, "hdfs");
    AuditHandler provider = factory.getAuditProvider();
    System.out.println("provider=" + provider.toString());
    File file = File.createTempFile("ranger-admin-test-site", ".xml");
    file.deleteOnExit();
    FileOutputStream outStream = new FileOutputStream(file);
    OutputStreamWriter writer = new OutputStreamWriter(outStream);
    /*
		// For setting up TestTagProvider

		writer.write("<configuration>\n" +
				"        <property>\n" +
				"                <name>ranger.plugin.tag.policy.rest.url</name>\n" +
				"                <value>http://os-def:6080</value>\n" +
				"        </property>\n" +
				"        <property>\n" +
				"                <name>ranger.externalurl</name>\n" +
				"                <value>http://os-def:6080</value>\n" +
				"        </property>\n" +
				"</configuration>\n");
				*/
    writer.write("<configuration>\n" + // For setting up x-forwarded-for for Hive
    "        <property>\n" + "                <name>ranger.plugin.hive.use.x-forwarded-for.ipaddress</name>\n" + "                <value>true</value>\n" + "        </property>\n" + "        <property>\n" + "                <name>ranger.plugin.hive.trusted.proxy.ipaddresses</name>\n" + "                <value>255.255.255.255; 128.101.101.101;128.101.101.99</value>\n" + "        </property>\n" + "        <property>\n" + "                <name>ranger.plugin.tag.attr.additional.date.formats</name>\n" + "                <value>abcd||xyz||yyyy/MM/dd'T'HH:mm:ss.SSS'Z'</value>\n" + "        </property>\n" + "        <property>\n" + "                <name>ranger.policyengine.trie.builder.thread.count</name>\n" + "                <value>3</value>\n" + "        </property>\n" + "</configuration>\n");
    writer.close();
    pluginContext.getConfig().addResource(new org.apache.hadoop.fs.Path(file.toURI()));
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) AuditHandler(org.apache.ranger.audit.provider.AuditHandler) RangerDefaultAuditHandler(org.apache.ranger.plugin.audit.RangerDefaultAuditHandler) GsonBuilder(com.google.gson.GsonBuilder) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) AuditProviderFactory(org.apache.ranger.audit.provider.AuditProviderFactory) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

RangerPluginConfig (org.apache.ranger.authorization.hadoop.config.RangerPluginConfig)16 RangerPluginContext (org.apache.ranger.plugin.policyengine.RangerPluginContext)6 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)4 GsonBuilder (com.google.gson.GsonBuilder)3 RangerDefaultAuditHandler (org.apache.ranger.plugin.audit.RangerDefaultAuditHandler)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Properties (java.util.Properties)2 RangerAdminClient (org.apache.ranger.admin.client.RangerAdminClient)2 AuditHandler (org.apache.ranger.audit.provider.AuditHandler)2 AuditProviderFactory (org.apache.ranger.audit.provider.AuditProviderFactory)2 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)2 RangerAccessRequest (org.apache.ranger.plugin.policyengine.RangerAccessRequest)2 RangerPolicyEngineImpl (org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl)2 RangerPolicyEngineOptions (org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions)2 BeforeClass (org.junit.BeforeClass)2 Gson (com.google.gson.Gson)1 InputStream (java.io.InputStream)1