Search in sources :

Example 1 with AuthorizationDataEntry

use of com.sun.security.jgss.AuthorizationDataEntry in project jdk8u_jdk by JetBrains.

the class Context method status.

/**
     * Prints status of GSSContext and Subject
     * @throws java.lang.Exception
     */
public void status() throws Exception {
    System.out.println("STATUS OF " + name.toUpperCase());
    try {
        StringBuffer sb = new StringBuffer();
        if (x.getAnonymityState()) {
            sb.append("anon, ");
        }
        if (x.getConfState()) {
            sb.append("conf, ");
        }
        if (x.getCredDelegState()) {
            sb.append("deleg, ");
        }
        if (x.getIntegState()) {
            sb.append("integ, ");
        }
        if (x.getMutualAuthState()) {
            sb.append("mutual, ");
        }
        if (x.getReplayDetState()) {
            sb.append("rep det, ");
        }
        if (x.getSequenceDetState()) {
            sb.append("seq det, ");
        }
        if (x instanceof ExtendedGSSContext) {
            if (((ExtendedGSSContext) x).getDelegPolicyState()) {
                sb.append("deleg policy, ");
            }
        }
        System.out.println("Context status of " + name + ": " + sb.toString());
        System.out.println(x.getSrcName() + " -> " + x.getTargName());
    } catch (Exception e) {
        // Don't care
        ;
    }
    if (s != null) {
        System.out.println("====== START SUBJECT CONTENT =====");
        for (Principal p : s.getPrincipals()) {
            System.out.println("    Principal: " + p);
        }
        for (Object o : s.getPublicCredentials()) {
            System.out.println("    " + o.getClass());
            System.out.println("        " + o);
        }
        System.out.println("====== Private Credentials Set ======");
        for (Object o : s.getPrivateCredentials()) {
            System.out.println("    " + o.getClass());
            if (o instanceof KerberosTicket) {
                KerberosTicket kt = (KerberosTicket) o;
                System.out.println("        " + kt.getServer() + " for " + kt.getClient());
            } else if (o instanceof KerberosKey) {
                KerberosKey kk = (KerberosKey) o;
                System.out.print("        " + kk.getKeyType() + " " + kk.getVersionNumber() + " " + kk.getAlgorithm() + " ");
                for (byte b : kk.getEncoded()) {
                    System.out.printf("%02X", b & 0xff);
                }
                System.out.println();
            } else if (o instanceof Map) {
                Map map = (Map) o;
                for (Object k : map.keySet()) {
                    System.out.println("        " + k + ": " + map.get(k));
                }
            } else {
                System.out.println("        " + o);
            }
        }
        System.out.println("====== END SUBJECT CONTENT =====");
    }
    if (x != null && x instanceof ExtendedGSSContext) {
        if (x.isEstablished()) {
            ExtendedGSSContext ex = (ExtendedGSSContext) x;
            Key k = (Key) ex.inquireSecContext(InquireType.KRB5_GET_SESSION_KEY);
            if (k == null) {
                throw new Exception("Session key cannot be null");
            }
            System.out.println("Session key is: " + k);
            boolean[] flags = (boolean[]) ex.inquireSecContext(InquireType.KRB5_GET_TKT_FLAGS);
            if (flags == null) {
                throw new Exception("Ticket flags cannot be null");
            }
            System.out.println("Ticket flags is: " + Arrays.toString(flags));
            String authTime = (String) ex.inquireSecContext(InquireType.KRB5_GET_AUTHTIME);
            if (authTime == null) {
                throw new Exception("Auth time cannot be null");
            }
            System.out.println("AuthTime is: " + authTime);
            if (!x.isInitiator()) {
                AuthorizationDataEntry[] ad = (AuthorizationDataEntry[]) ex.inquireSecContext(InquireType.KRB5_GET_AUTHZ_DATA);
                System.out.println("AuthzData is: " + Arrays.toString(ad));
            }
        }
    }
}
Also used : ExtendedGSSContext(com.sun.security.jgss.ExtendedGSSContext) KerberosTicket(javax.security.auth.kerberos.KerberosTicket) AuthorizationDataEntry(com.sun.security.jgss.AuthorizationDataEntry) PrivilegedActionException(java.security.PrivilegedActionException) GSSException(org.ietf.jgss.GSSException) InvocationTargetException(java.lang.reflect.InvocationTargetException) KerberosKey(javax.security.auth.kerberos.KerberosKey) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) KerberosKey(javax.security.auth.kerberos.KerberosKey) Key(java.security.Key)

Aggregations

AuthorizationDataEntry (com.sun.security.jgss.AuthorizationDataEntry)1 ExtendedGSSContext (com.sun.security.jgss.ExtendedGSSContext)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Key (java.security.Key)1 Principal (java.security.Principal)1 PrivilegedActionException (java.security.PrivilegedActionException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 KerberosKey (javax.security.auth.kerberos.KerberosKey)1 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)1 GSSException (org.ietf.jgss.GSSException)1