How to extract Kerberos TGT from UserGroupInformation

If you need to view lifetime of your Kerberos ticket in Hadoop’s UserGroupInformation or see Kerberos ticket expiration date in UserGroupInformation (and do other things), you need extract Kerberos TGT from UserGroupInformation.

This piece of code will be very useful for you:

public KerberosTicket extractTgtFromUGI(UserGroupInformation ugi) {
    Method method = null;
    try {
        method = ugi.getClass().getDeclaredMethod("getTGT");
        KerberosTicket tgt = (KerberosTicket) method.invoke(ugi);"Kerberos ticket info. startTime={}, endTime={}, renewTill={}", tgt.getStartTime(), tgt.getEndTime(), tgt.getRenewTill());
        return tgt;
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
        throw new RuntimeException(ex);

If you still have any questions, feel free to ask me in the comments under this article or write me at

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *