Search in sources :

Example 21 with GSSCredential

use of org.ietf.jgss.GSSCredential in project jdk8u_jdk by JetBrains.

the class MSOID method main.

public static void main(String[] args) throws Exception {
    // msoid.txt is a NegTokenInit packet sent from Internet Explorer to
    // IIS server on a test machine. No sensitive info included.
    byte[] header = Files.readAllBytes(Paths.get(System.getProperty("test.src"), "msoid.txt"));
    byte[] token = Base64.getMimeDecoder().decode(Arrays.copyOfRange(header, 10, header.length));
    GSSCredential cred = null;
    GSSContext ctx = GSSManager.getInstance().createContext(cred);
    try {
        ctx.acceptSecContext(token, 0, token.length);
        // and acceptor chooses another mech and goes on
        throw new Exception("Should fail");
    } catch (GSSException gsse) {
        // After the fix, GSS_KRB5_MECH_OID_MS is recognized but the token
        // cannot be accepted because we don't have any krb5 credential.
        gsse.printStackTrace();
        if (gsse.getMajor() != GSSException.NO_CRED) {
            throw gsse;
        }
        for (StackTraceElement st : gsse.getStackTrace()) {
            if (st.getClassName().startsWith("sun.security.jgss.krb5.")) {
                // Good, it is already in krb5 mech's hand.
                return;
            }
        }
        throw gsse;
    }
}
Also used : GSSException(org.ietf.jgss.GSSException) GSSCredential(org.ietf.jgss.GSSCredential) GSSContext(org.ietf.jgss.GSSContext) GSSException(org.ietf.jgss.GSSException) Exception(java.lang.Exception)

Example 22 with GSSCredential

use of org.ietf.jgss.GSSCredential in project jdk8u_jdk by JetBrains.

the class Context method delegated.

/**
     * Using the delegated credentials from a previous acceptor
     * @param c
     */
public Context delegated() throws Exception {
    Context out = new Context();
    out.s = s;
    try {
        out.cred = Subject.doAs(s, new PrivilegedExceptionAction<GSSCredential>() {

            @Override
            public GSSCredential run() throws Exception {
                GSSCredential cred = x.getDelegCred();
                if (cred == null && x.getCredDelegState() || cred != null && !x.getCredDelegState()) {
                    throw new Exception("getCredDelegState not match");
                }
                return cred;
            }
        });
    } catch (PrivilegedActionException pae) {
        throw pae.getException();
    }
    out.name = name + " as " + out.cred.getName().toString();
    return out;
}
Also used : LoginContext(javax.security.auth.login.LoginContext) ExtendedGSSContext(com.sun.security.jgss.ExtendedGSSContext) GSSContext(org.ietf.jgss.GSSContext) ExtendedGSSCredential(com.sun.security.jgss.ExtendedGSSCredential) GSSCredential(org.ietf.jgss.GSSCredential) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) PrivilegedActionException(java.security.PrivilegedActionException) GSSException(org.ietf.jgss.GSSException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with GSSCredential

use of org.ietf.jgss.GSSCredential in project jdk8u_jdk by JetBrains.

the class SpnegoLifeTime method main.

public static void main(String[] args) throws Exception {
    Oid oid = GSSUtil.GSS_SPNEGO_MECH_OID;
    new OneKDC(null).writeJAASConf();
    Context c, s;
    c = Context.fromJAAS("client");
    s = Context.fromJAAS("server");
    c.startAsClient(OneKDC.SERVER, oid);
    c.x().requestCredDeleg(true);
    s.startAsServer(oid);
    Context.handshake(c, s);
    GSSCredential cred = s.delegated().cred();
    cred.getRemainingInitLifetime(oid);
    cred.getUsage(oid);
}
Also used : GSSCredential(org.ietf.jgss.GSSCredential) Oid(org.ietf.jgss.Oid)

Aggregations

GSSCredential (org.ietf.jgss.GSSCredential)23 GSSException (org.ietf.jgss.GSSException)16 GSSManager (org.ietf.jgss.GSSManager)14 Oid (org.ietf.jgss.Oid)14 GSSName (org.ietf.jgss.GSSName)13 GSSContext (org.ietf.jgss.GSSContext)11 Subject (javax.security.auth.Subject)9 PrivilegedActionException (java.security.PrivilegedActionException)8 Principal (java.security.Principal)7 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)4 ExtendedGSSContext (com.sun.security.jgss.ExtendedGSSContext)3 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)3 LoginContext (javax.security.auth.login.LoginContext)3 LoginException (javax.security.auth.login.LoginException)3 SaslException (javax.security.sasl.SaslException)3 KrbException (org.apache.kerby.kerberos.kerb.KrbException)3 Test (org.junit.Test)3 ExtendedGSSCredential (com.sun.security.jgss.ExtendedGSSCredential)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2