Skip to content

Commit 921f922

Browse files
committed
Remove circular dependency and do not init class
1 parent 5eb229d commit 921f922

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,18 @@ public class PlatformName {
4949
* own implementations of many security packages and Cipher suites.
5050
* Note that these are not provided in Semeru runtimes:
5151
* See https://developer.ibm.com/languages/java/semeru-runtimes/
52+
* The class used is present in any supported IBM JTE Runtimes.
5253
*/
53-
public static final boolean IBM_JAVA = shouldUseIbmPackages();
54+
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM") &&
55+
hasClass("com.ibm.security.auth.module.JAASLoginModule");
5456

55-
private static boolean shouldUseIbmPackages() {
56-
if (JAVA_VENDOR_NAME.contains("IBM")) {
57-
try {
58-
/**
59-
* This class is provided by all supported IBM JTE Runtimes,
60-
* but ensures we do not make assumptions of existence of
61-
* specialised security modules based on vendor alone.
62-
*/
63-
Class.forName("com.ibm.security.auth.module.JAASLoginModule");
64-
return true;
65-
} catch(ClassNotFoundException ignored) {}
57+
private static boolean hasClass(String className) {
58+
try {
59+
Thread.currentThread().getContextClassLoader().loadClass(className);
60+
return true;
61+
} catch(ClassNotFoundException ignored) {
62+
return false;
6663
}
67-
68-
return false;
6964
}
7065

7166
public static void main(String[] args) {

hadoop-common-project/hadoop-minikdc/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
<artifactId>junit</artifactId>
4949
<scope>compile</scope>
5050
</dependency>
51-
<dependency>
52-
<groupId>org.apache.hadoop</groupId>
53-
<artifactId>hadoop-auth</artifactId>
54-
<scope>test</scope>
55-
</dependency>
5651
</dependencies>
5752

5853
<build>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@
3737
import java.util.HashMap;
3838
import java.util.Arrays;
3939

40-
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
41-
4240
public class TestMiniKdc extends KerberosSecurityTestcase {
41+
private static final boolean IBM_JAVA = shouldUseIbmPackages();
42+
43+
private static boolean shouldUseIbmPackages() {
44+
if (System.getProperty("java.vendor").contains("IBM")) {
45+
try {
46+
Class.forName("com.ibm.security.auth.module.JAASLoginModule");
47+
return true;
48+
} catch(ClassNotFoundException ignored) {}
49+
}
50+
51+
return false;
52+
}
4353

4454
@Test
4555
public void testMiniKdcStart() {

0 commit comments

Comments
 (0)