Skip to content

Fix checks for ibm security classes to work with recent IBM Semeru JDKs #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -31,6 +31,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.kerby.has.common.util.PlatformName.IBM_JAVA;

/**
* JAAS utilities for Has login.
*/
Expand All @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,29 @@ public static File getTempDir() {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
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;
Expand All @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
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;
Expand Down Expand Up @@ -106,7 +109,7 @@ public static Configuration useKeytab(String principal, File keytabFile) {
}

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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
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;
Expand All @@ -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";
}
Expand Down