@@ -49,6 +49,13 @@ public void testDefaultConfigs() {
4949 assertEquals ("ranger-pdp" , config .getAppType ());
5050 }
5151
52+ @ Test
53+ public void testLegacyConfigs () {
54+ RangerAuthzConfig config = new RangerAuthzConfig (createLegacyDevHiveProperties ());
55+
56+ validateLegacyProperties (config .getServiceProperties ("dev_hive" , "hive" ));
57+ }
58+
5259 @ Test
5360 public void testAuditConfigsV2 () {
5461 RangerAuthzConfig config = new RangerAuthzConfig (createAuditV2Properties ());
@@ -78,9 +85,20 @@ public void testAllAuthzConfigs() {
7885 validateDevHdfsProperties (config .getServiceProperties ("dev_hdfs" , "hdfs" ));
7986 validateAuditConfigV2 (config .getAuditProperties ());
8087 validateAuditConfigV3 (config .getAuditProperties ());
88+ validateAuditConfigLegacy (config .getAuditProperties ());
8189 assertEquals ("ranger-pdp" , config .getAppType ());
8290 }
8391
92+ @ Test
93+ public void testLegacyAuditConfigs () {
94+ RangerAuthzConfig config = new RangerAuthzConfig (createAuditLegacyProperties ());
95+ Properties auditProperties = config .getAuditProperties ();
96+
97+ assertEquals (10 , auditProperties .size ());
98+
99+ validateAuditConfigLegacy (auditProperties );
100+ }
101+
84102 private void validateDevHiveProperties (Properties prop ) {
85103 assertEquals (7 , prop .size ());
86104 assertEquals ("org.apache.ranger.admin.client.RangerAdminRESTClient" , prop .getProperty ("ranger.plugin.hive.policy.source.impl" ));
@@ -114,6 +132,20 @@ private void validateDevHdfsProperties(Properties prop) {
114132 assertEquals ("/etc/ranger/policycache" , prop .getProperty ("ranger.plugin.hdfs.policy.cache.dir" ));
115133 }
116134
135+ private void validateLegacyProperties (Properties prop ) {
136+ assertEquals (10 , prop .size ());
137+ assertEquals ("dev_hive" , prop .getProperty ("ranger.plugin.hive.service.name" ));
138+ assertEquals ("org.apache.ranger.admin.client.RangerAdminRESTClient" , prop .getProperty ("ranger.plugin.hive.policy.source.impl" ));
139+ assertEquals ("http://localhost:6080" , prop .getProperty ("ranger.plugin.hive.policy.rest.url" ));
140+ assertEquals ("/etc/hive/conf/ranger-policymgr-ssl.xml" , prop .getProperty ("ranger.plugin.hive.policy.rest.ssl.config.file" ));
141+ assertEquals ("120000" , prop .getProperty ("ranger.plugin.hive.policy.rest.client.connection.timeoutMs" ));
142+ assertEquals ("30000" , prop .getProperty ("ranger.plugin.hive.policy.rest.client.read.timeoutMs" ));
143+ assertEquals ("30000" , prop .getProperty ("ranger.plugin.hive.policy.pollIntervalMs" ));
144+ assertEquals ("/etc/ranger/policycache" , prop .getProperty ("ranger.plugin.hive.policy.cache.dir" ));
145+ assertEquals ("hadoopdev-clientcert.jks" , prop .getProperty ("xasecure.policymgr.clientssl.keystore" ));
146+ assertEquals ("cacerts-xasecure.jks" , prop .getProperty ("xasecure.policymgr.clientssl.truststore" ));
147+ }
148+
117149 private void validateAuditConfigV2 (Properties prop ) {
118150 assertEquals ("true" , prop .getProperty ("xasecure.audit.is.enabled" ));
119151 assertEquals ("false" , prop .getProperty ("xasecure.audit.hdfs.is.enabled" ));
@@ -157,6 +189,21 @@ private void validateAuditConfigV3(Properties props) {
157189 assertEquals ("ranger_audits" , props .getProperty ("xasecure.audit.destination.solr.collection" ));
158190 }
159191
192+ private void validateAuditConfigLegacy (Properties props ) {
193+ assertEquals ("true" , props .getProperty ("xasecure.audit.is.enabled" ));
194+ assertEquals ("false" , props .getProperty ("xasecure.audit.destination.hdfs" ));
195+ assertEquals ("true" , props .getProperty ("xasecure.audit.destination.solr" ));
196+ assertEquals ("false" , props .getProperty ("xasecure.audit.destination.log4j" ));
197+
198+ assertEquals ("hdfs://namenode:8020/ranger/audit" , props .getProperty ("xasecure.audit.destination.hdfs.dir" ));
199+ assertEquals ("%app-type%/%time:yyyyMMdd%" , props .getProperty ("xasecure.audit.destination.hdfs.subdir" ));
200+ assertEquals ("%app-type%_ranger_audit_%hostname%.log" , props .getProperty ("xasecure.audit.destination.hdfs.filename.format" ));
201+ assertEquals ("org.apache.ranger.audit.utils.RangerJSONAuditWriter" , props .getProperty ("xasecure.audit.destination.hdfs.filewriter.impl" ));
202+
203+ assertEquals ("http://localhost:6083/solr/ranger_audits" , props .getProperty ("xasecure.audit.destination.solr.urls" ));
204+ assertEquals ("ranger_audits" , props .getProperty ("xasecure.audit.destination.solr.collection" ));
205+ }
206+
160207 private static Properties createDefaultProperties () {
161208 Properties props = new Properties ();
162209
@@ -173,6 +220,23 @@ private static Properties createDefaultProperties() {
173220 return props ;
174221 }
175222
223+ private static Properties createLegacyDevHiveProperties () {
224+ Properties props = new Properties ();
225+
226+ props .put ("ranger.plugin.hive.service.name" , "dev_hive" );
227+ props .put ("ranger.plugin.hive.policy.source.impl" , "org.apache.ranger.admin.client.RangerAdminRESTClient" );
228+ props .put ("ranger.plugin.hive.policy.rest.url" , "http://localhost:6080" );
229+ props .put ("ranger.plugin.hive.policy.rest.ssl.config.file" , "/etc/hive/conf/ranger-policymgr-ssl.xml" );
230+ props .put ("ranger.plugin.hive.policy.rest.client.connection.timeoutMs" , "120000" );
231+ props .put ("ranger.plugin.hive.policy.rest.client.read.timeoutMs" , "30000" );
232+ props .put ("ranger.plugin.hive.policy.pollIntervalMs" , "30000" );
233+ props .put ("ranger.plugin.hive.policy.cache.dir" , "/etc/ranger/policycache" );
234+ props .put ("xasecure.policymgr.clientssl.keystore" , "hadoopdev-clientcert.jks" );
235+ props .put ("xasecure.policymgr.clientssl.truststore" , "cacerts-xasecure.jks" );
236+
237+ return props ;
238+ }
239+
176240 private static Properties createAuditV2Properties () {
177241 Properties props = new Properties ();
178242
@@ -224,11 +288,31 @@ private static Properties createAuditV3Properties() {
224288 return props ;
225289 }
226290
291+ private static Properties createAuditLegacyProperties () {
292+ Properties props = new Properties ();
293+
294+ props .setProperty ("xasecure.audit.is.enabled" , "true" );
295+ props .setProperty ("xasecure.audit.destination.hdfs" , "false" );
296+ props .setProperty ("xasecure.audit.destination.solr" , "true" );
297+ props .setProperty ("xasecure.audit.destination.log4j" , "false" );
298+
299+ props .setProperty ("xasecure.audit.destination.hdfs.dir" , "hdfs://namenode:8020/ranger/audit" );
300+ props .setProperty ("xasecure.audit.destination.hdfs.subdir" , "%app-type%/%time:yyyyMMdd%" );
301+ props .setProperty ("xasecure.audit.destination.hdfs.filename.format" , "%app-type%_ranger_audit_%hostname%.log" );
302+ props .setProperty ("xasecure.audit.destination.hdfs.filewriter.impl" , "org.apache.ranger.audit.utils.RangerJSONAuditWriter" );
303+
304+ props .setProperty ("xasecure.audit.destination.solr.urls" , "http://localhost:6083/solr/ranger_audits" );
305+ props .setProperty ("xasecure.audit.destination.solr.collection" , "ranger_audits" );
306+
307+ return props ;
308+ }
309+
227310 private static Properties createAllAuthzProperties () {
228311 Properties props = createDefaultProperties ();
229312
230313 props .putAll (createAuditV2Properties ());
231314 props .putAll (createAuditV3Properties ());
315+ props .putAll (createAuditLegacyProperties ());
232316
233317 props .setProperty ("ranger.authz.service.hive.service.name" , "dev_hive" );
234318
0 commit comments