You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by rm...@apache.org on 2021/09/23 17:37:42 UTC

[ranger] branch master updated: RANGER-3243:Build fails on JDK 8 and 11

This is an automated email from the ASF dual-hosted git repository.

rmani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 58a104b  RANGER-3243:Build fails on JDK 8 and 11
58a104b is described below

commit 58a104b862b03c55a6b48235f75718451d7c5098
Author: Martin Grigorov <mg...@apache.org>
AuthorDate: Thu Sep 23 10:30:12 2021 -0700

    RANGER-3243:Build fails on JDK 8 and 11
---
 .../hadoop/crypto/key/RangerSafenetKeySecure.java  | 16 +++++++------
 pom.xml                                            |  7 +++---
 ugsync-util/pom.xml                                | 26 ++++++++++++++++++++++
 ugsync/pom.xml                                     |  2 +-
 .../process/TestUnixUserGroupBuilder.java          |  4 ++--
 5 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/kms/src/main/java/org/apache/hadoop/crypto/key/RangerSafenetKeySecure.java b/kms/src/main/java/org/apache/hadoop/crypto/key/RangerSafenetKeySecure.java
index 371e367..b9ab88f 100644
--- a/kms/src/main/java/org/apache/hadoop/crypto/key/RangerSafenetKeySecure.java
+++ b/kms/src/main/java/org/apache/hadoop/crypto/key/RangerSafenetKeySecure.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.log4j.Logger;
 import com.sun.org.apache.xml.internal.security.utils.Base64;
 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.security.Key;
 import java.security.KeyStore;
@@ -68,14 +69,15 @@ public class RangerSafenetKeySecure implements RangerKMSMKI {
 		try {
 			int javaVersion = getJavaVersion();
 			/*Minimum java requirement for Ranger KMS is Java 8 and Maximum java supported by Ranger KMS is Java 11*/
-			if(javaVersion == 8){
-				provider = new sun.security.pkcs11.SunPKCS11(pkcs11CfgFilePath);
-			}else if(javaVersion == 9 || javaVersion == 10 || javaVersion == 11){
+			if(javaVersion <= 8){
+				Class<?> providerClass = Class.forName("sun.security.pkcs11.SunPKCS11");
+				Constructor<?> constructor = providerClass.getConstructor(String.class);
+				provider = (Provider) constructor.newInstance(pkcs11CfgFilePath);
+			}else if(javaVersion > 8){
 				Class<Provider> cls = Provider.class;
-				Method configureMethod = null;
-				configureMethod = cls.getDeclaredMethod("configure", String.class);
+				Method configureMethod = cls.getDeclaredMethod("configure", String.class);
 				provider = Security.getProvider(providerType);
-				if(configureMethod != null){
+				if(provider != null){
 					provider = (Provider) configureMethod.invoke(provider,pkcs11CfgFilePath);
 				}
 			}
@@ -191,4 +193,4 @@ public class RangerSafenetKeySecure implements RangerKMSMKI {
 			return Integer.parseInt(version);
 		}
 
-}
\ No newline at end of file
+}
diff --git a/pom.xml b/pom.xml
index 36036a6..3b73934 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,7 +120,7 @@
         <guice.version>4.0</guice.version>
         <hadoop.version>3.3.0</hadoop.version>
         <ozone.version>1.0.0</ozone.version>
-        <hamcrest.all.version>1.3</hamcrest.all.version>
+        <hamcrest.version>2.2</hamcrest.version>
         <hbase.version>2.2.6</hbase.version>
         <hive.version>3.1.2</hive.version>
         <hive.storage-api.version>2.7.2</hive.storage-api.version>
@@ -171,6 +171,7 @@
         <mysql-connector-java.version>5.1.31</mysql-connector-java.version>
         <netty-all.version>4.1.63.Final</netty-all.version>
         <noggit.version>0.8</noggit.version>
+        <orc.core.version>1.6.7</orc.core.version>
         <owasp-java-html-sanitizer.version>r239</owasp-java-html-sanitizer.version>
         <paranamer.version>2.3</paranamer.version>
         <presto.version>333</presto.version>
@@ -773,8 +774,8 @@
             </dependency>
             <dependency>
                 <groupId>org.hamcrest</groupId>
-                <artifactId>hamcrest-all</artifactId>
-                <version>${hamcrest.all.version}</version>
+                <artifactId>hamcrest</artifactId>
+                <version>${hamcrest.version}</version>
                 <scope>test</scope>
             </dependency>
             <dependency>
diff --git a/ugsync-util/pom.xml b/ugsync-util/pom.xml
index aa992ca..990eabe 100644
--- a/ugsync-util/pom.xml
+++ b/ugsync-util/pom.xml
@@ -50,4 +50,30 @@
         </dependency>
     </dependencies>
 
+    <profiles>
+        <profile>
+            <id>java9AndUp</id>
+            <activation>
+                <jdk>[9,)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>javax.xml.bind</groupId>
+                    <artifactId>jaxb-api</artifactId>
+                    <version>2.3.1</version>
+                </dependency>
+                <dependency>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-core</artifactId>
+                    <version>3.0.0</version>
+                </dependency>
+                <dependency>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                    <version>3.0.0</version>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
 </project>
diff --git a/ugsync/pom.xml b/ugsync/pom.xml
index 07e0c58..40d38da 100644
--- a/ugsync/pom.xml
+++ b/ugsync/pom.xml
@@ -118,7 +118,7 @@
     </dependency>
         <dependency>
             <groupId>org.hamcrest</groupId>
-            <artifactId>hamcrest-all</artifactId>
+            <artifactId>hamcrest</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.directory.server</groupId>
diff --git a/ugsync/src/test/java/org/apache/ranger/unixusersync/process/TestUnixUserGroupBuilder.java b/ugsync/src/test/java/org/apache/ranger/unixusersync/process/TestUnixUserGroupBuilder.java
index 30820ce..526efa0 100644
--- a/ugsync/src/test/java/org/apache/ranger/unixusersync/process/TestUnixUserGroupBuilder.java
+++ b/ugsync/src/test/java/org/apache/ranger/unixusersync/process/TestUnixUserGroupBuilder.java
@@ -26,7 +26,7 @@ import org.junit.Test;
 import java.util.Map;
 import java.util.Set;
 
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNull;
@@ -40,7 +40,7 @@ public class TestUnixUserGroupBuilder {
     private UserGroupSyncConfig config;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         config = UserGroupSyncConfig.getInstance();
         config.setProperty("ranger.usersync.unix.minUserId", "0");
         config.setProperty("ranger.usersync.unix.minGroupId", "0");