jdk/src/share/classes/sun/security/jgss/GSSNameImpl.java
author weijun
Tue, 05 Jan 2010 10:40:36 +0800
changeset 4533 eb8cec364323
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6895424: RFC 5653 Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
4533
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
     2
 * Copyright 2000-2010 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.util.ObjectIdentifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.DerInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.util.DerOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This is the implementation class for GSSName. Conceptually the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * GSSName is a container with mechanism specific name elements. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * name element is a representation of how that particular mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * would canonicalize this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Generally a GSSName is created by an application when it supplies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * a sequence of bytes and a nametype that helps each mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * decide how to interpret those bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * It is not necessary to create name elements for each available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * mechanism at the time the application creates the GSSName. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * implementation does this lazily, as and when name elements for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * mechanisms are required to be handed out. (Generally, other GSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * classes like GSSContext and GSSCredential request specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * elements depending on the mechanisms that they are dealing with.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Assume that getting a mechanism to parse the applciation specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * bytes is an expensive call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * When a GSSName is canonicalized wrt some mechanism, it is supposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * to discard all elements of other mechanisms and retain only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * element for this mechanism. In GSS terminology this is called a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Mechanism Name or MN. This implementation tries to retain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * application provided bytes and name type just in case the MN is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * asked to produce an element for a mechanism that is different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * When a GSSName is to be exported, the name element for the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * mechanism is converted to a byte representation and written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * out. It might happen that a name element for that mechanism cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * be obtained. This happens when the mechanism is just not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * in this GSS-API or when the mechanism is supported but bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * corresponding to the nametypes that it understands are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * available in this GSSName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * This class is safe for sharing. Each retrieval of a name element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * from getElement() might potentially add a new element to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * hashmap of elements, but getElement() is synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Mayank Upadhyay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public class GSSNameImpl implements GSSName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
4533
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    84
    /**
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    85
     * The old Oid used in RFC 2853. Now supported as
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    86
     * input parameters in:
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    87
     *
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    88
     * 1. The four overloaded GSSManager.createName(*) methods
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    89
     * 2. GSSManager.getMechsForName(Oid)
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    90
     *
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    91
     * Note that even if a GSSName is created with this old Oid,
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    92
     * its internal name type and getStringNameType() output are
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    93
     * always the new value.
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    94
     */
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    95
    final static Oid oldHostbasedServiceName;
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    96
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    97
    static {
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    98
        Oid tmp = null;
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
    99
        try {
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   100
            tmp = new Oid("1.3.6.1.5.6.2");
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   101
        } catch (Exception e) {
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   102
            // should never happen
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   103
        }
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   104
        oldHostbasedServiceName = tmp;
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   105
    }
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private GSSManagerImpl gssManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Store whatever the application passed in. We will use this to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * get individual mechanisms to create name elements as and when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Store both the String and the byte[]. Leave I18N to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * mechanism by allowing it to extract bytes from the String!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private String appNameStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private byte[] appNameBytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private Oid appNameType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * When we figure out what the printable name would be, we store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * both the name and its type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private String printableName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private Oid printableNameType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private HashMap<Oid, GSSNameSpi> elements = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private GSSNameSpi mechElement = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    static GSSNameImpl wrapElement(GSSManagerImpl gssManager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        GSSNameSpi mechElement) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return (mechElement == null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            null : new GSSNameImpl(gssManager, mechElement));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    GSSNameImpl(GSSManagerImpl gssManager, GSSNameSpi mechElement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.gssManager = gssManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        appNameStr = printableName = mechElement.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        appNameType = printableNameType = mechElement.getStringNameType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.mechElement = mechElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        elements = new HashMap<Oid, GSSNameSpi>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        elements.put(mechElement.getMechanism(), this.mechElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    GSSNameImpl(GSSManagerImpl gssManager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                       Object appName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                       Oid appNameType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this(gssManager, appName, appNameType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    GSSNameImpl(GSSManagerImpl gssManager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        Object appName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                        Oid appNameType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
4533
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   160
        if (oldHostbasedServiceName.equals(appNameType)) {
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   161
            appNameType = GSSName.NT_HOSTBASED_SERVICE;
eb8cec364323 6895424: RFC 5653
weijun
parents: 2
diff changeset
   162
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (appName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new GSSExceptionImpl(GSSException.BAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                   "Cannot import null name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (mech == null) mech = ProviderList.DEFAULT_MECH_OID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (NT_EXPORT_NAME.equals(appNameType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            importName(gssManager, appName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            init(gssManager, appName, appNameType, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private void init(GSSManagerImpl gssManager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                      Object appName, Oid appNameType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                      Oid mech)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.gssManager = gssManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.elements =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                new HashMap<Oid, GSSNameSpi>(gssManager.getMechs().length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (appName instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            this.appNameStr = (String) appName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             * If appNameType is null, then the nametype for this printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             * string is determined only by interrogating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
             * mechanism. Thus, defer the setting of printableName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             * printableNameType till later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (appNameType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                printableName = appNameStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                printableNameType = appNameType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            this.appNameBytes = (byte[]) appName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.appNameType = appNameType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        mechElement = getElement(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * printableName will be null if appName was in a byte[] or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         * appName was in a String but appNameType was null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (printableName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            printableName = mechElement.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            printableNameType = mechElement.getStringNameType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         *  At this point the GSSNameImpl has the following set:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         *   appNameStr or appNameBytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         *   appNameType (could be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         *   printableName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         *   printableNameType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         *   mechElement (which also exists in the hashmap of elements)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private void importName(GSSManagerImpl gssManager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            Object appName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        byte[] bytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (appName instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                bytes = ((String) appName).getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                // Won't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            bytes = (byte[]) appName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if ((bytes[pos++] != 0x04) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            (bytes[pos++] != 0x01))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new GSSExceptionImpl(GSSException.BAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                   "Exported name token id is corrupted!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int oidLen  = (((0xFF & bytes[pos++]) << 8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                       (0xFF & bytes[pos++]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        ObjectIdentifier temp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            DerInputStream din = new DerInputStream(bytes, pos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                                    oidLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            temp = new ObjectIdentifier(din);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new GSSExceptionImpl(GSSException.BAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                       "Exported name Object identifier is corrupted!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Oid oid = new Oid(temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        pos += oidLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int mechPortionLen = (((0xFF & bytes[pos++]) << 24) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                              ((0xFF & bytes[pos++]) << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                              ((0xFF & bytes[pos++]) << 8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                              (0xFF & bytes[pos++]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        byte[] mechPortion = new byte[mechPortionLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        System.arraycopy(bytes, pos, mechPortion, 0, mechPortionLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        init(gssManager, mechPortion, NT_EXPORT_NAME, oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public GSSName canonicalize(Oid mech) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (mech == null) mech = ProviderList.DEFAULT_MECH_OID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return wrapElement(gssManager, getElement(mech));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * This method may return false negatives. But if it says two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * names are equals, then there is some mechanism that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * authenticates them as the same principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public boolean equals(GSSName other) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (this.isAnonymous() || other.isAnonymous())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (other == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (! (other instanceof GSSNameImpl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return equals(gssManager.createName(other.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                                other.getStringNameType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * XXX Do a comparison of the appNameStr/appNameBytes if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * available. If that fails, then proceed with this test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        GSSNameImpl that = (GSSNameImpl) other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        GSSNameSpi myElement = this.mechElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        GSSNameSpi element = that.mechElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * XXX If they are not of the same mechanism type, convert both to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         * Kerberos since it is guaranteed to be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if ((myElement == null) && (element != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            myElement = this.getElement(element.getMechanism());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        } else if ((myElement != null) && (element == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            element = that.getElement(myElement.getMechanism());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (myElement != null && element != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return myElement.equals(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if ((this.appNameType != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            (that.appNameType != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (!this.appNameType.equals(that.appNameType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            byte[] myBytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            byte[] bytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                myBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    (this.appNameStr != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                     this.appNameStr.getBytes("UTF-8") :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                     this.appNameBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                bytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    (that.appNameStr != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                     that.appNameStr.getBytes("UTF-8") :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                     that.appNameBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                // Won't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return Arrays.equals(myBytes, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Returns a hashcode value for this GSSName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @return a hashCode value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * In order to get this to work reliably and properly(!), obtain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * Kerberos name element for the name and then call hashCode on its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * string representation. But this cannot be done if the nametype
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * is not one of those supported by the Kerberos provider and hence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * this name cannot be imported by Kerberos. In that case return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * constant value!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public boolean equals(Object another) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // XXX This can lead to an infinite loop. Extract info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            // and create a GSSNameImpl with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (another instanceof GSSName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                return equals((GSSName) another);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } catch (GSSException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            // Squelch it and return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns a flat name representation for this object. The name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * format is defined in RFC 2743:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Length           Name          Description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * 2               TOK_ID          Token Identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *                                 For exported name objects, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *                                 must be hex 04 01.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * 2               MECH_OID_LEN    Length of the Mechanism OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * MECH_OID_LEN    MECH_OID        Mechanism OID, in DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * 4               NAME_LEN        Length of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * NAME_LEN        NAME            Exported name; format defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *                                 applicable mechanism draft.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Note that it is not required to canonicalize a name before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * calling export(). i.e., the name need not be an MN. If it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * not an MN, an implementation defined algorithm can be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * choosing the mechanism which should export this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @return the flat name representation for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @exception GSSException with major codes NAME_NOT_MN, BAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *  BAD_NAME, FAILURE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public byte[] export() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (mechElement == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            /* Use default mech */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            mechElement = getElement(ProviderList.DEFAULT_MECH_OID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        byte[] mechPortion = mechElement.export();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        byte[] oidBytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        ObjectIdentifier oid = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            oid = new ObjectIdentifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                (mechElement.getMechanism().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            throw new GSSExceptionImpl(GSSException.FAILURE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                       "Invalid OID String ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        DerOutputStream dout = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            dout.putOID(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            throw new GSSExceptionImpl(GSSException.FAILURE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                   "Could not ASN.1 Encode "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                   + oid.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        oidBytes = dout.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        byte[] retVal = new byte[2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                + 2 + oidBytes.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                + 4 + mechPortion.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        retVal[pos++] = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        retVal[pos++] = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        retVal[pos++] = (byte) (oidBytes.length>>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        retVal[pos++] = (byte) oidBytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        System.arraycopy(oidBytes, 0, retVal, pos, oidBytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        pos += oidBytes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        retVal[pos++] = (byte) (mechPortion.length>>>24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        retVal[pos++] = (byte) (mechPortion.length>>>16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        retVal[pos++] = (byte) (mechPortion.length>>>8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        retVal[pos++] = (byte)  mechPortion.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        System.arraycopy(mechPortion, 0, retVal, pos, mechPortion.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         return printableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public Oid getStringNameType() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return printableNameType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public boolean isAnonymous() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (printableNameType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return GSSName.NT_ANONYMOUS.equals(printableNameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public boolean isMN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return true; // Since always canonicalized for some mech
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public synchronized GSSNameSpi getElement(Oid mechOid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        GSSNameSpi retVal = elements.get(mechOid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (retVal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            if (appNameStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                retVal = gssManager.getNameElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    (appNameStr, appNameType, mechOid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                retVal = gssManager.getNameElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    (appNameBytes, appNameType, mechOid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            elements.put(mechOid, retVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    Set<GSSNameSpi> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        return new HashSet<GSSNameSpi>(elements.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private static String getNameTypeStr(Oid nameTypeOid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (nameTypeOid == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return "(NT is null)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (nameTypeOid.equals(NT_USER_NAME))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return "NT_USER_NAME";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (nameTypeOid.equals(NT_HOSTBASED_SERVICE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return "NT_HOSTBASED_SERVICE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (nameTypeOid.equals(NT_EXPORT_NAME))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return "NT_EXPORT_NAME";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (nameTypeOid.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return "NT_GSS_KRB5_PRINCIPAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return "Unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
}