Home:ALL Converter>Check whether a Kerberos KeyTab file is valid in Java

Check whether a Kerberos KeyTab file is valid in Java

Ask Time:2018-03-28T08:43:23         Author:haxney

Json Formatter

I'm working on a Java code base that checks whether a Kerberos KeyTab file is valid, but it uses the internal class sun.security.krb5.internal.ktab.KeyTab for its isValid() method. Currently, it is doing the following:

File keytabFile = new File("/path/to/keytab");
KeyTab keytab = KeyTab.getInstance(keytabFile);
boolean keytabIsValid = keytab.isValid();
if (!keytabIsValid) {
   throw new ApplicationSpecificException("Keytab is not valid");
}

Accessing this method is more of an annoyance in Java 9, so I'm looking for a way to avoid using this internal class, but browsing through the JDK source, I haven't seen anything that exposes the isValid() method or an equivalent in a non-internal class.

Are there options which don't rely on hacks like reflecting on private methods or accessing internal APIs?

Author:haxney,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49524405/check-whether-a-kerberos-keytab-file-is-valid-in-java
yy