code: @SuppressWarnings({ "rawtypes", "unchecked" })
     protected DirContext setupKerberosContext(Hashtable<String,Object> env) 
     throws NamingException
     {
  
        LoginContext lc = null;
        try
        {
  
      	 lc = new LoginContext(getClass().getName(), new JXCallbackHandler());
           lc.login();
  
        }
        catch (LoginException ex)
        {
           throw new NamingException("login problem: " + ex);
        }
  
        DirContext ctx = (DirContext) Subject.doAs(lc.getSubject(), new JndiAction(env));
  
        if (ctx == null)
           throw new NamingException("another problem with GSSAPI");
        else
           return ctx;
      
     }
docs: Initial LDAP for kerberos support
  @param env
  @throws NamingException