2362N/A * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This is the implementation class for GSSName. Conceptually the 0N/A * GSSName is a container with mechanism specific name elements. Each 0N/A * name element is a representation of how that particular mechanism 0N/A * would canonicalize this principal. 0N/A * Generally a GSSName is created by an application when it supplies 0N/A * a sequence of bytes and a nametype that helps each mechanism 0N/A * decide how to interpret those bytes. 0N/A * It is not necessary to create name elements for each available 0N/A * mechanism at the time the application creates the GSSName. This 0N/A * implementation does this lazily, as and when name elements for 0N/A * mechanisms are required to be handed out. (Generally, other GSS 0N/A * classes like GSSContext and GSSCredential request specific 0N/A * elements depending on the mechanisms that they are dealing with.) 0N/A * Assume that getting a mechanism to parse the applciation specified 0N/A * bytes is an expensive call. 0N/A * When a GSSName is canonicalized wrt some mechanism, it is supposed 0N/A * to discard all elements of other mechanisms and retain only the 0N/A * element for this mechanism. In GSS terminology this is called a 0N/A * Mechanism Name or MN. This implementation tries to retain the 0N/A * application provided bytes and name type just in case the MN is 0N/A * asked to produce an element for a mechanism that is different. 0N/A * When a GSSName is to be exported, the name element for the desired 0N/A * mechanism is converted to a byte representation and written 0N/A * out. It might happen that a name element for that mechanism cannot 0N/A * be obtained. This happens when the mechanism is just not supported 0N/A * in this GSS-API or when the mechanism is supported but bytes 0N/A * corresponding to the nametypes that it understands are not 0N/A * available in this GSSName. 0N/A * This class is safe for sharing. Each retrieval of a name element 0N/A * from getElement() might potentially add a new element to the 0N/A * hashmap of elements, but getElement() is synchronized. 0N/A * @author Mayank Upadhyay 2036N/A * The old Oid used in RFC 2853. Now supported as 2036N/A * 1. The four overloaded GSSManager.createName(*) methods 2036N/A * 2. GSSManager.getMechsForName(Oid) 2036N/A * Note that even if a GSSName is created with this old Oid, 2036N/A * its internal name type and getStringNameType() output are 0N/A * Store whatever the application passed in. We will use this to 0N/A * get individual mechanisms to create name elements as and when 0N/A * Store both the String and the byte[]. Leave I18N to the 0N/A * mechanism by allowing it to extract bytes from the String! 0N/A * When we figure out what the printable name would be, we store 0N/A * both the name and its type. 0N/A "Cannot import null name");
0N/A * If appNameType is null, then the nametype for this printable 0N/A * string is determined only by interrogating the 0N/A * mechanism. Thus, defer the setting of printableName and 0N/A * printableNameType till later. 0N/A * printableName will be null if appName was in a byte[] or if 0N/A * appName was in a String but appNameType was null. 0N/A * At this point the GSSNameImpl has the following set: 0N/A * appNameStr or appNameBytes 0N/A * appNameType (could be null) 0N/A * mechElement (which also exists in the hashmap of elements) 0N/A "Exported name token id is corrupted!");
0N/A "Exported name Object identifier is corrupted!");
0N/A * This method may return false negatives. But if it says two 0N/A * names are equals, then there is some mechanism that 0N/A * authenticates them as the same principal. 0N/A * available. If that fails, then proceed with this test. 0N/A * XXX If they are not of the same mechanism type, convert both to 0N/A * Kerberos since it is guaranteed to be present. 0N/A * Returns a hashcode value for this GSSName. 0N/A * @return a hashCode value 0N/A * In order to get this to work reliably and properly(!), obtain a 0N/A * Kerberos name element for the name and then call hashCode on its 0N/A * string representation. But this cannot be done if the nametype 0N/A * is not one of those supported by the Kerberos provider and hence 0N/A * this name cannot be imported by Kerberos. In that case return a 0N/A // XXX This can lead to an infinite loop. Extract info 0N/A // and create a GSSNameImpl with it. 0N/A // Squelch it and return false 0N/A * Returns a flat name representation for this object. The name 0N/A * format is defined in RFC 2743: 0N/A * Length Name Description 0N/A * 2 TOK_ID Token Identifier 0N/A * For exported name objects, this 0N/A * must be hex 04 01. 0N/A * 2 MECH_OID_LEN Length of the Mechanism OID 0N/A * MECH_OID_LEN MECH_OID Mechanism OID, in DER 0N/A * 4 NAME_LEN Length of name 0N/A * NAME_LEN NAME Exported name; format defined in 0N/A * applicable mechanism draft. 0N/A * Note that it is not required to canonicalize a name before 0N/A * calling export(). i.e., the name need not be an MN. If it is 0N/A * not an MN, an implementation defined algorithm can be used for 0N/A * choosing the mechanism which should export this name. 0N/A * @return the flat name representation for this object 0N/A * @exception GSSException with major codes NAME_NOT_MN, BAD_NAME, 0N/A * BAD_NAME, FAILURE. 0N/A /* Use default mech */ 0N/A "Invalid OID String ");
0N/A "Could not ASN.1 Encode " 0N/A return true;
// Since always canonicalized for some mech 0N/A return "(NT is null)";
0N/A return "NT_USER_NAME";
0N/A return "NT_HOSTBASED_SERVICE";
0N/A return "NT_EXPORT_NAME";
0N/A return "NT_GSS_KRB5_PRINCIPAL";