1. /*
  2. * @(#)GSSManager.java 1.8 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 java.security.Provider;
  9. /**
  10. * This class serves as a factory for other important
  11. * GSS-API classes and also provides information about the mechanisms that
  12. * are supported. It can create instances of classes
  13. * implementing the following three GSS-API interfaces: {@link
  14. * GSSName GSSName}, {@link GSSCredential GSSCredential}, and {@link
  15. * GSSContext GSSContext}. It also has methods to query for the list
  16. * of available mechanisms and the nametypes that each mechanism
  17. * supports.<p>
  18. *
  19. * An instance of the default <code>GSSManager</code> subclass
  20. * may be obtained through the static method {@link #getInstance()
  21. * getInstance}, but applications are free to instantiate other subclasses
  22. * of <code>GSSManager</code>. The default <code>GSSManager</code> instance
  23. * will support the Kerberos v5 GSS-API mechanism in addition to any
  24. * others. This mechanism is identified by the Oid "1.2.840.113554.1.2.2"
  25. * and is defined in RFC 1964.<p>
  26. *
  27. * A subclass extending the <code>GSSManager</code> abstract class may be
  28. * implemented as a modular provider based layer that utilizes some well
  29. * known service provider specification. The <code>GSSManager</code> API
  30. * allows the application to set provider preferences on
  31. * such an implementation. These methods also allow the implementation to
  32. * throw a well-defined exception in case provider based configuration is
  33. * not supported. Applications that expect to be portable should be aware
  34. * of this and recover cleanly by catching the exception.<p>
  35. *
  36. * It is envisioned that there will be three most common ways in which
  37. * providers will be used:<p>
  38. * <ol>
  39. * <li> The application does not care about what provider is used (the
  40. * default case).
  41. * <li> The application wants a particular provider to be used
  42. * preferentially, either for a particular mechanism or all the
  43. * time, irrespective of mechanism.
  44. * <li> The application wants to use the locally configured providers
  45. * as far as possible but if support is missing for one or more
  46. * mechanisms then it wants to fall back on its own provider.
  47. *</ol><p>
  48. *
  49. * The <code>GSSManager</code> class has two methods that enable these modes of
  50. * usage: {@link #addProviderAtFront(Provider, Oid) addProviderAtFront} and
  51. * {@link #addProviderAtEnd(Provider, Oid) addProviderAtEnd}. These methods
  52. * have the effect of creating an ordered list of <i><provider,
  53. * oid></i> pairs where each pair indicates a preference of provider
  54. * for a given oid.<p>
  55. *
  56. * It is important to note that there are certain interactions
  57. * between the different GSS-API objects that are created by a
  58. * GSSManager, where the provider that is used for a particular mechanism
  59. * might need to be consistent across all objects. For instance, if a
  60. * GSSCredential contains elements from a provider <i>p</i> for a mechanism
  61. * <i>m</i>, it should generally be passed in to a GSSContext that will use
  62. * provider <i>p</i> for the mechanism <i>m</i>. A simple rule of thumb
  63. * that will maximize portability is that objects created from different
  64. * GSSManager's should not be mixed, and if possible, a different
  65. * GSSManager instance should be created if the application wants to invoke
  66. * the <code>addProviderAtFront</code> method on a GSSManager that has
  67. * already created an object.<p>
  68. *
  69. * Here is some sample code showing how the GSSManager might be used: <p>
  70. * <pre>
  71. * GSSManager manager = GSSManager.getInstance();
  72. *
  73. * Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2");
  74. * Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1");
  75. *
  76. * // Identify who the client wishes to be
  77. * GSSName userName = manager.createName("duke", GSSName.NT_USER_NAME);
  78. *
  79. * // Identify the name of the server. This uses a Kerberos specific
  80. * // name format.
  81. * GSSName serverName = manager.createName("nfs/foo.sun.com",
  82. * krb5PrincipalNameType);
  83. *
  84. * // Acquire credentials for the user
  85. * GSSCredential userCreds = manager.createCredential(userName,
  86. * GSSCredential.DEFAULT_LIFETIME,
  87. * krb5Mechanism,
  88. * GSSCredential.INITIATE_ONLY);
  89. *
  90. * // Instantiate and initialize a security context that will be
  91. * // established with the server
  92. * GSSContext context = manager.createContext(serverName,
  93. * krb5Mechanism,
  94. * userCreds,
  95. * GSSContext.DEFAULT_LIFETIME);
  96. * </pre><p>
  97. *
  98. * The server side might use the following variation of this source:<p>
  99. *
  100. * <pre>
  101. * // Acquire credentials for the server
  102. * GSSCredential serverCreds = manager.createCredential(serverName,
  103. * GSSCredential.DEFAULT_LIFETIME,
  104. * krb5Mechanism,
  105. * GSSCredential.ACCEPT_ONLY);
  106. *
  107. * // Instantiate and initialize a security context that will
  108. * // wait for an establishment request token from the client
  109. * GSSContext context = manager.createContext(serverCreds);
  110. * </pre>
  111. *
  112. * @author Mayank Upadhyay
  113. * @version 1.8, 01/23/03
  114. * @see GSSName
  115. * @see GSSCredential
  116. * @see GSSContext
  117. * @since 1.4
  118. */
  119. public abstract class GSSManager {
  120. /**
  121. * Returns the default GSSManager implementation.
  122. *
  123. * @return a GSSManager implementation
  124. */
  125. public static GSSManager getInstance() {
  126. return new sun.security.jgss.GSSManagerImpl();
  127. }
  128. /**
  129. * Returns a list of mechanisms that are available to GSS-API callers
  130. * through this GSSManager. The default GSSManager obtained from the
  131. * {@link #getInstance() getInstance()} method includes the Oid
  132. * "1.2.840.113554.1.2.2" in its list. This Oid identifies the Kerberos
  133. * v5 GSS-API mechanism that is defined in RFC 1964.
  134. *
  135. * @return an array of Oid objects corresponding to the mechanisms that
  136. * are available. A <code>null</code> value is returned when no
  137. * mechanism are available (an example of this would be when mechanism
  138. * are dynamically configured, and currently no mechanisms are
  139. * installed).
  140. */
  141. public abstract Oid[] getMechs();
  142. /**
  143. * Returns then name types supported by the indicated mechanism.<p>
  144. *
  145. * The default GSSManager instance includes support for the Kerberos v5
  146. * mechanism. When this mechanism ("1.2.840.113554.1.2.2") is indicated,
  147. * the returned list will contain at least the following nametypes:
  148. * {@link GSSName#NT_HOSTBASED_SERVICE GSSName.NT_HOSTBASED_SERVICE},
  149. * {@link GSSName#NT_EXPORT_NAME GSSName.NT_EXPORT_NAME}, and the
  150. * Kerberos v5 specific Oid "1.2.840.113554.1.2.2.1". The namespace for
  151. * the Oid "1.2.840.113554.1.2.2.1" is defined in RFC 1964.
  152. *
  153. * @return an array of Oid objects corresponding to the name types that
  154. * the mechanism supports.
  155. * @param mech the Oid of the mechanism to query
  156. *
  157. * @see #getMechsForName(Oid)
  158. *
  159. * @throws GSSException containing the following
  160. * major error codes:
  161. * {@link GSSException#BAD_MECH GSSException.BAD_MECH}
  162. * {@link GSSException#FAILURE GSSException.FAILURE}
  163. */
  164. public abstract Oid[] getNamesForMech(Oid mech)
  165. throws GSSException;
  166. /**
  167. * Returns a list of mechanisms that support the indicated name type.<p>
  168. *
  169. * The Kerberos v5 mechanism ("1.2.840.113554.1.2.2") will always be
  170. * returned in this list when the indicated nametype is one of
  171. * {@link GSSName#NT_HOSTBASED_SERVICE GSSName.NT_HOSTBASED_SERVICE},
  172. * {@link GSSName#NT_EXPORT_NAME GSSName.NT_EXPORT_NAME}, or
  173. * "1.2.840.113554.1.2.2.1".
  174. *
  175. * @return an array of Oid objects corresponding to the mechanisms that
  176. * support the specified name type. <code>null</code> is returned when no
  177. * mechanisms are found to support the specified name type.
  178. * @param nameType the Oid of the name type to look for
  179. *
  180. * @see #getNamesForMech(Oid)
  181. */
  182. public abstract Oid[] getMechsForName(Oid nameType);
  183. /**
  184. * Factory method to convert a string name from the
  185. * specified namespace to a GSSName object. In general, the
  186. * <code>GSSName</code> object created will contain multiple
  187. * representations of the name, one for each mechanism that is
  188. * supported; two examples that are exceptions to this are when
  189. * the namespace type parameter indicates NT_EXPORT_NAME or when the
  190. * GSS-API implementation is not multi-mechanism. It is
  191. * not recommended to use this method with a NT_EXPORT_NAME type because
  192. * representing a previously exported name consisting of abitrary bytes
  193. * as a String might cause problems with character encoding schemes. In
  194. * such cases it is recommended that the bytes be passed in directly to
  195. * the overloaded form of this method {@link #createName(byte[],
  196. * Oid) createName}.
  197. *
  198. * @param nameStr the string representing a printable form of the name to
  199. * create.
  200. * @param nameType the Oid specifying the namespace of the printable name
  201. * supplied. <code>null</code> can be used to specify
  202. * that a mechanism specific default printable syntax should
  203. * be assumed by each mechanism that examines nameStr.
  204. * It is not advisable to use the nametype NT_EXPORT_NAME with this
  205. * method.
  206. * @return a GSSName representing the indicated principal
  207. *
  208. * @see GSSName
  209. * @see GSSName#NT_EXPORT_NAME
  210. *
  211. * @throws GSSException containing the following
  212. * major error codes:
  213. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  214. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  215. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  216. * {@link GSSException#FAILURE GSSException.FAILURE}
  217. */
  218. public abstract GSSName createName(String nameStr, Oid nameType)
  219. throws GSSException;
  220. /**
  221. * Factory method to convert a byte array containing a
  222. * name from the specified namespace to a GSSName object. In general,
  223. * the <code>GSSName</code> object created will contain multiple
  224. * representations of the name, one for each mechanism that is
  225. * supported; two examples that are exceptions to this are when the
  226. * namespace type parameter indicates NT_EXPORT_NAME or when the
  227. * GSS-API implementation is not multi-mechanism. The bytes that are
  228. * passed in are interpreted by each underlying mechanism according to
  229. * some encoding scheme of its choice for the given nametype.
  230. *
  231. * @param name the byte array containing the name to create
  232. * @param nameType the Oid specifying the namespace of the name supplied
  233. * in the byte array. <code>null</code> can be used to specify that a
  234. * mechanism specific default syntax should be assumed by each mechanism
  235. * that examines the byte array.
  236. * @return a GSSName representing the indicated principal
  237. *
  238. * @see GSSName
  239. * @see GSSName#NT_EXPORT_NAME
  240. *
  241. * @throws GSSException containing the following
  242. * major error codes:
  243. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  244. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  245. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  246. * {@link GSSException#FAILURE GSSException.FAILURE}
  247. */
  248. public abstract GSSName createName(byte name[], Oid nameType)
  249. throws GSSException;
  250. /**
  251. * Factory method to convert a string name from the
  252. * specified namespace to a GSSName object and canonicalize it at the
  253. * same time for a mechanism. In other words, this method is
  254. * a utility that does the equivalent of two steps: the {@link
  255. * #createName(String, Oid) createName} and then also the {@link
  256. * GSSName#canonicalize(Oid) GSSName.canonicalize}.
  257. *
  258. * @param nameStr the string representing a printable form of the name to
  259. * create.
  260. * @param nameType the Oid specifying the namespace of the printable name
  261. * supplied. <code>null</code> can be used to specify
  262. * that a mechanism specific default printable syntax should
  263. * be assumed by each mechanism that examines nameStr.
  264. * It is not advisable to use the nametype NT_EXPORT_NAME with this
  265. * method.
  266. * @param mech Oid specifying the mechanism for which the name should be
  267. * canonicalized
  268. * @return a GSSName representing the indicated principal
  269. *
  270. * @see GSSName#canonicalize(Oid)
  271. * @see GSSName#NT_EXPORT_NAME
  272. *
  273. * @throws GSSException containing the following
  274. * major error codes:
  275. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  276. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  277. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  278. * {@link GSSException#FAILURE GSSException.FAILURE}
  279. */
  280. public abstract GSSName createName(String nameStr, Oid nameType,
  281. Oid mech) throws GSSException;
  282. /**
  283. * Factory method to convert a byte array containing a
  284. * name from the specified namespace to a GSSName object and canonicalize
  285. * it at the same time for a mechanism. In other words, this method is a
  286. * utility that does the equivalent of two steps: the {@link
  287. * #createName(byte[], Oid) createName} and then also {@link
  288. * GSSName#canonicalize(Oid) GSSName.canonicalize}.
  289. *
  290. * @param name the byte array containing the name to create
  291. * @param nameType the Oid specifying the namespace of the name supplied
  292. * in the byte array. <code>null</code> can be used to specify that a
  293. * mechanism specific default syntax should be assumed by each mechanism
  294. * that examines the byte array.
  295. * @param mech Oid specifying the mechanism for which the name should be
  296. * canonicalized
  297. * @return a GSSName representing the indicated principal
  298. *
  299. * @see GSSName#canonicalize(Oid)
  300. * @see GSSName#NT_EXPORT_NAME
  301. *
  302. * @throws GSSException containing the following
  303. * major error codes:
  304. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  305. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  306. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  307. * {@link GSSException#FAILURE GSSException.FAILURE}
  308. */
  309. public abstract GSSName createName(byte name[], Oid nameType, Oid mech)
  310. throws GSSException;
  311. /**
  312. * Factory method for acquiring default credentials. This will cause
  313. * the GSS-API to use system specific defaults for the set of mechanisms,
  314. * name, and lifetime.<p>
  315. *
  316. * GSS-API mechanism providers must impose a local access-control
  317. * policy on callers to prevent unauthorized callers from acquiring
  318. * credentials to which they are not entitled. The kinds of permissions
  319. * needed by different mechanism providers will be documented on a
  320. * per-mechanism basis. A failed permission check might cause a {@link
  321. * java.lang.SecurityException SecurityException} to be thrown from
  322. * this method.
  323. *
  324. * @param usage The intended usage for this credential object. The value
  325. * of this parameter must be one of:
  326. * {@link GSSCredential#INITIATE_AND_ACCEPT
  327. * GSSCredential.INITIATE_AND_ACCEPT},
  328. * {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
  329. * {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
  330. * @return a GSSCredential of the requested type.
  331. *
  332. * @see GSSCredential
  333. *
  334. * @throws GSSException containing the following
  335. * major error codes:
  336. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  337. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  338. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  339. * {@link GSSException#CREDENTIALS_EXPIRED
  340. * GSSException.CREDENTIALS_EXPIRED},
  341. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  342. * {@link GSSException#FAILURE GSSException.FAILURE}
  343. */
  344. public abstract GSSCredential createCredential (int usage)
  345. throws GSSException;
  346. /**
  347. * Factory method for acquiring a single mechanism credential.<p>
  348. *
  349. * GSS-API mechanism providers must impose a local access-control
  350. * policy on callers to prevent unauthorized callers from acquiring
  351. * credentials to which they are not entitled. The kinds of permissions
  352. * needed by different mechanism providers will be documented on a
  353. * per-mechanism basis. A failed permission check might cause a {@link
  354. * java.lang.SecurityException SecurityException} to be thrown from
  355. * this method. <p>
  356. *
  357. * Non-default values for lifetime cannot always be honored by the
  358. * underlying mechanisms, thus applications should be prepared to call
  359. * {@link GSSCredential#getRemainingLifetime() getRemainingLifetime}
  360. * on the returned credential.<p>
  361. *
  362. * @param name the name of the principal for whom this credential is to be
  363. * acquired. Use <code>null</code> to specify the default principal.
  364. * @param lifetime The number of seconds that credentials should remain
  365. * valid. Use {@link GSSCredential#INDEFINITE_LIFETIME
  366. * GSSCredential.INDEFINITE_LIFETIME} to request that the credentials
  367. * have the maximum permitted lifetime. Use {@link
  368. * GSSCredential#DEFAULT_LIFETIME GSSCredential.DEFAULT_LIFETIME} to
  369. * request default credential lifetime.
  370. * @param mech the Oid of the desired mechanism. Use <code>(Oid) null
  371. * </code> to request the default mechanism.
  372. * @param usage The intended usage for this credential object. The value
  373. * of this parameter must be one of:
  374. * {@link GSSCredential#INITIATE_AND_ACCEPT
  375. * GSSCredential.INITIATE_AND_ACCEPT},
  376. * {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
  377. * {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
  378. * @return a GSSCredential of the requested type.
  379. *
  380. * @see GSSCredential
  381. *
  382. * @throws GSSException containing the following
  383. * major error codes:
  384. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  385. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  386. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  387. * {@link GSSException#CREDENTIALS_EXPIRED
  388. * GSSException.CREDENTIALS_EXPIRED},
  389. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  390. * {@link GSSException#FAILURE GSSException.FAILURE}
  391. */
  392. public abstract GSSCredential createCredential (GSSName name,
  393. int lifetime, Oid mech, int usage)
  394. throws GSSException;
  395. /**
  396. * Factory method for acquiring credentials over a set of
  397. * mechanisms. This method attempts to acquire credentials for
  398. * each of the mechanisms specified in the array called mechs. To
  399. * determine the list of mechanisms for which the acquisition of
  400. * credentials succeeded, the caller should use the {@link
  401. * GSSCredential#getMechs() GSSCredential.getMechs} method.<p>
  402. *
  403. * GSS-API mechanism providers must impose a local access-control
  404. * policy on callers to prevent unauthorized callers from acquiring
  405. * credentials to which they are not entitled. The kinds of permissions
  406. * needed by different mechanism providers will be documented on a
  407. * per-mechanism basis. A failed permission check might cause a {@link
  408. * java.lang.SecurityException SecurityException} to be thrown from
  409. * this method.<p>
  410. *
  411. * Non-default values for lifetime cannot always be honored by the
  412. * underlying mechanisms, thus applications should be prepared to call
  413. * {@link GSSCredential#getRemainingLifetime() getRemainingLifetime}
  414. * on the returned credential.<p>
  415. *
  416. * @param name the name of the principal for whom this credential is to
  417. * be acquired. Use <code>null</code> to specify the default
  418. * principal.
  419. * @param lifetime The number of seconds that credentials should remain
  420. * valid. Use {@link GSSCredential#INDEFINITE_LIFETIME
  421. * GSSCredential.INDEFINITE_LIFETIME} to request that the credentials
  422. * have the maximum permitted lifetime. Use {@link
  423. * GSSCredential#DEFAULT_LIFETIME GSSCredential.DEFAULT_LIFETIME} to
  424. * request default credential lifetime.
  425. * @param mechs an array of Oid's indicating the mechanisms over which
  426. * the credential is to be acquired. Use <code>(Oid[]) null</code> for
  427. * requesting a system specific default set of mechanisms.
  428. * @param usage The intended usage for this credential object. The value
  429. * of this parameter must be one of:
  430. * {@link GSSCredential#INITIATE_AND_ACCEPT
  431. * GSSCredential.INITIATE_AND_ACCEPT},
  432. * {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
  433. * {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
  434. * @return a GSSCredential of the requested type.
  435. *
  436. * @see GSSCredential
  437. *
  438. * @throws GSSException containing the following
  439. * major error codes:
  440. * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
  441. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
  442. * {@link GSSException#BAD_NAME GSSException.BAD_NAME},
  443. * {@link GSSException#CREDENTIALS_EXPIRED
  444. * GSSException.CREDENTIALS_EXPIRED},
  445. * {@link GSSException#NO_CRED GSSException.NO_CRED},
  446. * {@link GSSException#FAILURE GSSException.FAILURE}
  447. */
  448. public abstract GSSCredential createCredential(GSSName name,
  449. int lifetime, Oid mechs[], int usage)
  450. throws GSSException;
  451. /**
  452. * Factory method for creating a context on the initiator's
  453. * side.
  454. *
  455. * Some mechanism providers might require that the caller be granted
  456. * permission to initiate a security context. A failed permission check
  457. * might cause a {@link java.lang.SecurityException SecurityException}
  458. * to be thrown from this method.<p>
  459. *
  460. * Non-default values for lifetime cannot always be honored by the
  461. * underlying mechanism, thus applications should be prepared to call
  462. * {@link GSSContext#getLifetime() getLifetime} on the returned
  463. * context.<p>
  464. *
  465. * @param peer the name of the target peer.
  466. * @param mech the Oid of the desired mechanism. Use <code>null</code>
  467. * to request the default mechanism.
  468. * @param myCred the credentials of the initiator. Use
  469. * <code>null</code> to act as the default initiator principal.
  470. * @param lifetime the lifetime, in seconds, requested for the
  471. * context. Use {@link GSSContext#INDEFINITE_LIFETIME
  472. * GSSContext.INDEFINITE_LIFETIME} to request that the context have the
  473. * maximum permitted lifetime. Use {@link GSSContext#DEFAULT_LIFETIME
  474. * GSSContext.DEFAULT_LIFETIME} to request a default lifetime for the
  475. * context.
  476. * @return an unestablished GSSContext
  477. *
  478. * @see GSSContext
  479. *
  480. * @throws GSSException containing the following
  481. * major error codes:
  482. * {@link GSSException#NO_CRED GSSException.NO_CRED}
  483. * {@link GSSException#CREDENTIALS_EXPIRED
  484. * GSSException.CREDENTIALS_EXPIRED}
  485. * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE}
  486. * {@link GSSException#BAD_MECH GSSException.BAD_MECH}
  487. * {@link GSSException#FAILURE GSSException.FAILURE}
  488. */
  489. public abstract GSSContext createContext(GSSName peer, Oid mech,
  490. GSSCredential myCred, int lifetime)
  491. throws GSSException;
  492. /**
  493. * Factory method for creating a context on the acceptor' side. The
  494. * context's properties will be determined from the input token supplied
  495. * to the accept method.
  496. *
  497. * Some mechanism providers might require that the caller be granted
  498. * permission to accept a security context. A failed permission check
  499. * might cause a {@link java.lang.SecurityException SecurityException}
  500. * to be thrown from this method.
  501. *
  502. * @param myCred the credentials for the acceptor. Use
  503. * <code>null</code> to act as a default acceptor principal.
  504. * @return an unestablished GSSContext
  505. *
  506. * @see GSSContext
  507. *
  508. * @throws GSSException containing the following
  509. * major error codes:
  510. * {@link GSSException#NO_CRED GSSException.NO_CRED}
  511. * {@link GSSException#CREDENTIALS_EXPIRED
  512. * GSSException.CREDENTIALS_EXPIRED}
  513. * {@link GSSException#BAD_MECH GSSException.BAD_MECH}
  514. * {@link GSSException#FAILURE GSSException.FAILURE}
  515. */
  516. public abstract GSSContext createContext(GSSCredential myCred)
  517. throws GSSException;
  518. /**
  519. * Factory method for creating a previously exported context. The
  520. * context properties will be determined from the input token and
  521. * cannot be modified through the set methods.<p>
  522. *
  523. * Implementations are not required to support the inter-process
  524. * transfer of security contexts. Before exporting a context, calling
  525. * the {@link GSSContext#isTransferable() GSSContext.isTransferable}
  526. * will indicate if the context is transferable. Calling this method in
  527. * an implementation that does not support it will result in a
  528. * <code>GSSException</code> with the error
  529. * code {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE}.
  530. *
  531. * Some mechanism providers might require that the caller be granted
  532. * permission to initiate or accept a security context. A failed
  533. * permission check might cause a {@link java.lang.SecurityException
  534. * SecurityException} to be thrown from this method.
  535. *
  536. * @param interProcessToken the token previously emitted from the
  537. * export method.
  538. * @return the previously established GSSContext
  539. *
  540. * @see GSSContext
  541. *
  542. * @throws GSSException containing the following
  543. * major error codes:
  544. * {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT},
  545. * {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
  546. * {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
  547. * {@link GSSException#UNAUTHORIZED GSSException.UNAUTHORIZED},
  548. * {@link GSSException#FAILURE GSSException.FAILURE}
  549. */
  550. public abstract GSSContext createContext(byte [] interProcessToken)
  551. throws GSSException;
  552. /**
  553. * This method is used to indicate to the GSSManager that the
  554. * application would like a particular provider to be used ahead of all
  555. * others when support is desired for the given mechanism. When a value
  556. * of null is used instead of an <code>Oid</code> for the mechanism,
  557. * the GSSManager must use the indicated provider ahead of all others
  558. * no matter what the mechanism is. Only when the indicated provider
  559. * does not support the needed mechanism should the GSSManager move on
  560. * to a different provider.<p>
  561. *
  562. * Calling this method repeatedly preserves the older settings but
  563. * lowers them in preference thus forming an ordered list of provider
  564. * and <code>Oid</code> pairs that grows at the top.<p>
  565. *
  566. * Calling addProviderAtFront with a null <code>Oid</code> will remove
  567. * all previous preferences that were set for this provider in the
  568. * GSSManager instance. Calling addProviderAtFront with a non-null
  569. * <code>Oid</code> will remove any previous preference that was set
  570. * using this mechanism and this provider together.<p>
  571. *
  572. * If the GSSManager implementation does not support an SPI with a
  573. * pluggable provider architecture it should throw a GSSException with
  574. * the status code GSSException.UNAVAILABLE to indicate that the
  575. * operation is unavailable.<p>
  576. *
  577. * Suppose an application desired that the provider A always be checked
  578. * first when any mechanism is needed, it would call:<p>
  579. * <pre>
  580. * GSSManager mgr = GSSManager.getInstance();
  581. * // mgr may at this point have its own pre-configured list
  582. * // of provider preferences. The following will prepend to
  583. * // any such list:
  584. *
  585. * mgr.addProviderAtFront(A, null);
  586. * </pre>
  587. * Now if it also desired that the mechanism of Oid m1 always be
  588. * obtained from the provider B before the previously set A was checked,
  589. * it would call:<p>
  590. * <pre>
  591. * mgr.addProviderAtFront(B, m1);
  592. * </pre>
  593. * The GSSManager would then first check with B if m1 was needed. In
  594. * case B did not provide support for m1, the GSSManager would continue
  595. * on to check with A. If any mechanism m2 is needed where m2 is
  596. * different from m1 then the GSSManager would skip B and check with A
  597. * directly.<p>
  598. *
  599. * Suppose at a later time the following call is made to the same
  600. * GSSManager instance:<p>
  601. * <pre>
  602. * mgr.addProviderAtFront(B, null)
  603. * </pre>
  604. * then the previous setting with the pair (B, m1) is subsumed by this
  605. * and should be removed. Effectively the list of preferences now
  606. * becomes {(B, null), (A, null),
  607. * ... //followed by the pre-configured list.<p>
  608. *
  609. * Please note, however, that the following call:
  610. * <pre>
  611. * mgr.addProviderAtFront(A, m3)
  612. * </pre>
  613. * does not subsume the previous setting of (A, null) and the list will
  614. * effectively become {(A, m3), (B, null), (A, null), ...}
  615. *
  616. * @param p the provider instance that should be used whenever support
  617. * is needed for mech.
  618. * @param mech the mechanism for which the provider is being set
  619. *
  620. * @throws GSSException containing the following
  621. * major error codes:
  622. * {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
  623. * {@link GSSException#FAILURE GSSException.FAILURE}
  624. */
  625. public abstract void addProviderAtFront(Provider p, Oid mech)
  626. throws GSSException;
  627. /**
  628. * This method is used to indicate to the GSSManager that the
  629. * application would like a particular provider to be used if no other
  630. * provider can be found that supports the given mechanism. When a value
  631. * of null is used instead of an Oid for the mechanism, the GSSManager
  632. * must use the indicated provider for any mechanism.<p>
  633. *
  634. * Calling this method repeatedly preserves the older settings but
  635. * raises them above newer ones in preference thus forming an ordered
  636. * list of providers and Oid pairs that grows at the bottom. Thus the
  637. * older provider settings will be utilized first before this one is.<p>
  638. *
  639. * If there are any previously existing preferences that conflict with
  640. * the preference being set here, then the GSSManager should ignore this
  641. * request.<p>
  642. *
  643. * If the GSSManager implementation does not support an SPI with a
  644. * pluggable provider architecture it should throw a GSSException with
  645. * the status code GSSException.UNAVAILABLE to indicate that the
  646. * operation is unavailable.<p>
  647. *
  648. * Suppose an application desired that when a mechanism of Oid m1 is
  649. * needed the system default providers always be checked first, and only
  650. * when they do not support m1 should a provider A be checked. It would
  651. * then make the call:<p>
  652. * <pre>
  653. * GSSManager mgr = GSSManager.getInstance();
  654. * mgr.addProviderAtEnd(A, m1);
  655. * </pre>
  656. * Now, if it also desired that for all mechanisms the provider B be
  657. * checked after all configured providers have been checked, it would
  658. * then call:<p>
  659. * <pre>
  660. * mgr.addProviderAtEnd(B, null);
  661. * </pre>
  662. * Effectively the list of preferences now becomes {..., (A, m1), (B,
  663. * null)}.<p>
  664. *
  665. * Suppose at a later time the following call is made to the same
  666. * GSSManager instance:<p>
  667. * <pre>
  668. * mgr.addProviderAtEnd(B, m2)
  669. * </pre>
  670. * then the previous setting with the pair (B, null) subsumes this and
  671. * therefore this request should be ignored. The same would happen if a
  672. * request is made for the already existing pairs of (A, m1) or (B,
  673. * null).<p>
  674. *
  675. * Please note, however, that the following call:<p>
  676. * <pre>
  677. * mgr.addProviderAtEnd(A, null)
  678. * </pre>
  679. * is not subsumed by the previous setting of (A, m1) and the list will
  680. * effectively become {..., (A, m1), (B, null), (A, null)}
  681. *
  682. * @param p the provider instance that should be used whenever support
  683. * is needed for mech.
  684. * @param mech the mechanism for which the provider is being set
  685. *
  686. * @throws GSSException containing the following
  687. * major error codes:
  688. * {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
  689. * {@link GSSException#FAILURE GSSException.FAILURE}
  690. */
  691. public abstract void addProviderAtEnd(Provider p, Oid mech)
  692. throws GSSException;
  693. }