Skip to content

Commit c5b360f

Browse files
authored
HADOOP-18329. Support for IBM Semeru JVM > 11.0.15.0 Vendor Name Changes (#4537) (#5208)
The static boolean PlatformName.IBM_JAVA now identifies Java 11+ IBM Semeru runtimes as IBM JVM releases. Contributed by Jack Buggins.
1 parent 50a0f33 commit c5b360f

File tree

2 files changed

+92
-11
lines changed

2 files changed

+92
-11
lines changed

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/util/PlatformName.java

+60-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.hadoop.util;
2020

21+
import java.security.AccessController;
22+
import java.security.PrivilegedAction;
23+
import java.util.Arrays;
24+
2125
import org.apache.hadoop.classification.InterfaceAudience;
2226
import org.apache.hadoop.classification.InterfaceStability;
2327

@@ -33,21 +37,71 @@ public class PlatformName {
3337
* per the java-vm.
3438
*/
3539
public static final String PLATFORM_NAME =
36-
(System.getProperty("os.name").startsWith("Windows")
37-
? System.getenv("os") : System.getProperty("os.name"))
38-
+ "-" + System.getProperty("os.arch")
39-
+ "-" + System.getProperty("sun.arch.data.model");
40+
(System.getProperty("os.name").startsWith("Windows") ?
41+
System.getenv("os") : System.getProperty("os.name"))
42+
+ "-" + System.getProperty("os.arch") + "-"
43+
+ System.getProperty("sun.arch.data.model");
4044

4145
/**
4246
* The java vendor name used in this platform.
4347
*/
4448
public static final String JAVA_VENDOR_NAME = System.getProperty("java.vendor");
4549

50+
/**
51+
* Define a system class accessor that is open to changes in underlying implementations
52+
* of the system class loader modules.
53+
*/
54+
private static final class SystemClassAccessor extends ClassLoader {
55+
public Class<?> getSystemClass(String className) throws ClassNotFoundException {
56+
return findSystemClass(className);
57+
}
58+
}
59+
4660
/**
4761
* A public static variable to indicate the current java vendor is
48-
* IBM java or not.
62+
* IBM and the type is Java Technology Edition which provides its
63+
* own implementations of many security packages and Cipher suites.
64+
* Note that these are not provided in Semeru runtimes:
65+
* See https://developer.ibm.com/languages/java/semeru-runtimes for details.
4966
*/
50-
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");
67+
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM") &&
68+
hasIbmTechnologyEditionModules();
69+
70+
private static boolean hasIbmTechnologyEditionModules() {
71+
return Arrays.asList(
72+
"com.ibm.security.auth.module.JAASLoginModule",
73+
"com.ibm.security.auth.module.Win64LoginModule",
74+
"com.ibm.security.auth.module.NTLoginModule",
75+
"com.ibm.security.auth.module.AIX64LoginModule",
76+
"com.ibm.security.auth.module.LinuxLoginModule",
77+
"com.ibm.security.auth.module.Krb5LoginModule"
78+
).stream().anyMatch((module) -> isSystemClassAvailable(module));
79+
}
80+
81+
/**
82+
* In rare cases where different behaviour is performed based on the JVM vendor
83+
* this method should be used to test for a unique JVM class provided by the
84+
* vendor rather than using the vendor method. For example if on JVM provides a
85+
* different Kerberos login module testing for that login module being loadable
86+
* before configuring to use it is preferable to using the vendor data.
87+
*
88+
* @param className the name of a class in the JVM to test for
89+
* @return true if the class is available, false otherwise.
90+
*/
91+
private static boolean isSystemClassAvailable(String className) {
92+
return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
93+
try {
94+
// Using ClassLoader.findSystemClass() instead of
95+
// Class.forName(className, false, null) because Class.forName with a null
96+
// ClassLoader only looks at the boot ClassLoader with Java 9 and above
97+
// which doesn't look at all the modules available to the findSystemClass.
98+
new SystemClassAccessor().getSystemClass(className);
99+
return true;
100+
} catch (Exception ignored) {
101+
return false;
102+
}
103+
});
104+
}
51105

52106
public static void main(String[] args) {
53107
System.out.println(PLATFORM_NAME);

hadoop-common-project/hadoop-minikdc/src/test/java/org/apache/hadoop/minikdc/TestMiniKdc.java

+32-5
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,35 @@
3838
import java.util.Arrays;
3939

4040
public class TestMiniKdc extends KerberosSecurityTestcase {
41-
private static final boolean IBM_JAVA = System.getProperty("java.vendor")
42-
.contains("IBM");
41+
private static final boolean IBM_JAVA = shouldUseIbmPackages();
42+
// duplicated to avoid cycles in the build
43+
private static boolean shouldUseIbmPackages() {
44+
final List<String> ibmTechnologyEditionSecurityModules = Arrays.asList(
45+
"com.ibm.security.auth.module.JAASLoginModule",
46+
"com.ibm.security.auth.module.Win64LoginModule",
47+
"com.ibm.security.auth.module.NTLoginModule",
48+
"com.ibm.security.auth.module.AIX64LoginModule",
49+
"com.ibm.security.auth.module.LinuxLoginModule",
50+
"com.ibm.security.auth.module.Krb5LoginModule"
51+
);
52+
53+
if (System.getProperty("java.vendor").contains("IBM")) {
54+
return ibmTechnologyEditionSecurityModules
55+
.stream().anyMatch((module) -> isSystemClassAvailable(module));
56+
}
57+
58+
return false;
59+
}
60+
61+
private static boolean isSystemClassAvailable(String className) {
62+
try {
63+
Class.forName(className);
64+
return true;
65+
} catch (Exception ignored) {
66+
return false;
67+
}
68+
}
69+
4370
@Test
4471
public void testMiniKdcStart() {
4572
MiniKdc kdc = getKdc();
@@ -117,9 +144,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
117144
options.put("debug", "true");
118145

119146
return new AppConfigurationEntry[]{
120-
new AppConfigurationEntry(getKrb5LoginModuleName(),
121-
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
122-
options)};
147+
new AppConfigurationEntry(getKrb5LoginModuleName(),
148+
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
149+
options)};
123150
}
124151
}
125152

0 commit comments

Comments
 (0)