Enable detailed logging for Kerberos in Java

kerberos, logging

Solution

You can enable logging by setting system property `sun.security.krb5.debug` to `true`.

See Oracle documentation

Problem

I have a Java-based web application that takes the contents of a web form containing a username and password and authenticates using Kerberos to a Windows-based domain. The KDC address is apparently configured to map to different IP addresses at each lookup and this can be confirmed by using the ping command from the command line. The call responds immediately for most requests but the response is slow (5-10 seconds or even longer) intermittently. I think this may be due to which domain controller is used. I've tried to turn on Kerberos logging but the IP address of the domain controller is not shown. How can I turn on more detailed logging to try to identify dodgy domain controllers please? The code extract sources the `kerb.conf` and `kerb_context.conf` from the filesystem. The `kerb.conf` is: ``` [libdefaults] default_realm = EXAMPLE.COM [realms] CYMRU.NHS.UK = { kdc = example.com:88 admin_server = example.com kpasswd_server = example.com } ``` The kerb_context.conf is: ``` primaryLoginContext { com.sun.security.auth.module.Krb5LoginModule required useTicketCache=false refreshKrb5Config=true debug=true; }; ``` The example source is: ``` static NadexUser executePerformLogin(String username, String password) throws LoginException { char[] passwd = password.toCharArray(); String kerbConf = ERXFileUtilities.pathForResourceNamed("nadex/kerb.conf", "RSCorp", null); String kerbContextConf = ERXFileUtilities.pathURLForResourceNamed("nadex/kerb_context.conf", "RSCorp", null).toExternalForm(); System.setProperty("java.security.krb5.conf", kerbConf); System.setProperty("java.security.auth.login.config", kerbContextConf); try { LoginContext lc = new LoginContext("primaryLoginContext", new UserNamePasswordCallbackHandler(username, password)); lc.login(); return new _NadexUser(lc.getSubject()); } catch (javax.security.auth.login.LoginException le) { throw new LoginException("Failed to login : " + le.getLocalizedMessage(), le); } } ```

Original source