Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/org/ietf/jgss/GSSName.java
38830 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package org.ietf.jgss;2627import sun.security.jgss.spi.*;28import java.util.Vector;29import java.util.Enumeration;3031/**32* This interface encapsulates a single GSS-API principal entity. The33* application obtains an implementation of this interface34* through one of the <code>createName</code> methods that exist in the {@link35* GSSManager GSSManager} class. Conceptually a GSSName contains many36* representations of the entity or many primitive name elements, one for37* each supported underlying mechanism. In GSS terminology, a GSSName that38* contains an element from just one mechanism is called a Mechanism Name39* (MN)<p>40*41* Since different authentication mechanisms may employ different42* namespaces for identifying their principals, GSS-API's naming support is43* necessarily complex in multi-mechanism environments (or even in some44* single-mechanism environments where the underlying mechanism supports45* multiple namespaces). Different name formats and their definitions are46* identified with {@link Oid Oid's} and some standard types47* are defined in this interface. The format of the names can be derived48* based on the unique <code>Oid</code> of its name type.<p>49*50* Included below are code examples utilizing the <code>GSSName</code> interface.51* The code below creates a <code>GSSName</code>, converts it to an MN, performs a52* comparison, obtains a printable representation of the name, exports it53* to a byte array and then re-imports to obtain a54* new <code>GSSName</code>.<p>55* <pre>56* GSSManager manager = GSSManager.getInstance();57*58* // create a host based service name59* GSSName name = manager.createName("service@host",60* GSSName.NT_HOSTBASED_SERVICE);61*62* Oid krb5 = new Oid("1.2.840.113554.1.2.2");63*64* GSSName mechName = name.canonicalize(krb5);65*66* // the above two steps are equivalent to the following67* GSSName mechName = manager.createName("service@host",68* GSSName.NT_HOSTBASED_SERVICE, krb5);69*70* // perform name comparison71* if (name.equals(mechName))72* print("Names are equals.");73*74* // obtain textual representation of name and its printable75* // name type76* print(mechName.toString() +77* mechName.getStringNameType().toString());78*79* // export and re-import the name80* byte [] exportName = mechName.export();81*82* // create a new name object from the exported buffer83* GSSName newName = manager.createName(exportName,84* GSSName.NT_EXPORT_NAME);85*86* </pre>87* @see #export()88* @see #equals(GSSName)89* @see GSSManager#createName(String, Oid)90* @see GSSManager#createName(String, Oid, Oid)91* @see GSSManager#createName(byte[], Oid)92*93* @author Mayank Upadhyay94* @since 1.495*/96public interface GSSName {9798/**99* Oid indicating a host-based service name form. It is used to100* represent services associated with host computers. This name form101* is constructed using two elements, "service" and "hostname", as102* follows: service@hostname.<p>103*104* It represents the following Oid value:<br>105* <code>{ iso(1) member-body(2) United106* States(840) mit(113554) infosys(1) gssapi(2) generic(1) service_name(4)107* }</code>108*/109public static final Oid NT_HOSTBASED_SERVICE110= Oid.getInstance("1.2.840.113554.1.2.1.4");111112/**113* Name type to indicate a named user on a local system.<p>114* It represents the following Oid value:<br>115* <code>{ iso(1) member-body(2) United116* States(840) mit(113554) infosys(1) gssapi(2) generic(1) user_name(1)117* }</code>118*/119public static final Oid NT_USER_NAME120= Oid.getInstance("1.2.840.113554.1.2.1.1");121122/**123* Name type to indicate a numeric user identifier corresponding to a124* user on a local system. (e.g. Uid).<p>125*126* It represents the following Oid value:<br>127* <code>{ iso(1) member-body(2) United States(840) mit(113554)128* infosys(1) gssapi(2) generic(1) machine_uid_name(2) }</code>129*/130public static final Oid NT_MACHINE_UID_NAME131= Oid.getInstance("1.2.840.113554.1.2.1.2");132133/**134* Name type to indicate a string of digits representing the numeric135* user identifier of a user on a local system.<p>136*137* It represents the following Oid value:<br>138* <code>{ iso(1) member-body(2) United139* States(840) mit(113554) infosys(1) gssapi(2) generic(1)140* string_uid_name(3) }</code>141*/142public static final Oid NT_STRING_UID_NAME143= Oid.getInstance("1.2.840.113554.1.2.1.3");144145/**146* Name type for representing an anonymous entity.<p>147* It represents the following Oid value:<br>148* <code>{ 1(iso), 3(org), 6(dod), 1(internet),149* 5(security), 6(nametypes), 3(gss-anonymous-name) }</code>150*/151public static final Oid NT_ANONYMOUS152= Oid.getInstance("1.3.6.1.5.6.3");153154/**155* Name type used to indicate an exported name produced by the export156* method.<p>157*158* It represents the following Oid value:<br> <code>{ 1(iso),159* 3(org), 6(dod), 1(internet), 5(security), 6(nametypes),160* 4(gss-api-exported-name) }</code>161*/162public static final Oid NT_EXPORT_NAME163= Oid.getInstance("1.3.6.1.5.6.4");164165/**166* Compares two <code>GSSName</code> objects to determine if they refer to the167* same entity.168*169* @param another the <code>GSSName</code> to compare this name with170* @return true if the two names contain at least one primitive element171* in common. If either of the names represents an anonymous entity, the172* method will return false.173*174* @throws GSSException when the names cannot be compared, containing the following175* major error codes:176* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},177* {@link GSSException#FAILURE GSSException.FAILURE}178*/179public boolean equals(GSSName another) throws GSSException;180181/**182* Compares this <code>GSSName</code> object to another Object that might be a183* <code>GSSName</code>. The behaviour is exactly the same as in {@link184* #equals(GSSName) equals} except that no GSSException is thrown;185* instead, false will be returned in the situation where an error186* occurs.187* @return true if the object to compare to is also a <code>GSSName</code> and the two188* names refer to the same entity.189* @param another the object to compare this name to190* @see #equals(GSSName)191*/192public boolean equals(Object another);193194/**195* Returns a hashcode value for this GSSName.196*197* @return a hashCode value198*/199public int hashCode();200201/**202* Creates a name that is canonicalized for some203* mechanism.204*205* @return a <code>GSSName</code> that contains just one primitive206* element representing this name in a canonicalized form for the desired207* mechanism.208* @param mech the oid for the mechanism for which the canonical form of209* the name is requested.210*211* @throws GSSException containing the following212* major error codes:213* {@link GSSException#BAD_MECH GSSException.BAD_MECH},214* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},215* {@link GSSException#BAD_NAME GSSException.BAD_NAME},216* {@link GSSException#FAILURE GSSException.FAILURE}217*/218public GSSName canonicalize(Oid mech) throws GSSException;219220/**221* Returns a canonical contiguous byte representation of a mechanism name222* (MN), suitable for direct, byte by byte comparison by authorization223* functions. If the name is not an MN, implementations may throw a224* GSSException with the NAME_NOT_MN status code. If an implementation225* chooses not to throw an exception, it should use some system specific226* default mechanism to canonicalize the name and then export227* it. Structurally, an exported name object consists of a header228* containing an OID identifying the mechanism that authenticated the229* name, and a trailer containing the name itself, where the syntax of230* the trailer is defined by the individual mechanism specification. The231* format of the header of the output buffer is specified in RFC 2743.<p>232*233* The exported name is useful when used in large access control lists234* where the overhead of creating a <code>GSSName</code> object on each235* name and invoking the equals method on each name from the ACL may be236* prohibitive.<p>237*238* Exported names may be re-imported by using the byte array factory239* method {@link GSSManager#createName(byte[], Oid)240* GSSManager.createName} and specifying the NT_EXPORT_NAME as the name241* type object identifier. The resulting <code>GSSName</code> name will242* also be a MN.<p>243* @return a byte[] containing the exported name. RFC 2743 defines the244* "Mechanism-Independent Exported Name Object Format" for these bytes.245*246* @throws GSSException containing the following247* major error codes:248* {@link GSSException#BAD_NAME GSSException.BAD_NAME},249* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},250* {@link GSSException#FAILURE GSSException.FAILURE}251*/252public byte[] export() throws GSSException;253254/**255* Returns a textual representation of the <code>GSSName</code> object. To retrieve256* the printed name format, which determines the syntax of the returned257* string, use the {@link #getStringNameType() getStringNameType}258* method.259*260* @return a String representing this name in printable form.261*/262public String toString();263264/**265* Returns the name type of the printable266* representation of this name that can be obtained from the <code>267* toString</code> method.268*269* @return an Oid representing the namespace of the name returned270* from the toString method.271*272* @throws GSSException containing the following273* major error codes:274* {@link GSSException#FAILURE GSSException.FAILURE}275*/276public Oid getStringNameType() throws GSSException;277278/**279* Tests if this name object represents an anonymous entity.280*281* @return true if this is an anonymous name, false otherwise.282*/283public boolean isAnonymous();284285/**286* Tests if this name object represents a Mechanism Name (MN). An MN is287* a GSSName the contains exactly one mechanism's primitive name288* element.289*290* @return true if this is an MN, false otherwise.291*/292public boolean isMN();293294}295296297