sun.security.jgss.spi.GSSCredentialSpi Java Examples

The following examples show how to use sun.security.jgss.spi.GSSCredentialSpi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpNegoCredElement.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public SpNegoCredElement(GSSCredentialSpi cred) throws GSSException {
    this.cred = cred;
}
 
Example #2
Source File: SpNegoCredElement.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    return cred.impersonate(name);
}
 
Example #3
Source File: SpNegoCredElement.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    return cred.impersonate(name);
}
 
Example #4
Source File: GSSUtil.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}
 
Example #5
Source File: GSSUtil.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #6
Source File: GSSCredElement.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    throw new GSSException(GSSException.FAILURE, -1,
            "Not supported yet");
}
 
Example #7
Source File: SpNegoCredElement.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public SpNegoCredElement(GSSCredentialSpi cred) throws GSSException {
    this.cred = cred;
}
 
Example #8
Source File: GSSUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #9
Source File: GSSUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}
 
Example #10
Source File: GSSCredElement.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    throw new GSSException(GSSException.FAILURE, -1,
            "Not supported yet");
}
 
Example #11
Source File: SpNegoCredElement.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public GSSCredentialSpi getInternalCred() {
    return cred;
}
 
Example #12
Source File: GSSUtil.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}
 
Example #13
Source File: GSSCredElement.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    throw new GSSException(GSSException.FAILURE, -1,
            "Not supported yet");
}
 
Example #14
Source File: SpNegoCredElement.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    return cred.impersonate(name);
}
 
Example #15
Source File: SpNegoCredElement.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public GSSCredentialSpi getInternalCred() {
    return cred;
}
 
Example #16
Source File: GSSUtil.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #17
Source File: GSSUtil.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #18
Source File: GSSUtil.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}
 
Example #19
Source File: GSSCredElement.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    throw new GSSException(GSSException.FAILURE, -1,
            "Not supported yet");
}
 
Example #20
Source File: SpNegoCredElement.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    return cred.impersonate(name);
}
 
Example #21
Source File: SpNegoCredElement.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public GSSCredentialSpi getInternalCred() {
    return cred;
}
 
Example #22
Source File: SpNegoCredElement.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public SpNegoCredElement(GSSCredentialSpi cred) throws GSSException {
    this.cred = cred;
}
 
Example #23
Source File: GSSUtil.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #24
Source File: GSSUtil.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}
 
Example #25
Source File: GSSCredElement.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    throw new GSSException(GSSException.FAILURE, -1,
            "Not supported yet");
}
 
Example #26
Source File: SpNegoCredElement.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public GSSCredentialSpi impersonate(GSSNameSpi name) throws GSSException {
    return cred.impersonate(name);
}
 
Example #27
Source File: SpNegoCredElement.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public GSSCredentialSpi getInternalCred() {
    return cred;
}
 
Example #28
Source File: SpNegoCredElement.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public SpNegoCredElement(GSSCredentialSpi cred) throws GSSException {
    this.cred = cred;
}
 
Example #29
Source File: GSSUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Searches the private credentials of current Subject with the
 * specified criteria and returns the matching GSSCredentialSpi
 * object out of Sun's impl of GSSCredential. Returns null if
 * no Subject present or a Vector which contains 0 or more
 * matching GSSCredentialSpi objects.
 */
public static <T extends GSSCredentialSpi> Vector<T>
        searchSubject(final GSSNameSpi name,
                      final Oid mech,
                      final boolean initiate,
                      final Class<? extends T> credCls) {
    debug("Search Subject for " + getMechStr(mech) +
          (initiate? " INIT" : " ACCEPT") + " cred (" +
          (name == null? "<<DEF>>" : name.toString()) + ", " +
          credCls.getName() + ")");
    final AccessControlContext acc = AccessController.getContext();
    try {
        Vector<T> creds =
            AccessController.doPrivileged
            (new PrivilegedExceptionAction<Vector<T>>() {
                public Vector<T> run() throws Exception {
                    Subject accSubj = Subject.getSubject(acc);
                    Vector<T> result = null;
                    if (accSubj != null) {
                        result = new Vector<T>();
                        Iterator<GSSCredentialImpl> iterator =
                            accSubj.getPrivateCredentials
                            (GSSCredentialImpl.class).iterator();
                        while (iterator.hasNext()) {
                            GSSCredentialImpl cred = iterator.next();
                            debug("...Found cred" + cred);
                            try {
                                GSSCredentialSpi ce =
                                    cred.getElement(mech, initiate);
                                debug("......Found element: " + ce);
                                if (ce.getClass().equals(credCls) &&
                                    (name == null ||
                                     name.equals((Object) ce.getName()))) {
                                    result.add(credCls.cast(ce));
                                } else {
                                    debug("......Discard element");
                                }
                            } catch (GSSException ge) {
                                debug("...Discard cred (" + ge + ")");
                            }
                        }
                    } else debug("No Subject");
                    return result;
                }
            });
        return creds;
    } catch (PrivilegedActionException pae) {
        debug("Unexpected exception when searching Subject:");
        if (DEBUG) pae.printStackTrace();
        return null;
    }
}
 
Example #30
Source File: GSSUtil.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Note: The current impl only works with Sun's impl of
 * GSSName and GSSCredential since it depends on package
 * private APIs.
 */
public static Subject getSubject(GSSName name,
                                 GSSCredential creds) {

    HashSet<Object> privCredentials = null;
    HashSet<Object> pubCredentials = new HashSet<Object>(); // empty Set

    Set<GSSCredentialSpi> gssCredentials = null;

    Set<KerberosPrincipal> krb5Principals =
                            new HashSet<KerberosPrincipal>();

    if (name instanceof GSSNameImpl) {
        try {
            GSSNameSpi ne = ((GSSNameImpl) name).getElement
                (GSS_KRB5_MECH_OID);
            String krbName = ne.toString();
            if (ne instanceof Krb5NameElement) {
                krbName =
                    ((Krb5NameElement) ne).getKrb5PrincipalName().getName();
            }
            KerberosPrincipal krbPrinc = new KerberosPrincipal(krbName);
            krb5Principals.add(krbPrinc);
        } catch (GSSException ge) {
            debug("Skipped name " + name + " due to " + ge);
        }
    }

    if (creds instanceof GSSCredentialImpl) {
        gssCredentials = ((GSSCredentialImpl) creds).getElements();
        privCredentials = new HashSet<Object>(gssCredentials.size());
        populateCredentials(privCredentials, gssCredentials);
    } else {
        privCredentials = new HashSet<Object>(); // empty Set
    }
    debug("Created Subject with the following");
    debug("principals=" + krb5Principals);
    debug("public creds=" + pubCredentials);
    debug("private creds=" + privCredentials);

    return new Subject(false, krb5Principals, pubCredentials,
                       privCredentials);

}