Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

/**
* The {@link KerberosAuthenticator} implements the Kerberos SPNEGO authentication sequence.
Expand Down Expand Up @@ -88,7 +88,7 @@ private static class KerberosConfiguration extends Configuration {

/* Return the OS login module class name */
private static String getOSLoginModuleName() {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
if (windows) {
return is64Bit ? "com.ibm.security.auth.module.Win64LoginModule"
: "com.ibm.security.auth.module.NTLoginModule";
Expand Down Expand Up @@ -117,14 +117,14 @@ private static String getOSLoginModuleName() {

static {
String ticketCache = System.getenv("KRB5CCNAME");
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
USER_KERBEROS_OPTIONS.put("useDefaultCcache", "true");
} else {
USER_KERBEROS_OPTIONS.put("doNotPrompt", "true");
USER_KERBEROS_OPTIONS.put("useTicketCache", "true");
}
if (ticketCache != null) {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
// The first value searched when "useDefaultCcache" is used.
System.setProperty("KRB5CCNAME", ticketCache);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.security.authentication.util;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class KerberosUtil {

/* Return the Kerberos login module name */
public static String getKrb5LoginModuleName() {
return (IBM_JAVA)
return (USE_IBM_JAVA_PACKAGES)
? "com.ibm.security.auth.module.Krb5LoginModule"
: "com.sun.security.auth.module.Krb5LoginModule";
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public static String getDomainRealm(String shortprinc) {
Object principalName; //of type sun.security.krb5.PrincipalName or IBM equiv
String realmString = null;
try {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
classRef = Class.forName("com.ibm.security.krb5.PrincipalName");
} else {
classRef = Class.forName("sun.security.krb5.PrincipalName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,34 @@ 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/
Comment thread
JackBuggins marked this conversation as resolved.
Outdated
*/
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");
public static final boolean USE_IBM_JAVA_PACKAGES = shouldUseIbmPackages();

/*
* IBM_JAVA must be preserved due to the public nature of the property.
*/
@Deprecated
public static final boolean IBM_JAVA = USE_IBM_JAVA_PACKAGES;
Comment thread
JackBuggins marked this conversation as resolved.
Outdated

private static boolean shouldUseIbmPackages() {
if (JAVA_VENDOR_NAME.contains("IBM")) {
try {
/**
* This class is provided by all supported IBM JTE Runtimes,
* but ensures we do not make assumptions of existence of
* specialised security modules based on vendor alone.
Comment thread
JackBuggins marked this conversation as resolved.
Outdated
*/
Class.forName("com.ibm.security.auth.module.JAASLoginModule");
return true;
} catch(ClassNotFoundException ignored) {}
}

return false;
}

public static void main(String[] args) {
System.out.println(PLATFORM_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.Set;
import java.util.concurrent.Callable;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

/**
* Test helper class for Java Kerberos setup.
Expand Down Expand Up @@ -67,7 +67,7 @@ public KerberosConfiguration(String principal) {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, String> options = new HashMap<String, String>();
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
options.put("useKeytab", KerberosTestUtils.getKeytabFile().startsWith("file://") ?
KerberosTestUtils.getKeytabFile() : "file://" + KerberosTestUtils.getKeytabFile());
options.put("principal", principal);
Expand All @@ -86,7 +86,7 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
}
String ticketCache = System.getenv("KRB5CCNAME");
if (ticketCache != null) {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
// IBM JAVA only respect system property and not env variable
// The first value searched when "useDefaultCcache" is used.
System.setProperty("KRB5CCNAME", ticketCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_TOKEN_FILES;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_TOKENS;
import static org.apache.hadoop.security.UGIExceptionMessages.*;
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;
import static org.apache.hadoop.util.StringUtils.getTrimmedStringCollection;

import org.apache.hadoop.classification.VisibleForTesting;
Expand Down Expand Up @@ -430,7 +430,7 @@ static Optional<ExecutorService> getKerberosLoginRenewalExecutor() {
/* Return the OS login module class name */
/* For IBM JDK, use the common OS login module class name for all platforms */
private static String getOSLoginModuleName() {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
return "com.ibm.security.auth.module.JAASLoginModule";
} else {
return windows ? "com.sun.security.auth.module.NTLoginModule"
Expand All @@ -445,7 +445,7 @@ private static Class<? extends Principal> getOsPrincipalClass() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
try {
String principalClass = null;
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
principalClass = "com.ibm.security.auth.UsernamePrincipal";
} else {
principalClass = windows ? "com.sun.security.auth.NTUserPrincipal"
Expand Down Expand Up @@ -2203,7 +2203,7 @@ private AppConfigurationEntry getKerberosEntry() {
}

// use keytab if given else fallback to ticket cache.
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
if (params.containsKey(LoginParam.KEYTAB)) {
final String keytab = params.get(LoginParam.KEYTAB);
if (keytab != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.hadoop.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.hadoop.util.PlatformName.JAVA_VENDOR_NAME;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -102,11 +102,11 @@ public enum Mode { CLIENT, SERVER }
"ssl.server.exclude.cipher.list";

public static final String KEY_MANAGER_SSLCERTIFICATE =
JAVA_VENDOR_NAME.contains("IBM") ? "ibmX509" :
USE_IBM_JAVA_PACKAGES ? "ibmX509" :
KeyManagerFactory.getDefaultAlgorithm();

public static final String TRUST_MANAGER_SSLCERTIFICATE =
JAVA_VENDOR_NAME.contains("IBM") ? "ibmX509" :
USE_IBM_JAVA_PACKAGES ? "ibmX509" :
TrustManagerFactory.getDefaultAlgorithm();

public static final String KEYSTORES_FACTORY_CLASS_KEY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import org.apache.hadoop.security.alias.LocalJavaKeyStoreProvider;
import org.apache.hadoop.test.GenericTestUtils;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Logger;
Expand All @@ -99,7 +99,7 @@ public class TestConfiguration {
"./test-config-multi-byte-saved-TestConfiguration.xml").getAbsolutePath();
final static Random RAN = new Random();
final static String XMLHEADER =
IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>":
USE_IBM_JAVA_PACKAGES?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>":
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><configuration>";

/** Four apostrophes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@
import java.util.Arrays;

public class TestMiniKdc extends KerberosSecurityTestcase {
private static final boolean IBM_JAVA = System.getProperty("java.vendor")
.contains("IBM");
private static final boolean USE_IBM_JAVA_PACKAGES = shouldUseIbmPackages();
Comment thread
JackBuggins marked this conversation as resolved.
Outdated

private static boolean shouldUseIbmPackages() {
if (System.getProperty("java.vendor").contains("IBM")) {
try {
Class.forName("com.ibm.security.auth.module.JAASLoginModule");
return true;
} catch(ClassNotFoundException ignored) {}
}

return false;
}

@Test
public void testMiniKdcStart() {
MiniKdc kdc = getKdc();
Expand Down Expand Up @@ -98,7 +109,7 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, String> options = new HashMap<String, String>();
options.put("principal", principal);
options.put("refreshKrb5Config", "true");
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
options.put("useKeytab", keytab);
options.put("credsType", "both");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import static org.apache.hadoop.registry.client.impl.zk.ZookeeperConfigOptions.*;
import static org.apache.hadoop.registry.client.api.RegistryConstants.*;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

/**
* Implement the registry security ... a self contained service for
Expand Down Expand Up @@ -616,7 +616,7 @@ public static String getKerberosAuthModuleForJVM() {
* Note the semicolon on the last entry
*/
private static final String JAAS_ENTRY =
(IBM_JAVA ?
(USE_IBM_JAVA_PACKAGES ?
"%s { %n"
+ " %s required%n"
+ " useKeytab=\"%s\"%n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

class KerberosConfiguration extends javax.security.auth.login.Configuration {
private String principal;
Expand Down Expand Up @@ -54,7 +54,7 @@ public static javax.security.auth.login.Configuration createServerConfig(
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, String> options = new HashMap<String, String>();
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
options.put("useKeytab", keytab.startsWith("file://")
? keytab
: "file://" + keytab);
Expand All @@ -74,7 +74,7 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
}
String ticketCache = System.getenv("KRB5CCNAME");
if (ticketCache != null) {
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
// IBM JAVA only respect system property and not env variable
// The first value searched when "useDefaultCcache" is used.
System.setProperty("KRB5CCNAME", ticketCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import static org.apache.hadoop.security.authentication.util.KerberosName.DEFAULT_MECHANISM;
import static org.apache.hadoop.security.authentication.util.KerberosName.MECHANISM_HADOOP;
import static org.apache.hadoop.security.authentication.util.KerberosName.MECHANISM_MIT;
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.apache.hadoop.util.PlatformName.USE_IBM_JAVA_PACKAGES;

import org.junit.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -141,7 +141,7 @@ public void testKerberosAuth() throws Throwable {
Object kerb5LoginObject = kerb5LoginConstr.newInstance();
final Map<String, String> options = new HashMap<String, String>();
options.put("debug", "true");
if (IBM_JAVA) {
if (USE_IBM_JAVA_PACKAGES) {
options.put("useKeytab",
keytab_alice.getAbsolutePath().startsWith("file://")
? keytab_alice.getAbsolutePath()
Expand Down