jdk/src/share/classes/sun/security/jgss/GSSManagerImpl.java
author weijun
Wed, 07 Nov 2012 14:13:01 +0800
changeset 14413 e954df027393
parent 5506 202f599c92aa
child 17435 ec797e955dca
permissions -rw-r--r--
6355584: Introduce constrained Kerberos delegation Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
     2
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4533
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.jgss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import org.ietf.jgss.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.security.jgss.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class provides the default implementation of the GSSManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class GSSManagerImpl extends GSSManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // Undocumented property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final String USE_NATIVE_PROP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        "sun.security.jgss.native";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final Boolean USE_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        USE_NATIVE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                    public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                            String osname = System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                            if (osname.startsWith("SunOS") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                osname.startsWith("Linux")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                return new Boolean(System.getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                    (USE_NATIVE_PROP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                            return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private ProviderList list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Used by java SPNEGO impl to make sure native is disabled
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 715
diff changeset
    64
    public GSSManagerImpl(GSSCaller caller, boolean useNative) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        list = new ProviderList(caller, useNative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // Used by HTTP/SPNEGO NegotiatorImpl
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 715
diff changeset
    69
    public GSSManagerImpl(GSSCaller caller) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        list = new ProviderList(caller, USE_NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public GSSManagerImpl() {
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 715
diff changeset
    74
        list = new ProviderList(GSSCaller.CALLER_UNKNOWN, USE_NATIVE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public Oid[] getMechs(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return list.getMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public Oid[] getNamesForMech(Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        MechanismFactory factory = list.getMechFactory(mech);
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    84
        return factory.getNameTypes().clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public Oid[] getMechsForName(Oid nameType){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Oid[] mechs = list.getMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Oid[] retVal = new Oid[mechs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
4533
eb8cec364323 6895424: RFC 5653
weijun
parents: 2942
diff changeset
    92
        // Compatibility with RFC 2853 old NT_HOSTBASED_SERVICE value.
eb8cec364323 6895424: RFC 5653
weijun
parents: 2942
diff changeset
    93
        if (nameType.equals(GSSNameImpl.oldHostbasedServiceName)) {
eb8cec364323 6895424: RFC 5653
weijun
parents: 2942
diff changeset
    94
            nameType = GSSName.NT_HOSTBASED_SERVICE;
eb8cec364323 6895424: RFC 5653
weijun
parents: 2942
diff changeset
    95
        }
eb8cec364323 6895424: RFC 5653
weijun
parents: 2942
diff changeset
    96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // Iterate thru all mechs in GSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        for (int i = 0; i < mechs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            // what nametypes does this mech support?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            Oid mech = mechs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                Oid[] namesForMech = getNamesForMech(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                // Is the desired Oid present in that list?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                if (nameType.containedIn(namesForMech)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    retVal[pos++] = mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            } catch (GSSException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                // Squelch it and just skip over this mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                GSSUtil.debug("Skip " + mech +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                              ": error retrieving supported name types");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // Trim the list if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (pos < retVal.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Oid[] temp = new Oid[pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            for (int i = 0; i < pos; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                temp[i] = retVal[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            retVal = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public GSSName createName(String nameStr, Oid nameType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return new GSSNameImpl(this, nameStr, nameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public GSSName createName(byte name[], Oid nameType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return new GSSNameImpl(this, name, nameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public GSSName createName(String nameStr, Oid nameType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                              Oid mech) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return new GSSNameImpl(this, nameStr, nameType, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public GSSName createName(byte name[], Oid nameType, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return new GSSNameImpl(this, name, nameType, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public GSSCredential createCredential(int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return new GSSCredentialImpl(this, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public GSSCredential createCredential(GSSName aName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                          int lifetime, Oid mech, int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return new GSSCredentialImpl(this, aName, lifetime, mech, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public GSSCredential createCredential(GSSName aName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                          int lifetime, Oid mechs[], int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return new GSSCredentialImpl(this, aName, lifetime, mechs, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public GSSContext createContext(GSSName peer, Oid mech,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                    GSSCredential myCred, int lifetime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return new GSSContextImpl(this, peer, mech, myCred, lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public GSSContext createContext(GSSCredential myCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return new GSSContextImpl(this, myCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public GSSContext createContext(byte[] interProcessToken)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return new GSSContextImpl(this, interProcessToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void addProviderAtFront(Provider p, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        list.addProviderAtFront(p, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void addProviderAtEnd(Provider p, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        list.addProviderAtEnd(p, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public GSSCredentialSpi getCredentialElement(GSSNameSpi name, int initLifetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                          int acceptLifetime, Oid mech, int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        MechanismFactory factory = list.getMechFactory(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return factory.getCredentialElement(name, initLifetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                            acceptLifetime, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // Used by java SPNEGO impl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public GSSNameSpi getNameElement(String name, Oid nameType, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // Just use the most preferred MF impl assuming GSSNameSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // objects are interoperable among providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        MechanismFactory factory = list.getMechFactory(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return factory.getNameElement(name, nameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // Used by java SPNEGO impl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public GSSNameSpi getNameElement(byte[] name, Oid nameType, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // Just use the most preferred MF impl assuming GSSNameSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // objects are interoperable among providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        MechanismFactory factory = list.getMechFactory(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return factory.getNameElement(name, nameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    GSSContextSpi getMechanismContext(GSSNameSpi peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                      GSSCredentialSpi myInitiatorCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                      int lifetime, Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Provider p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (myInitiatorCred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            p = myInitiatorCred.getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        MechanismFactory factory = list.getMechFactory(mech, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return factory.getMechanismContext(peer, myInitiatorCred, lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    GSSContextSpi getMechanismContext(GSSCredentialSpi myAcceptorCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                      Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        Provider p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (myAcceptorCred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            p = myAcceptorCred.getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        MechanismFactory factory = list.getMechFactory(mech, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return factory.getMechanismContext(myAcceptorCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    GSSContextSpi getMechanismContext(byte[] exportedContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if ((exportedContext == null) || (exportedContext.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new GSSException(GSSException.NO_CONTEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        GSSContextSpi result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // Only allow context import with native provider since JGSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // still has not defined its own interprocess token format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Oid[] mechs = list.getMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        for (int i = 0; i < mechs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            MechanismFactory factory = list.getMechFactory(mechs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (factory.getProvider().getName().equals("SunNativeGSS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                result = factory.getMechanismContext(exportedContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (result != null) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throw new GSSException(GSSException.UNAVAILABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}