Path: blob/master/src/java.security.jgss/share/classes/org/ietf/jgss/GSSName.java
41155 views
/*1* Copyright (c) 2000, 2015, 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;2627/**28* This interface encapsulates a single GSS-API principal entity. The29* application obtains an implementation of this interface30* through one of the <code>createName</code> methods that exist in the {@link31* GSSManager GSSManager} class. Conceptually a GSSName contains many32* representations of the entity or many primitive name elements, one for33* each supported underlying mechanism. In GSS terminology, a GSSName that34* contains an element from just one mechanism is called a Mechanism Name35* (MN)<p>36*37* Since different authentication mechanisms may employ different38* namespaces for identifying their principals, GSS-API's naming support is39* necessarily complex in multi-mechanism environments (or even in some40* single-mechanism environments where the underlying mechanism supports41* multiple namespaces). Different name formats and their definitions are42* identified with {@link Oid Oid's} and some standard types43* are defined in this interface. The format of the names can be derived44* based on the unique <code>Oid</code> of its name type.<p>45*46* Included below are code examples utilizing the <code>GSSName</code> interface.47* The code below creates a <code>GSSName</code>, converts it to an MN, performs a48* comparison, obtains a printable representation of the name, exports it49* to a byte array and then re-imports to obtain a50* new <code>GSSName</code>.51* <pre>52* GSSManager manager = GSSManager.getInstance();53*54* // create a host based service name55* GSSName name = manager.createName("service@host",56* GSSName.NT_HOSTBASED_SERVICE);57*58* Oid krb5 = new Oid("1.2.840.113554.1.2.2");59*60* GSSName mechName = name.canonicalize(krb5);61*62* // the above two steps are equivalent to the following63* GSSName mechName = manager.createName("service@host",64* GSSName.NT_HOSTBASED_SERVICE, krb5);65*66* // perform name comparison67* if (name.equals(mechName))68* print("Names are equals.");69*70* // obtain textual representation of name and its printable71* // name type72* print(mechName.toString() +73* mechName.getStringNameType().toString());74*75* // export and re-import the name76* byte [] exportName = mechName.export();77*78* // create a new name object from the exported buffer79* GSSName newName = manager.createName(exportName,80* GSSName.NT_EXPORT_NAME);81*82* </pre>83* If a security manager is installed, in order to create a {@code GSSName}84* that contains a Kerberos name element without providing its realm,85* a {@link javax.security.auth.kerberos.ServicePermission ServicePermission}86* must be granted and the service principal of the permission must minimally87* be inside the Kerberos name element's realm. For example, if the result of88* {@link GSSManager#createName(String, Oid) createName("user", NT_USER_NAME)}89* contains a Kerberos name element {@code [email protected]}, then90* a {@code ServicePermission} with service principal91* {@code host/[email protected]} (and any action) must be granted.92* Otherwise, the creation will throw a {@link GSSException} containing the93* {@code GSSException.FAILURE} error code.94*95* @see #export()96* @see #equals(GSSName)97* @see GSSManager#createName(String, Oid)98* @see GSSManager#createName(String, Oid, Oid)99* @see GSSManager#createName(byte[], Oid)100*101* @author Mayank Upadhyay102* @since 1.4103*/104public interface GSSName {105106/**107* Oid indicating a host-based service name form. It is used to108* represent services associated with host computers. This name form109* is constructed using two elements, "service" and "hostname", as110* follows: service@hostname.<p>111*112* It represents the following Oid value:<br>113* <code>{ iso(1) member-body(2) United114* States(840) mit(113554) infosys(1) gssapi(2) generic(1) service_name(4)115* }</code>116*/117public static final Oid NT_HOSTBASED_SERVICE118= Oid.getInstance("1.2.840.113554.1.2.1.4");119120/**121* Name type to indicate a named user on a local system.<p>122* It represents the following Oid value:<br>123* <code>{ iso(1) member-body(2) United124* States(840) mit(113554) infosys(1) gssapi(2) generic(1) user_name(1)125* }</code>126*/127public static final Oid NT_USER_NAME128= Oid.getInstance("1.2.840.113554.1.2.1.1");129130/**131* Name type to indicate a numeric user identifier corresponding to a132* user on a local system. (e.g. Uid).<p>133*134* It represents the following Oid value:<br>135* <code>{ iso(1) member-body(2) United States(840) mit(113554)136* infosys(1) gssapi(2) generic(1) machine_uid_name(2) }</code>137*/138public static final Oid NT_MACHINE_UID_NAME139= Oid.getInstance("1.2.840.113554.1.2.1.2");140141/**142* Name type to indicate a string of digits representing the numeric143* user identifier of a user on a local system.<p>144*145* It represents the following Oid value:<br>146* <code>{ iso(1) member-body(2) United147* States(840) mit(113554) infosys(1) gssapi(2) generic(1)148* string_uid_name(3) }</code>149*/150public static final Oid NT_STRING_UID_NAME151= Oid.getInstance("1.2.840.113554.1.2.1.3");152153/**154* Name type for representing an anonymous entity.<p>155* It represents the following Oid value:<br>156* <code>{ 1(iso), 3(org), 6(dod), 1(internet),157* 5(security), 6(nametypes), 3(gss-anonymous-name) }</code>158*/159public static final Oid NT_ANONYMOUS160= Oid.getInstance("1.3.6.1.5.6.3");161162/**163* Name type used to indicate an exported name produced by the export164* method.<p>165*166* It represents the following Oid value:<br> <code>{ 1(iso),167* 3(org), 6(dod), 1(internet), 5(security), 6(nametypes),168* 4(gss-api-exported-name) }</code>169*/170public static final Oid NT_EXPORT_NAME171= Oid.getInstance("1.3.6.1.5.6.4");172173/**174* Compares two <code>GSSName</code> objects to determine if they refer to the175* same entity.176*177* @param another the <code>GSSName</code> to compare this name with178* @return true if the two names contain at least one primitive element179* in common. If either of the names represents an anonymous entity, the180* method will return false.181*182* @throws GSSException when the names cannot be compared, containing the following183* major error codes:184* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},185* {@link GSSException#FAILURE GSSException.FAILURE}186*/187public boolean equals(GSSName another) throws GSSException;188189/**190* Compares this <code>GSSName</code> object to another Object that might be a191* <code>GSSName</code>. The behaviour is exactly the same as in {@link192* #equals(GSSName) equals} except that no GSSException is thrown;193* instead, false will be returned in the situation where an error194* occurs.195* @return true if the object to compare to is also a <code>GSSName</code> and the two196* names refer to the same entity.197* @param another the object to compare this name to198* @see #equals(GSSName)199*/200public boolean equals(Object another);201202/**203* Returns a hashcode value for this GSSName.204*205* @return a hashCode value206*/207public int hashCode();208209/**210* Creates a name that is canonicalized for some211* mechanism.212*213* @return a <code>GSSName</code> that contains just one primitive214* element representing this name in a canonicalized form for the desired215* mechanism.216* @param mech the oid for the mechanism for which the canonical form of217* the name is requested.218*219* @throws GSSException containing the following220* major error codes:221* {@link GSSException#BAD_MECH GSSException.BAD_MECH},222* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},223* {@link GSSException#BAD_NAME GSSException.BAD_NAME},224* {@link GSSException#FAILURE GSSException.FAILURE}225*/226public GSSName canonicalize(Oid mech) throws GSSException;227228/**229* Returns a canonical contiguous byte representation of a mechanism name230* (MN), suitable for direct, byte by byte comparison by authorization231* functions. If the name is not an MN, implementations may throw a232* GSSException with the NAME_NOT_MN status code. If an implementation233* chooses not to throw an exception, it should use some system specific234* default mechanism to canonicalize the name and then export235* it. Structurally, an exported name object consists of a header236* containing an OID identifying the mechanism that authenticated the237* name, and a trailer containing the name itself, where the syntax of238* the trailer is defined by the individual mechanism specification. The239* format of the header of the output buffer is specified in RFC 2743.<p>240*241* The exported name is useful when used in large access control lists242* where the overhead of creating a <code>GSSName</code> object on each243* name and invoking the equals method on each name from the ACL may be244* prohibitive.<p>245*246* Exported names may be re-imported by using the byte array factory247* method {@link GSSManager#createName(byte[], Oid)248* GSSManager.createName} and specifying the NT_EXPORT_NAME as the name249* type object identifier. The resulting <code>GSSName</code> name will250* also be a MN.251*252* @return a byte[] containing the exported name. RFC 2743 defines the253* "Mechanism-Independent Exported Name Object Format" for these bytes.254*255* @throws GSSException containing the following256* major error codes:257* {@link GSSException#BAD_NAME GSSException.BAD_NAME},258* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},259* {@link GSSException#FAILURE GSSException.FAILURE}260*/261public byte[] export() throws GSSException;262263/**264* Returns a textual representation of the <code>GSSName</code> object. To retrieve265* the printed name format, which determines the syntax of the returned266* string, use the {@link #getStringNameType() getStringNameType}267* method.268*269* @return a String representing this name in printable form.270*/271public String toString();272273/**274* Returns the name type of the printable275* representation of this name that can be obtained from the <code>276* toString</code> method.277*278* @return an Oid representing the namespace of the name returned279* from the toString method.280*281* @throws GSSException containing the following282* major error codes:283* {@link GSSException#FAILURE GSSException.FAILURE}284*/285public Oid getStringNameType() throws GSSException;286287/**288* Tests if this name object represents an anonymous entity.289*290* @return true if this is an anonymous name, false otherwise.291*/292public boolean isAnonymous();293294/**295* Tests if this name object represents a Mechanism Name (MN). An MN is296* a GSSName the contains exactly one mechanism's primitive name297* element.298*299* @return true if this is an MN, false otherwise.300*/301public boolean isMN();302303}304305306