You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2023/06/26 13:56:24 UTC

[knox] branch master updated: KNOX-2923 - Support for JDK 17 (#762)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2886e70ae KNOX-2923 - Support for JDK 17 (#762)
2886e70ae is described below

commit 2886e70ae9ba7ce2a634ce5164f8383eea574b29
Author: Sandeep Moré <mo...@gmail.com>
AuthorDate: Mon Jun 26 09:56:18 2023 -0400

    KNOX-2923 - Support for JDK 17 (#762)
    
    * KNOX-2923 - Support for JDK 17
    
    * KNOX-2923 - Fix issues with JDK 8 build and add JDK 17 support to knoxcli
    
    * KNOX-2923 - Fix the error in CI/CD  -URI is not hierarchical
    
    * KNOX-2923 - Fix an issue where maven builds were failing on JDK 8
    
    * KNOX-2923 - Use jetbrains repo to fetch pty4j artifacts
---
 .../security/ldap/SimpleLdapServerTest.java        |  2 +-
 gateway-demo-ldap/src/test/resources/log4j2.xml    | 29 ++++++++++++++
 gateway-demo-ldap/src/test/resources/users.ldif    | 44 ++++++++++++++++++++++
 gateway-release-common/home/bin/knox-functions.sh  |  8 ++++
 gateway-release/home/bin/knoxcli.sh                |  8 ++++
 gateway-server/pom.xml                             |  6 +++
 .../knox/gateway/util/X509CertificateUtil.java     |  2 +-
 pom.xml                                            | 12 ++++--
 8 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/gateway-demo-ldap/src/test/java/org/apache/knox/gateway/security/ldap/SimpleLdapServerTest.java b/gateway-demo-ldap/src/test/java/org/apache/knox/gateway/security/ldap/SimpleLdapServerTest.java
index f7bd4d667..d1fd156f9 100644
--- a/gateway-demo-ldap/src/test/java/org/apache/knox/gateway/security/ldap/SimpleLdapServerTest.java
+++ b/gateway-demo-ldap/src/test/java/org/apache/knox/gateway/security/ldap/SimpleLdapServerTest.java
@@ -41,7 +41,7 @@ public class SimpleLdapServerTest {
 
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
-    ldifFile = new File( ClassLoader.getSystemResource( "users.ldif" ).toURI() );
+    ldifFile = new File( SimpleLdapServerTest.class.getResource( "/users.ldif" ).toURI());
     ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", ldifFile, ldapTransport );
     ldap.start();
diff --git a/gateway-demo-ldap/src/test/resources/log4j2.xml b/gateway-demo-ldap/src/test/resources/log4j2.xml
new file mode 100644
index 000000000..c3f84a55b
--- /dev/null
+++ b/gateway-demo-ldap/src/test/resources/log4j2.xml
@@ -0,0 +1,29 @@
+<?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.
+-->
+<Configuration>
+    <Appenders>
+        <Console name="stdout" target="SYSTEM_OUT">
+            <PatternLayout pattern="%d{ISO8601} %-5p %m%n" />
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="error">
+            <AppenderRef ref="stdout"/>
+        </Root>
+    </Loggers>
+</Configuration>
diff --git a/gateway-demo-ldap/src/test/resources/users.ldif b/gateway-demo-ldap/src/test/resources/users.ldif
new file mode 100644
index 000000000..f75edb8b7
--- /dev/null
+++ b/gateway-demo-ldap/src/test/resources/users.ldif
@@ -0,0 +1,44 @@
+# 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.
+
+version: 1
+
+dn: dc=hadoop,dc=apache,dc=org
+objectclass: organization
+objectclass: dcObject
+o: Hadoop at Apache.org
+dc: hadoop
+description: Makers of Hadoop
+
+# entry for a sample people container
+# please replace with site specific values
+dn: ou=people,dc=hadoop,dc=apache,dc=org
+objectclass:top
+objectclass:organizationalUnit
+ou: people
+
+# entry for a sample end user
+# please replace with site specific values
+dn: uid=guest,ou=people,dc=hadoop,dc=apache,dc=org
+objectclass:top
+objectclass:person
+objectclass:organizationalPerson
+objectclass:inetOrgPerson
+cn: Guest
+sn: User
+uid: guest
+userPassword:guest-password
+
diff --git a/gateway-release-common/home/bin/knox-functions.sh b/gateway-release-common/home/bin/knox-functions.sh
index eef91eae8..1a5dc5cc6 100644
--- a/gateway-release-common/home/bin/knox-functions.sh
+++ b/gateway-release-common/home/bin/knox-functions.sh
@@ -164,6 +164,14 @@ function buildAppJavaOpts {
       addAppJavaOpts "${APP_JAVA_LIB_PATH}"
     fi
 
+    # Add properties to enable Knox to run on JDK 17
+    JAVA_VERSION=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
+    CHECK_VERSION_17="17"
+    if [[ "$JAVA_VERSION" == *"$CHECK_VERSION_17"* ]]; then
+        echo "Java version is $CHECK_VERSION_17. Adding properties to enable Knox to run on JDK 17"
+        addAppJavaOpts " --add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.pkcs=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED"
+    fi
+
     # echo "APP_JAVA_OPTS =" "${APP_JAVA_OPTS[@]}"
 }
 
diff --git a/gateway-release/home/bin/knoxcli.sh b/gateway-release/home/bin/knoxcli.sh
index 2bb32085e..08573c495 100755
--- a/gateway-release/home/bin/knoxcli.sh
+++ b/gateway-release/home/bin/knoxcli.sh
@@ -60,6 +60,14 @@ function buildAppJavaOpts {
       addAppJavaOpts "${APP_JAVA_LIB_PATH}"
     fi
 
+    # Add properties to enable Knox to run on JDK 17
+    JAVA_VERSION=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
+    CHECK_VERSION_17="17"
+    if [[ "$JAVA_VERSION" == *"$CHECK_VERSION_17"* ]]; then
+        echo "Java version is $CHECK_VERSION_17. Adding properties to enable Knox to run on JDK 17"
+        addAppJavaOpts " --add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.pkcs=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED"
+    fi
+
     # echo "APP_JAVA_OPTS =" "${APP_JAVA_OPTS[@]}"
 }
 
diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml
index fdc0ff790..88495cbcb 100644
--- a/gateway-server/pom.xml
+++ b/gateway-server/pom.xml
@@ -397,6 +397,12 @@
             <groupId>com.sun.xml.bind</groupId>
             <artifactId>jaxb-impl</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.glassfish.jaxb</groupId>
+            <artifactId>jaxb-runtime</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.knox</groupId>
             <artifactId>gateway-util-configinjector</artifactId>
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X509CertificateUtil.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X509CertificateUtil.java
index 155a4021b..741511bd4 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X509CertificateUtil.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X509CertificateUtil.java
@@ -143,7 +143,7 @@ public class X509CertificateUtil {
 
       // AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid);
       Class<?> algorithmIdClass = Class.forName(getAlgorithmIdModuleName());
-      Field md5WithRSAField = algorithmIdClass.getDeclaredField("md5WithRSAEncryption_oid");
+      Field md5WithRSAField = algorithmIdClass.getDeclaredField("RSAEncryption_oid");
       md5WithRSAField.setAccessible(true);
       Class<?> objectIdentifierClass = Class.forName(getObjectIdentifierModuleName());
 
diff --git a/pom.xml b/pom.xml
index 46a44d852..279c580e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -260,6 +260,7 @@
         <protobuf.version>3.16.3</protobuf.version>
         <powermock.version>2.0.9</powermock.version>
         <purejavacomm.version>0.0.11.1</purejavacomm.version>
+        <!-- After JDK 11 we can use 0.12.4 from maven central -->
         <pty4j.version>0.11.4</pty4j.version>
         <rest-assured.version>4.3.3</rest-assured.version>
         <shiro.version>1.10.0</shiro.version>
@@ -288,9 +289,9 @@
     </properties>
     <repositories>
         <repository>
-            <id>jcenter</id>
-            <name>jcenter</name>
-            <url>https://jcenter.bintray.com</url>
+            <id>jetbrains-pty4j</id>
+            <name>jetbrains-intellij-dependencies</name>
+            <url>https://packages.jetbrains.team/maven/p/ij/intellij-dependencies</url>
         </repository>
     </repositories>
     <profiles>
@@ -400,6 +401,7 @@
         </profile>
     </profiles>
 
+
     <build>
         <pluginManagement>
             <plugins>
@@ -524,6 +526,10 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
+                    <!-- For JDK 17 builds uncomment the following lines, make sure to remove space between - - (double dash) -->
+                    <!--
+                    <argLine>@{argLine} - -add-exports java.base/sun.security.x509=ALL-UNNAMED - -add-exports java.base/sun.security.pkcs=ALL-UNNAMED - - add-exports java.naming/com.sun.jndi.ldap=ALL-UNNAMED - -add-opens java.base/sun.security.util=ALL-UNNAMED</argLine>
+                    -->
                     <excludedGroups>
                         org.apache.knox.test.category.SlowTests,org.apache.knox.test.category.ManualTests,org.apache.knox.test.category.VerifyTest,org.apache.knox.test.category.ReleaseTest
                     </excludedGroups>