jdk/src/share/classes/sun/security/jgss/spnego/SpNegoMechFactory.java
changeset 4338 f36521ae16db
parent 2942 37d9baeb7518
child 5506 202f599c92aa
equal deleted inserted replaced
4337:2a6d13ebbbed 4338:f36521ae16db
    55     private static Oid[] nameTypes =
    55     private static Oid[] nameTypes =
    56         new Oid[] { GSSName.NT_USER_NAME,
    56         new Oid[] { GSSName.NT_USER_NAME,
    57                         GSSName.NT_HOSTBASED_SERVICE,
    57                         GSSName.NT_HOSTBASED_SERVICE,
    58                         GSSName.NT_EXPORT_NAME};
    58                         GSSName.NT_EXPORT_NAME};
    59 
    59 
       
    60     // The default underlying mech of SPNEGO, must not be SPNEGO itself.
       
    61     private static final Oid DEFAULT_SPNEGO_MECH_OID =
       
    62             ProviderList.DEFAULT_MECH_OID.equals(GSS_SPNEGO_MECH_OID)?
       
    63                 GSSUtil.GSS_KRB5_MECH_OID:
       
    64                 ProviderList.DEFAULT_MECH_OID;
       
    65 
    60     // Use an instance of a GSSManager whose provider list
    66     // Use an instance of a GSSManager whose provider list
    61     // does not include native provider
    67     // does not include native provider
    62     final GSSManagerImpl manager;
    68     final GSSManagerImpl manager;
    63     final Oid[] availableMechs;
    69     final Oid[] availableMechs;
    64 
    70 
    98             // Skip SpNego mechanism
   104             // Skip SpNego mechanism
    99             if (!mechs[i].equals(GSS_SPNEGO_MECH_OID)) {
   105             if (!mechs[i].equals(GSS_SPNEGO_MECH_OID)) {
   100                 availableMechs[j++] = mechs[i];
   106                 availableMechs[j++] = mechs[i];
   101             }
   107             }
   102         }
   108         }
       
   109         // Move the preferred mech to first place
       
   110         for (int i=0; i<availableMechs.length; i++) {
       
   111             if (availableMechs[i].equals(DEFAULT_SPNEGO_MECH_OID)) {
       
   112                 if (i != 0) {
       
   113                     availableMechs[i] = availableMechs[0];
       
   114                     availableMechs[0] = DEFAULT_SPNEGO_MECH_OID;
       
   115                 }
       
   116                 break;
       
   117             }
       
   118         }
   103     }
   119     }
   104 
   120 
   105     public GSSNameSpi getNameElement(String nameStr, Oid nameType)
   121     public GSSNameSpi getNameElement(String nameStr, Oid nameType)
   106         throws GSSException {
   122             throws GSSException {
   107         // get NameElement for the default Mechanism
   123         return manager.getNameElement(
   108         return manager.getNameElement(nameStr, nameType, null);
   124                 nameStr, nameType, DEFAULT_SPNEGO_MECH_OID);
   109     }
   125     }
   110 
   126 
   111     public GSSNameSpi getNameElement(byte[] name, Oid nameType)
   127     public GSSNameSpi getNameElement(byte[] name, Oid nameType)
   112         throws GSSException {
   128             throws GSSException {
   113         // get NameElement for the default Mechanism
   129         return manager.getNameElement(name, nameType, DEFAULT_SPNEGO_MECH_OID);
   114         return manager.getNameElement(name, nameType, null);
       
   115     }
   130     }
   116 
   131 
   117     public GSSCredentialSpi getCredentialElement(GSSNameSpi name,
   132     public GSSCredentialSpi getCredentialElement(GSSNameSpi name,
   118            int initLifetime, int acceptLifetime,
   133            int initLifetime, int acceptLifetime,
   119            int usage) throws GSSException {
   134            int usage) throws GSSException {