Java and Kerberos authentication krb5.conf versus System.setProperty
Asked Answered
O

1

18

Please help me on a kerberos+Java problem. I have a simple Java program to authenticate to a Windows Active Directory using Kerberos. The following java code works fine without any problems and prints true-

public class KerberosAuthenticator {
    public static void main(String[] args) {
        String jaasConfigFilePath = "/myDir/jaas.conf";

        System.setProperty("java.security.auth.login.config", jaasConfigFilePath);

        System.setProperty("java.security.krb5.realm", "ENG.TEST.COM");
        System.setProperty("java.security.krb5.kdc","winsvr2003r2.eng.test.com");

        boolean success = auth.KerberosAuthenticator.authenticate("testprincipal", "testpass");

        System.out.println(success);
    }
}

Bue when I specify the path to the krb5.conf file instead of manually specifying the realm and kdc, it errors out saying "Null realm name (601) - default realm not specified". Following is the code-

public class KerberosAuthenticator {
    public static void main(String[] args) {
        String jaasConfigFilePath = "/myDir/jaas.conf";

        System.setProperty("java.security.auth.login.config", jaasConfigFilePath);

        String krb5ConfigFilePath = "/etc/krb5/krb5.conf";
        System.setProperty("java.security.krb5.conf", krb5ConfigFilePath);

        boolean success = auth.KerberosAuthenticator.authenticate("testprincipal", "testpass");

        System.out.println(success);
    }
}

The contents of krb5.conf is as follows-

[libdefault]
 default_realm = ENG.TEST.COM

[realms]
 ENG.TEST.COM = {
  kdc = winsvr2003r2.eng.test.com
  kpasswd_server = winsvr2003r2.eng.test.com
  admin_server = winsvr2003r2.eng.test.com
  kpasswd_protocol = SET_CHANGE
 }

[domain_realm]
 .eng.test.com = ENG.TEST.COM
 eng.test.com = ENG.TEST.COM
[logging]
 default = FILE:/var/krb5/kdc.log
 kdc = FILE:/var/krb5/kdc.log
 kdc_rotate = {
  period = 1d
  versions = 10
 }

[appdefaults]
 kinit = {
 renewable = true
 forwardable = true
 }
Occlusive answered 16/9, 2009 at 9:40 Comment(1)
I don't know the answer to your question, but if I was in your shoes, I'd use my IDE's debugger to step into the KerberosAuthenticator to determine why it isn't getting the default realm. Good luck!Illicit
N
21

Your krb5.conf is wrong. It's [libdefaults], not [libdefault].

Necessitate answered 16/9, 2009 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.