1. /*
  2. * @(#)GSSName.java 1.6 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.ietf.jgss;
  8. import sun.security.jgss.spi.*;
  9. import java.util.Vector;
  10. import java.util.Enumeration;
  11. /**
  12. * This interface encapsulates a single GSS-API principal entity. The
  13. * application obtains an implementation of this interface
  14. * through one of the <code>createName</code> methods that exist in the {@link
  15. * GSSManager GSSManager} class. Conceptually a GSSName contains many
  16. * representations of the entity or many primitive name elements, one for
  17. * each supported underlying mechanism. In GSS terminology, a GSSName that
  18. * contains an element from just one mechanism is called a Mechanism Name
  19. * (MN)<p>
  20. *
  21. * Since different authentication mechanisms may employ different
  22. * namespaces for identifying their principals, GSS-API's naming support is
  23. * necessarily complex in multi-mechanism environments (or even in some
  24. * single-mechanism environments where the underlying mechanism supports
  25. * multiple namespaces). Different name formats and their definitions are
  26. * identified with {@link Oid Oid's} and some standard types
  27. * are defind in this interface. The format of the names can be derived
  28. * based on the unique <code>Oid</code> of its name type.<p>
  29. *
  30. * Included below are code examples utilizing the <code>GSSName</code> interface.
  31. * The code below creates a <code>GSSName</code>, converts it to an MN, performs a
  32. * comparison, obtains a printable representation of the name, exports it
  33. * to a byte array and then re-imports to obtain a
  34. * new <code>GSSName</code>.<p>
  35. * <pre>
  36. * GSSManager manager = GSSManager.getInstance();
  37. *
  38. * // create a host based service name
  39. * GSSName name = manager.createName("service@host",
  40. * GSSName.NT_HOSTBASED_SERVICE);
  41. *
  42. * Oid krb5 = new Oid("1.2.840.113554.1.2.2");
  43. *
  44. * GSSName mechName = name.canonicalize(krb5);
  45. *
  46. * // the above two steps are equivalent to the following
  47. * GSSName mechName = manager.createName("service@host",
  48. * GSSName.NT_HOSTBASED_SERVICE, krb5);
  49. *
  50. * // perform name comparison
  51. * if (name.equals(mechName))
  52. * print("Names are equals.");
  53. *
  54. * // obtain textual representation of name and its printable
  55. * // name type
  56. * print(mechName.toString() +
  57. * mechName.getStringNameType().toString());
  58. *
  59. * // export and re-import the name
  60. * byte [] exportName = mechName.export();
  61. *
  62. * // create a new name object from the exported buffer
  63. * GSSName newName = manager.createName(exportName,
  64. * GSSName.NT_EXPORT_NAME);
  65. *
  66. * </pre>
  67. * @see #export()
  68. * @see #equals(GSSName)
  69. * @see GSSManager#createName(String, Oid)
  70. * @see GSSManager#createName(String, Oid, Oid)
  71. * @see GSSManager#createName(byte[], Oid)
  72. *
  73. * @author Mayank Upadhyay
  74. * @version 1.6, 01/23/03
  75. * @since 1.4
  76. */
  77. public interface GSSName {
  78. /**
  79. * Oid indicating a host-based service name form. It is used to
  80. * represent services associated with host computers. This name form
  81. * is constructed using two elements, "service" and "hostname", as
  82. * follows: service@hostname.<p>
  83. *
  84. * It represents the following Oid value:<br>
  85. * <code>{ 1(iso), 3(org), 6(dod), 1(internet), 5(security),
  86. * 6(nametypes), 2(gss-host-based-services) }</code>
  87. */
  88. public static final Oid NT_HOSTBASED_SERVICE
  89. = Oid.getInstance("1.3.6.1.5.6.2");
  90. /**
  91. * Name type to indicate a named user on a local system.<p>
  92. * It represents the following Oid value:<br>
  93. * <code>{ iso(1) member-body(2) United
  94. * States(840) mit(113554) infosys(1) gssapi(2) generic(1) user_name(1)
  95. * }</code>
  96. */
  97. public static final Oid NT_USER_NAME
  98. = Oid.getInstance("1.2.840.113554.1.2.1.1");
  99. /**
  100. * Name type to indicate a numeric user identifier corresponding to a
  101. * user on a local system. (e.g. Uid).<p>
  102. *
  103. * It represents the following Oid value:<br>
  104. * <code>{ iso(1) member-body(2) United States(840) mit(113554)
  105. * infosys(1) gssapi(2) generic(1) machine_uid_name(2) }</code>
  106. */
  107. public static final Oid NT_MACHINE_UID_NAME
  108. = Oid.getInstance("1.2.840.113554.1.2.1.2");
  109. /**
  110. * Name type to indicate a string of digits representing the numeric
  111. * user identifier of a user on a local system.<p>
  112. *
  113. * It represents the following Oid value:<br>
  114. * <code>{ iso(1) member-body(2) United
  115. * States(840) mit(113554) infosys(1) gssapi(2) generic(1)
  116. * string_uid_name(3) }</code>
  117. */
  118. public static final Oid NT_STRING_UID_NAME
  119. = Oid.getInstance("1.2.840.113554.1.2.1.3");
  120. /**
  121. * Name type for representing an anonymous entity.<p>
  122. * It represents the following Oid value:<br>
  123. * <code>{ 1(iso), 3(org), 6(dod), 1(internet),
  124. * 5(security), 6(nametypes), 3(gss-anonymous-name) }</code>
  125. */
  126. public static final Oid NT_ANONYMOUS
  127. = Oid.getInstance("1.3.6.1.5.6.3");
  128. /**
  129. * Name type used to indicate an exported name produced by the export
  130. * method.<p>
  131. *
  132. * It represents the following Oid value:<br> <code>{ 1(iso),
  133. * 3(org), 6(dod), 1(internet), 5(security), 6(nametypes),
  134. * 4(gss-api-exported-name) }</code>
  135. */
  136. public static final Oid NT_EXPORT_NAME
  137. = Oid.getInstance("1.3.6.1.5.6.4");
  138. /**
  139. * Compares two <code>GSSName</code> objects to determine if they refer to the
  140. * same entity.
  141. *
  142. * @param another the <code>GSSName</code> to compare this name with
  143. * @return true if the two names contain at least one primitive element
  144. * in common. If either of the names represents an anonymous entity, the
  145. * method will return false.
  146. *
  147. * @throws GSSException when the names cannot be compared, containing the following
  148. * major error codes:
  149. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  150. * {@link GSSException#FAILURE GSSException.FAILURE}
  151. */
  152. public boolean equals(GSSName another) throws GSSException;
  153. /**
  154. * Compares this <code>GSSName</code> object to another Object that might be a
  155. * <code>GSSName</code>. The behaviour is exactly the same as in {@link
  156. * #equals(GSSName) equals} except that no GSSException is thrown;
  157. * instead, false will be returned in the situation where an error
  158. * occurs.
  159. * @return true if the object to compare to is also a <code>GSSName</code> and the two
  160. * names refer to the same entity.
  161. * @param another the object to compare this name to
  162. * @see #equals(GSSName)
  163. */
  164. public boolean equals(Object another);
  165. /**
  166. * Returns a hashcode value for this GSSName.
  167. *
  168. * @return a hashCode value
  169. */
  170. public int hashCode();
  171. /**
  172. * Creates a name that is canonicalized for some
  173. * mechanism.
  174. *
  175. * @return a <code>GSSName</code> that contains just one primitive
  176. * element representing this name in a canonicalized form for the desired
  177. * mechanism.
  178. * @param mech the oid for the mechanism for which the canonical form of
  179. * the name is requested.
  180. *
  181. * @throws GSSException containing the following
  182. * major error codes:
  183. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  184. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  185. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  186. * {@link GSSException#FAILURE GSSException.FAILURE}
  187. */
  188. public GSSName canonicalize(Oid mech) throws GSSException;
  189. /**
  190. * Returns a canonical contiguous byte representation of a mechanism name
  191. * (MN), suitable for direct, byte by byte comparison by authorization
  192. * functions. If the name is not an MN, implementations may throw a
  193. * GSSException with the NAME_NOT_MN status code. If an implementation
  194. * chooses not to throw an exception, it should use some system specific
  195. * default mechanism to canonicalize the name and then export
  196. * it. Structurally, an exported name object consists of a header
  197. * containing an OID identifying the mechanism that authenticated the
  198. * name, and a trailer containing the name itself, where the syntax of
  199. * the trailer is defined by the individual mechanism specification. The
  200. * format of the header of the output buffer is specified in RFC 2743.<p>
  201. *
  202. * The exported name is useful when used in large access control lists
  203. * where the overhead of creating a <code>GSSName</code> object on each
  204. * name and invoking the equals method on each name from the ACL may be
  205. * prohibitive.<p>
  206. *
  207. * Exported names may be re-imported by using the byte array factory
  208. * method {@link GSSManager#createName(byte[], Oid)
  209. * GSSManager.createName} and specifying the NT_EXPORT_NAME as the name
  210. * type object identifier. The resulting <code>GSSName</code> name will
  211. * also be a MN.<p>
  212. * @return a byte[] containing the exported name. RFC 2743 defines the
  213. * "Mechanism-Independent Exported Name Object Format" for these bytes.
  214. *
  215. * @throws GSSException containing the following
  216. * major error codes:
  217. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  218. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  219. * {@link GSSException#FAILURE GSSException.FAILURE}
  220. */
  221. public byte[] export() throws GSSException;
  222. /**
  223. * Returns a textual representation of the <code>GSSName</code> object. To retrieve
  224. * the printed name format, which determines the syntax of the returned
  225. * string, use the {@link #getStringNameType() getStringNameType}
  226. * method.
  227. *
  228. * @return a String representing this name in printable form.
  229. */
  230. public String toString();
  231. /**
  232. * Returns the name type of the printable
  233. * representation of this name that can be obtained from the <code>
  234. * toString</code> method.
  235. *
  236. * @return an Oid representing the namespace of the name returned
  237. * from the toString method.
  238. *
  239. * @throws GSSException containing the following
  240. * major error codes:
  241. * {@link GSSException#FAILURE GSSException.FAILURE}
  242. */
  243. public Oid getStringNameType() throws GSSException;
  244. /**
  245. * Tests if this name object represents an anonymous entity.
  246. *
  247. * @return true if this is an anonymous name, false otherwise.
  248. */
  249. public boolean isAnonymous();
  250. /**
  251. * Tests if this name object represents a Mechanism Name (MN). An MN is
  252. * a GSSName the contains exactly one mechanism's primitive name
  253. * element.
  254. *
  255. * @return true if this is an MN, false otherwise.
  256. */
  257. public boolean isMN();
  258. }