// vim:shiftwidth=4:tabstop=4:expandtab

import sun.security.krb5.PrincipalName;
import sun.security.krb5.internal.ccache.FileCredentialsCache;

public class kwho {
    public static void main(String[] args) {


        String cache = System.getenv("KRB5CCNAME");
        if (cache == null) {
            System.err.println("Uh-oh, KRB5CCNAME is not set.  Quitting.");
            return;
        }

        // The FileCredentialsCache does not want to see the "FILE:" prefix
        if ((cache.length() >= 5)
                && cache.substring(0,5).equalsIgnoreCase("FILE:")) {
            cache = cache.substring(5);
        }

        //assumes credendials cache of type "FILE:"
        FileCredentialsCache fcc = FileCredentialsCache.acquireInstance(null, cache);
        if (fcc == null) {
            System.err.println(
                    "No credentials cache found (ticket cache " + cache + ")");
            return;
        }
        PrincipalName princ = fcc.getPrimaryPrincipal();
        String[] nameStrings = princ.getNameStrings();
        StringBuffer temp = new StringBuffer(nameStrings[0]);
        for (int i=1; i<nameStrings.length; i++) {
            temp.append("/");
            temp.append(nameStrings[i]);
        }
        System.out.println(temp);
    }
}


@@ -290,84 +290,8 @@
 ) %7B%0A
-            System.err.println(%22Uh-oh, KRB5CCNAME is not set.  Quitting.%22);%0A
     
@@ -298,32 +298,32 @@
         return;%0A
+
         %7D%0A%0A     
@@ -405,152 +405,50 @@
     
-if ((cache.length() %3E= 5)%0A                && cache.substring(0,5).equalsIgnoreCase
+cache = cache.replaceAll
 (%22
+%5E
 FILE:%22
-)) %7B%0A            cache = cache.substring(5);%0A        %7D
+, cache);
 %0A%0A  
@@ -583,16 +583,16 @@
 cache);%0A
+
         
@@ -614,120 +614,8 @@
 ) %7B%0A
-            System.err.println(%0A                    %22No credentials cache found (ticket cache %22 + cache + %22)%22);%0A
     

Exit silently if ccache is not found or empty.