IBM JDK Class not found error when handling SASL
Attempt to load multiple IBM classes but fallback on loading the Sun class if the IBM one is not found.
Reviewers: Mickael Maison Ismael Juma
@@ -49,7 +49,10 @@ public enum KerberosError {
static {
try {
- if (Java.isIbmJdk()) {
+ // different IBM JDKs versions include different security implementations
+ if (Java.isIbmJdk() && canLoad("com.ibm.security.krb5.KrbException")) {
+ KRB_EXCEPTION_CLASS = Class.forName("com.ibm.security.krb5.KrbException");
+ } else if (Java.isIbmJdk() && canLoad("com.ibm.security.krb5.internal.KrbException")) {
KRB_EXCEPTION_CLASS = Class.forName("com.ibm.security.krb5.internal.KrbException");
} else {
KRB_EXCEPTION_CLASS = Class.forName("sun.security.krb5.KrbException");
@@ -60,6 +63,15 @@ public enum KerberosError {
}
}
+ private static boolean canLoad(String clazz) {
+ try {
+ Class.forName(clazz);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
private final int errorCode;
private final boolean retriable;
