0

I want to access an LDAP directory in Java using a keytab. However, my keytab appears as null.

Password access works with this code after the logincontext has been created (I get my tickets in kerberos):

Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
env.put(Context.PROVIDER_URL, "ldap://localhost/");
final DirContext ctx = new InitialDirContext(env);
Attributes attributes = ctx.getAttributes("cn=user1,ou=people,dc=example,dc=com");

I use the following code to try to access the directory via the Keytab file, but it always asks me to enter a password :

JaasClient {
  com.sun.security.auth.module.Krb5LoginModule required
    client=true
    useKeyTab=true
    keytab="/etc/security/keytabs/users3.keytab"
    debug=true
    storeKey=true
    principal="[email protected]";
};
DirContextSource.Builder builder = new DirContextSource.Builder("ldap://localhost");
builder.gssApiAuth("JaasClient");
DirContextSource contextSource = builder.build();
DirContext ctx = contextSource.getDirContext();
Attributes attributes = ctx.getAttributes("cn=user1,ou=people,dc=example,dc=com");

Error :

Debug is true storeKey true useTicketCache false useKeyTab true doNotPrompt false ticketCache is null isInitiator true KeyTab is null
Key for the principal users3@REALM not available in default key tab

Can someone tell me what I am doing wrong ?

2
  • Test the keytab is correct with kinit before assuming everything is correct. Commented Jun 7, 2023 at 17:59
  • You haven't shared any usable information, but the output from the Krb5LoginModule only. BTW, thanks for trying out my library. Commented Jul 11, 2023 at 19:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.