1. /*
  2. * @(#)LdapContext.java 1.8 01/02/09
  3. *
  4. * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming.ldap;
  11. import javax.naming.NamingException;
  12. import javax.naming.directory.DirContext;
  13. import java.util.Hashtable;
  14. /**
  15. * This interface represents a context in which you can perform
  16. * operations with LDAPv3-style controls and perform LDAPv3-style
  17. * extended operations.
  18. *
  19. * For applications that do not require such controls or extended
  20. * operations, the more generic <tt>javax.naming.directory.DirContext</tt>
  21. * should be used instead.
  22. *
  23. * <h3>Usage Details About Controls</h3>
  24. *
  25. * This interface provides support for LDAP v3 controls.
  26. * At a high level, this support allows a user
  27. * program to set request controls for LDAP operations that are executed
  28. * in the course of the user program's invocation of
  29. * <tt>Context</tt>/<tt>DirContext</tt>
  30. * methods, and read response controls resulting from LDAP operations.
  31. * At the implementation level, there are some details that developers of
  32. * both the user program and service providers need to understand in order
  33. * to correctly use request and response controls.
  34. *
  35. * <h3>Request Controls</h3>
  36. * <p>
  37. * There are two types of request controls:
  38. * <ul>
  39. * <li>Request controls that affect how a connection is created
  40. * <li>Request controls that affect context methods
  41. * </ul>
  42. *
  43. * The former is used whenever a connection needs to be established or
  44. * re-established with an LDAP server. The latter is used when all other
  45. * LDAP operations are sent to the LDAP server. The reason why a
  46. * distinction between these two types of request controls is necessary
  47. * is because JNDI is a high-level API that does not deal directly with
  48. * connections. It is the job of service providers to do any necessary
  49. * connection management. Consequently, a single
  50. * connection may be shared by multiple context instances, and a service provider
  51. * is free to use its own algorithms to conserve connection and network
  52. * usage. Thus, when a method is invoked on the context instance, the service
  53. * provider might need to do some connection management in addition to
  54. * performing the corresponding LDAP operations. For connection management,
  55. * it uses the <em>connection request controls</em>, while for the normal
  56. * LDAP operations, it uses the <em>context request controls</em>.
  57. *<p>Unless explicitly qualified, the term "request controls" refers to
  58. * context request controls.
  59. *
  60. * <h4>Context Request Controls</h4>
  61. * There are two ways in which a context instance gets its request controls:
  62. * <ol>
  63. * <tt>
  64. * <li>ldapContext.newInstance(<strong>reqCtls</strong>)
  65. * <li>ldapContext.setRequestControls(<strong>reqCtls</strong>)
  66. * </tt>
  67. * </ol>
  68. * where <tt>ldapContext</tt> is an instance of <tt>LdapContext</tt>.
  69. * Specifying <tt>null</tt> or an empty array for <tt>reqCtls</tt>
  70. * means no request controls.
  71. * <tt>newInstance()</tt> creates a new instance of a context using
  72. * <tt>reqCtls</tt>, while <tt>setRequestControls()</tt>
  73. * updates an existing context instance's request controls to <tt>reqCtls</tt>.
  74. * <p>
  75. * Unlike environment properties, request controls of a context instance
  76. * <em>are not inherited</em> by context instances that are derived from
  77. * it. Derived context instances have <tt>null</tt> as their context
  78. * request controls. You must set the request controls of a derived context
  79. * instance explicitly using <tt>setRequestControls()</tt>.
  80. * <p>
  81. * A context instance's request controls are retrieved using
  82. * the method <tt>getRequestControls()</tt>.
  83. *
  84. * <h4>Connection Request Controls</h4>
  85. * There are three ways in which connection request controls are set:
  86. * <ol>
  87. * <tt>
  88. * <li>
  89. * new InitialLdapContext(env, <strong>connCtls</strong>)
  90. * <li>refException.getReferralContext(env, <strong>connCtls</strong>)
  91. * <li>ldapContext.reconnect(<strong>connCtls</strong>);
  92. * </tt>
  93. * </ol>
  94. * where <tt>refException</tt> is an instance of
  95. * <tt>LdapReferralException</tt>, and <tt>ldapContext</tt> is an
  96. * instance of <tt>LdapContext</tt>.
  97. * Specifying <tt>null</tt> or an empty array for <tt>connCtls</tt>
  98. * means no connection request controls.
  99. * <p>
  100. * Like environment properties, connection request controls of a context
  101. * <em>are inherited</em> by contexts that are derived from it.
  102. * Typically, you initialize the connection request controls using the
  103. * <tt>InitialLdapContext</tt> constructor or
  104. * <tt>LdapReferralContext.getReferralContext()</tt>. These connection
  105. * request controls are inherited by contexts that share the same
  106. * connection--that is, contexts derived from the initial or referral
  107. * contexts.
  108. * <p>
  109. * Use <tt>reconnect()</tt> to change the connection request controls of
  110. * a context.
  111. * Invoking <tt>ldapContext.reconnect()</tt> affects only the
  112. * connection used by <tt>ldapContext</tt> and any new contexts instances that are
  113. * derived form <tt>ldapContext</tt>. Contexts that previously shared the
  114. * connection with <tt>ldapContext</tt> remain unchanged. That is, a context's
  115. * connection request controls must be explicitly changed and is not
  116. * affected by changes to another context's connection request
  117. * controls.
  118. * <p>
  119. * A context instance's connection request controls are retrieved using
  120. * the method <tt>getConnectControls()</tt>.
  121. *
  122. * <h4>Service Provider Requirements</h4>
  123. *
  124. * A service provider supports connection and context request controls
  125. * in the following ways. Context request controls must be associated on
  126. * a per context instance basis while connection request controls must be
  127. * associated on a per connection instance basis. The service provider
  128. * must look for the connection request controls in the environment
  129. * property "java.naming.ldap.control.connect" and pass this environment
  130. * property on to context instances that it creates.
  131. *
  132. * <h3>Response Controls</h3>
  133. *
  134. * The method <tt>LdapContext.getResponseControls()</tt> is used to
  135. * retrieve the response controls generated by LDAP operations executed
  136. * as the result of invoking a <tt>Context</tt>/<tt>DirContext</tt>
  137. * operation. The result is all of the responses controls generated
  138. * by the underlying LDAP operations, including any implicit reconnection.
  139. * To get only the reconnection response controls,
  140. * use <tt>reconnect()</tt> followed by <tt>getResponseControls()</tt>.
  141. *
  142. * <h3>Parameters</h3>
  143. *
  144. * A <tt>Control[]</tt> array
  145. * passed as a parameter to any method is owned by the caller.
  146. * The service provider will not modify the array or keep a reference to it,
  147. * although it may keep references to the individual <tt>Control</tt> objects
  148. * in the array.
  149. * A <tt>Control[]</tt> array returned by any method is immutable, and may
  150. * not subsequently be modified by either the caller or the service provider.
  151. *
  152. * @author Rosanna Lee
  153. * @author Scott Seligman
  154. * @author Vincent Ryan
  155. * @version 1.8 01/02/09
  156. *
  157. * @see InitialLdapContext
  158. * @see LdapReferralException#getReferralContext(java.util.Hashtable,javax.naming.ldap.Control[])
  159. * @since 1.3
  160. */
  161. public interface LdapContext extends DirContext {
  162. /**
  163. * Performs an extended operation.
  164. *
  165. * This method is used to support LDAPv3 extended operations.
  166. * @param request The non-null request to be performed.
  167. * @return The possibly null response of the operation. null means
  168. * the operation did not generate any response.
  169. * @throws NamingException If an error occurred while performing the
  170. * extended operation.
  171. */
  172. public ExtendedResponse extendedOperation(ExtendedRequest request)
  173. throws NamingException;
  174. /**
  175. * Creates a new instance of this context initialized using request controls.
  176. *
  177. * This method is a convenience method for creating a new instance
  178. * of this context for the purposes of multithreaded access.
  179. * For example, if multiple threads want to use different context
  180. * request controls,
  181. * each thread may use this method to get its own copy of this context
  182. * and set/get context request controls without having to synchronize with other
  183. * threads.
  184. *<p>
  185. * The new context has the same environment properties and connection
  186. * request controls as this context. See the class description for details.
  187. * Implementations might also allow this context and the new context
  188. * to share the same network connection or other resources if doing
  189. * so does not impede the independence of either context.
  190. *
  191. * @param requestControls The possibly null request controls
  192. * to use for the new context.
  193. * If null, the context is initialized with no request controls.
  194. *
  195. * @return A non-null <tt>LdapContext</tt> instance.
  196. * @exception NamingException If an error occurred while creating
  197. * the new instance.
  198. * @see InitialLdapContext
  199. */
  200. public LdapContext newInstance(Control[] requestControls)
  201. throws NamingException;
  202. /**
  203. * Reconnects to the LDAP server using the supplied controls and
  204. * this context's environment.
  205. *<p>
  206. * This method is a way to explicitly initiate an LDAP "bind" operation.
  207. * For example, you can use this method to set request controls for
  208. * the LDAP "bind" operation, or to explicitly connect to the server
  209. * to get response controls returned by the LDAP "bind" operation.
  210. *<p>
  211. * This method sets this context's <tt>connCtls</tt>
  212. * to be its new connection request controls. This context's
  213. * context request controls are not affected.
  214. * After this method has been invoked, any subsequent
  215. * implicit reconnections will be done using <tt>connCtls</tt>.
  216. * <tt>connCtls</tt> are also used as
  217. * connection request controls for new context instances derived from this
  218. * context.
  219. * These connection request controls are not
  220. * affected by <tt>setRequestControls()</tt>.
  221. *<p>
  222. * Service provider implementors should read the "Service Provider" section
  223. * in the class description for implementation details.
  224. * @param connCtls The possibly null controls to use. If null, no
  225. * controls are used.
  226. * @exception NamingException If an error occurred while reconnecting.
  227. * @see #getConnectControls
  228. * @see #newInstance
  229. */
  230. public void reconnect(Control[] connCtls) throws NamingException;
  231. /**
  232. * Retrieves the connection request controls in effect for this context.
  233. * The controls are owned by the JNDI implementation and are
  234. * immutable. Neither the array nor the controls may be modified by the
  235. * caller.
  236. *
  237. * @return A possibly-null array of controls. null means no connect controls
  238. * have been set for this context.
  239. * @exception NamingException If an error occurred while getting the request
  240. * controls.
  241. */
  242. public Control[] getConnectControls() throws NamingException;
  243. /**
  244. * Sets the request controls for methods subsequently
  245. * invoked on this context.
  246. * The request controls are owned by the JNDI implementation and are
  247. * immutable. Neither the array nor the controls may be modified by the
  248. * caller.
  249. * <p>
  250. * This removes any previous request controls and adds
  251. * <tt>requestControls</tt>
  252. * for use by subsequent methods invoked on this context.
  253. * This method does not affect this context's connection request controls.
  254. *<p>
  255. * Note that <tt>requestControls</tt> will be in effect until the next
  256. * invocation of <tt>setRequestControls()</tt>. You need to explicitly
  257. * invoke <tt>setRequestControls()</tt> with <tt>null</tt> or an empty
  258. * array to clear the controls if you don't want them to affect the
  259. * context methods any more.
  260. * To check what request controls are in effect for this context, use
  261. * <tt>getRequestControls()</tt>.
  262. * @param requestControls The possibly null controls to use. If null, no
  263. * controls are used.
  264. * @exception NamingException If an error occurred while setting the
  265. * request controls.
  266. * @see #getRequestControls
  267. */
  268. public void setRequestControls(Control[] requestControls)
  269. throws NamingException;
  270. /**
  271. * Retrieves the request controls in effect for this context.
  272. * The request controls are owned by the JNDI implementation and are
  273. * immutable. Neither the array nor the controls may be modified by the
  274. * caller.
  275. *
  276. * @return A possibly-null array of controls. null means no request controls
  277. * have been set for this context.
  278. * @exception NamingException If an error occurred while getting the request
  279. * controls.
  280. * @see #setRequestControls
  281. */
  282. public Control[] getRequestControls() throws NamingException;
  283. /**
  284. * Retrieves the response controls produced as a result of the last
  285. * method invoked on this context.
  286. * The response controls are owned by the JNDI implementation and are
  287. * immutable. Neither the array nor the controls may be modified by the
  288. * caller.
  289. *<p>
  290. * These response controls might have been generated by a successful or
  291. * failed operation.
  292. *<p>
  293. * When a context method that may return response controls is invoked,
  294. * response controls from the previous method invocation are cleared.
  295. * <tt>getResponseControls()</tt> returns all of the response controls
  296. * generated by LDAP operations used by the context method in the order
  297. * received from the LDAP server.
  298. * Invoking <tt>getResponseControls()</tt> does not
  299. * clear the response controls. You can call it many times (and get
  300. * back the same controls) until the next context method that may return
  301. * controls is invoked.
  302. *<p>
  303. * @return A possibly null array of controls. If null, the previous
  304. * method invoked on this context did not produce any controls.
  305. * @exception NamingException If an error occurred while getting the response
  306. * controls.
  307. */
  308. public Control[] getResponseControls() throws NamingException;
  309. /**
  310. * Constant that holds the name of the environment property
  311. * for specifying the list of control factories to use. The value
  312. * of the property should be a colon-separated list of the fully
  313. * qualified class names of factory classes that will create a control
  314. * given another control. See
  315. * <tt>ControlFactory.getControlInstance()</tt> for details.
  316. * This property may be specified in the environment, an applet
  317. * parameter, a system property, or one or more resource files.
  318. *<p>
  319. * The value of this constant is "java.naming.factory.control".
  320. *<p>
  321. * @see ControlFactory
  322. * @see javax.naming.Context#addToEnvironment
  323. * @see javax.naming.Context#removeFromEnvironment
  324. */
  325. static final String CONTROL_FACTORIES = "java.naming.factory.control";
  326. }