jdk/src/share/classes/sun/security/jgss/GSSUtil.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
child 22973 616ad2891b71
equal deleted inserted replaced
10335:3c7eda3ab2f5 10336:0bb1999251f8
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   314      * specified criteria and returns the matching GSSCredentialSpi
   314      * specified criteria and returns the matching GSSCredentialSpi
   315      * object out of Sun's impl of GSSCredential. Returns null if
   315      * object out of Sun's impl of GSSCredential. Returns null if
   316      * no Subject present or a Vector which contains 0 or more
   316      * no Subject present or a Vector which contains 0 or more
   317      * matching GSSCredentialSpi objects.
   317      * matching GSSCredentialSpi objects.
   318      */
   318      */
   319     public static Vector searchSubject(final GSSNameSpi name,
   319     public static <T extends GSSCredentialSpi> Vector<T>
   320                                        final Oid mech,
   320             searchSubject(final GSSNameSpi name,
   321                                        final boolean initiate,
   321                           final Oid mech,
   322                                        final Class credCls) {
   322                           final boolean initiate,
       
   323                           final Class<? extends T> credCls) {
   323         debug("Search Subject for " + getMechStr(mech) +
   324         debug("Search Subject for " + getMechStr(mech) +
   324               (initiate? " INIT" : " ACCEPT") + " cred (" +
   325               (initiate? " INIT" : " ACCEPT") + " cred (" +
   325               (name == null? "<<DEF>>" : name.toString()) + ", " +
   326               (name == null? "<<DEF>>" : name.toString()) + ", " +
   326               credCls.getName() + ")");
   327               credCls.getName() + ")");
   327         final AccessControlContext acc = AccessController.getContext();
   328         final AccessControlContext acc = AccessController.getContext();
   328         try {
   329         try {
   329             Vector creds =
   330             Vector<T> creds =
   330                 AccessController.doPrivileged
   331                 AccessController.doPrivileged
   331                 (new PrivilegedExceptionAction<Vector>() {
   332                 (new PrivilegedExceptionAction<Vector<T>>() {
   332                     public Vector run() throws Exception {
   333                     public Vector<T> run() throws Exception {
   333                         Subject accSubj = Subject.getSubject(acc);
   334                         Subject accSubj = Subject.getSubject(acc);
   334                         Vector<GSSCredentialSpi> result = null;
   335                         Vector<T> result = null;
   335                         if (accSubj != null) {
   336                         if (accSubj != null) {
   336                             result = new Vector<GSSCredentialSpi>();
   337                             result = new Vector<T>();
   337                             Iterator<GSSCredentialImpl> iterator =
   338                             Iterator<GSSCredentialImpl> iterator =
   338                                 accSubj.getPrivateCredentials
   339                                 accSubj.getPrivateCredentials
   339                                 (GSSCredentialImpl.class).iterator();
   340                                 (GSSCredentialImpl.class).iterator();
   340                             while (iterator.hasNext()) {
   341                             while (iterator.hasNext()) {
   341                                 GSSCredentialImpl cred = iterator.next();
   342                                 GSSCredentialImpl cred = iterator.next();
   345                                         cred.getElement(mech, initiate);
   346                                         cred.getElement(mech, initiate);
   346                                     debug("......Found element: " + ce);
   347                                     debug("......Found element: " + ce);
   347                                     if (ce.getClass().equals(credCls) &&
   348                                     if (ce.getClass().equals(credCls) &&
   348                                         (name == null ||
   349                                         (name == null ||
   349                                          name.equals((Object) ce.getName()))) {
   350                                          name.equals((Object) ce.getName()))) {
   350                                         result.add(ce);
   351                                         result.add(credCls.cast(ce));
   351                                     } else {
   352                                     } else {
   352                                         debug("......Discard element");
   353                                         debug("......Discard element");
   353                                     }
   354                                     }
   354                                 } catch (GSSException ge) {
   355                                 } catch (GSSException ge) {
   355                                     debug("...Discard cred (" + ge + ")");
   356                                     debug("...Discard cred (" + ge + ")");