You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by co...@apache.org on 2022/12/19 08:10:01 UTC

[directory-kerby] branch trunk updated: Fix checks for ibm security classes to work with recent IBM Semeru JDKs

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

coheigea pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/directory-kerby.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 73cbc009 Fix checks for ibm security classes to work with recent IBM Semeru JDKs
     new a56ab976 Merge pull request #111 from linux-on-ibm-z/ibm-semeru-jdk-support
73cbc009 is described below

commit 73cbc009f774f6e6d22611332891a490a279c273
Author: Jonathan Albrecht <jo...@ibm.com>
AuthorDate: Mon Nov 7 16:02:52 2022 -0500

    Fix checks for ibm security classes to work with recent IBM Semeru JDKs
---
 .../kerby/has/common/util/HasJaasLoginUtil.java    |  4 +++-
 .../apache/kerby/has/common/util/PlatformName.java | 23 ++++++++++++++++++--
 .../main/java/org/apache/kerby/util/SysUtil.java   | 25 ++++++++++++++++++++++
 .../apache/kerby/kerberos/kerb/admin/AuthUtil.java |  5 ++++-
 .../kerby/kerberos/kerb/client/JaasKrbUtil.java    |  5 ++++-
 .../kerby/kerberos/tool/kadmin/AuthUtil.java       |  5 ++++-
 6 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/HasJaasLoginUtil.java b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/HasJaasLoginUtil.java
index 3eb68dc5..3a0342cb 100644
--- a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/HasJaasLoginUtil.java
+++ b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/HasJaasLoginUtil.java
@@ -31,6 +31,8 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import static org.apache.kerby.has.common.util.PlatformName.IBM_JAVA;
+
 /**
  * JAAS utilities for Has login.
  */
@@ -40,7 +42,7 @@ public class HasJaasLoginUtil {
     public static final boolean ENABLE_DEBUG = true;
 
     private static String getKrb5LoginModuleName() {
-        return System.getProperty("java.vendor").contains("IBM")
+        return IBM_JAVA
             ? "com.ibm.security.auth.module.Krb5LoginModule"
             : "org.apache.kerby.has.client.HasLoginModule";
     }
diff --git a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/PlatformName.java b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/PlatformName.java
index 8a2c9613..f4b8bc99 100644
--- a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/PlatformName.java
+++ b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/PlatformName.java
@@ -49,9 +49,28 @@ public class PlatformName {
 
   /**
    * A public static variable to indicate the current java vendor is
-   * IBM java or not.
+   * IBM and the type is Java Technology Edition which provides its
+   * own implementations of many security packages and Cipher suites.
+   * Note that these are not provided in Semeru runtimes:
+   * See https://developer.ibm.com/languages/java/semeru-runtimes/
+   * The class used is present in any supported IBM JTE Runtimes.
    */
-  public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");
+  public static final boolean IBM_JAVA = shouldUseIbmSecurity();
+
+  private static boolean shouldUseIbmSecurity() {
+    if (!JAVA_VENDOR_NAME.contains("IBM")) {
+      return false;
+    }
+
+    try {
+      Class.forName("com.ibm.security.auth.module.JAASLoginModule",
+        false,
+        PlatformName.class.getClassLoader());
+      return true;
+    } catch (Exception ignored) { }
+
+    return false;
+  }
 
   public static void main(String[] args) {
     System.out.println(PLATFORM_NAME);
diff --git a/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/SysUtil.java b/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/SysUtil.java
index d6078711..62e78cea 100644
--- a/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/SysUtil.java
+++ b/kerby-common/kerby-util/src/main/java/org/apache/kerby/util/SysUtil.java
@@ -32,4 +32,29 @@ public final class SysUtil {
         return new File(tmpDir);
     }
 
+  /**
+   * A public static variable to indicate the current java vendor is
+   * IBM and the type is Java Technology Edition which provides its
+   * own implementations of many security packages and Cipher suites.
+   * Note that these are not provided in Semeru runtimes:
+   * See https://developer.ibm.com/languages/java/semeru-runtimes/
+   * The class used is present in any supported IBM JTE Runtimes.
+   */
+  public static final boolean IBM_JAVA = shouldUseIbmSecurity();
+
+  private static boolean shouldUseIbmSecurity() {
+    if (!System.getProperty("java.vendor").contains("IBM")) {
+      return false;
+    }
+
+    try {
+      Class.forName("com.ibm.security.auth.module.JAASLoginModule",
+        false,
+        SysUtil.class.getClassLoader());
+      return true;
+    } catch (Exception ignored) { }
+
+    return false;
+  }
+
 }
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/AuthUtil.java b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/AuthUtil.java
index dad1e747..969f8315 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/AuthUtil.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/AuthUtil.java
@@ -26,6 +26,9 @@ import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+
+import static org.apache.kerby.util.SysUtil.IBM_JAVA;
+
 import java.io.File;
 import java.security.Principal;
 import java.util.HashMap;
@@ -38,7 +41,7 @@ public class AuthUtil {
     public static final boolean ENABLE_DEBUG = false;
 
     private static String getKrb5LoginModuleName() {
-        return System.getProperty("java.vendor").contains("IBM")
+        return IBM_JAVA
             ? "com.ibm.security.auth.module.Krb5LoginModule"
             : "com.sun.security.auth.module.Krb5LoginModule";
     }
diff --git a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/JaasKrbUtil.java b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/JaasKrbUtil.java
index 7cdcb7c6..135fad19 100644
--- a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/JaasKrbUtil.java
+++ b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/JaasKrbUtil.java
@@ -29,6 +29,9 @@ import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+
+import static org.apache.kerby.util.SysUtil.IBM_JAVA;
+
 import java.io.File;
 import java.io.IOException;
 import java.security.Principal;
@@ -106,7 +109,7 @@ public final class JaasKrbUtil {
     }
 
     private static String getKrb5LoginModuleName() {
-        return System.getProperty("java.vendor").contains("IBM")
+        return IBM_JAVA
                 ? "com.ibm.security.auth.module.Krb5LoginModule"
                 : "com.sun.security.auth.module.Krb5LoginModule";
     }
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/AuthUtil.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/AuthUtil.java
index 0062a1e3..9c8bbe1b 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/AuthUtil.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/AuthUtil.java
@@ -25,6 +25,9 @@ import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+
+import static org.apache.kerby.util.SysUtil.IBM_JAVA;
+
 import java.io.File;
 import java.security.Principal;
 import java.util.HashMap;
@@ -37,7 +40,7 @@ public class AuthUtil {
     public static final boolean ENABLE_DEBUG = true;
 
     private static String getKrb5LoginModuleName() {
-        return System.getProperty("java.vendor").contains("IBM")
+        return IBM_JAVA
             ? "com.ibm.security.auth.module.Krb5LoginModule"
             : "com.sun.security.auth.module.Krb5LoginModule";
     }