I have been trying to understand how these different APIs glue together behind the scenes. Though this question might seem to be a broad one, I also want to understand a particular scenario. Any pointers on this this can further be debugged will be appreciated.
I am following this basic tutorial - https://docs.oracle.com/javase/jndi/tutorial/ldap/security/src/Mutual.java
In this, I am particularly trying to understand, what this line actually means, during the creation of DirContext
// Request the use of the "GSSAPI" SASL mechanism Authenticate by using already established Kerberos credentials env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
What are the high level steps done during the creation DirContext/LDAPContext when Context.SECURITY_AUTHENTICATION
is set to GSSAPI
in the environment hashtable?
- Is the TGT of the Subject required for this
LDAPContext
creation? - What is the role of the TGT/Subject/Private-public credentials of the Subject acquired during the LoginContext#login() process?
Let us start from the beginning:
LoginContext lc = new LoginContext(...)
lc.login()
What this piece of code does is that, it communicates with the KDC server, and obtains a TGT from it, if the authentication is successful! The login context has a Subject(authenticated) populated in it, which has all the information of the Credentials.
Once that is done, the following code is used to perform the JNDI.
What does it actually mean to execute the code as the PrivilegedAction of the Subject as follows?
Subject.doAs(lc.getSubject(), new JndiAction(args));
I am failing to understand what will happen to the objects returned from the Subject.doAs(...)?
Scenario:
Consider that the DirContext is returned by the Subject.doAs(...) method by using PrivilegedAction{....} so that the the context can be used later on.
What will happen to this context if the Subject through which it was created was
logged out
or itscredentials are invalidated or changed?
Will it still continue to work?Are the TGTs used for any of the later
ctx
operations like search() or is the GSSAPI in the picture for any of these operations?How does active directory validate this context valid?
Requirement
a. We don't want to perform any JNDI operation within the
PrivilegedAction#run
. We just want to return thecontext
object which we want to cache or use later.
b. We have a peculiar requirement that we can't have on single
krb.conf
file due to some reasons. We create and destroy krb.conf for every subsequent request.
c. The reason for me asking question #5 is that - once the krb.conf file is re-generated as explained above, all the credentials from the in-memory
LoginContext#Subject
objects are invalidated and can't be used further.
d. In this case, can we use the cached context?
Any help to understand the real working is appreciated