1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapConstraints.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
34 namespace Novell
.Directory
.Ldap
37 /// <summary> Defines options controlling Ldap operations on the directory.
39 /// An LdapConstraints object is always associated with an LdapConnection
40 /// object; its values can be changed with LdapConnection.setConstraints, or
41 /// overridden by passing an LdapConstraints object to an operation.
44 /// <seealso cref="LdapConnection.Constraints">
46 public class LdapConstraints
: System
.ICloneable
48 /// <summary> Returns the maximum number of referrals to follow during automatic
49 /// referral following. The operation will be abandoned and terminated by
50 /// the API with a result code of LdapException.REFERRAL_LIMIT_EXCEEDED
51 /// if the number of referrals in a sequence exceeds the limit.
52 /// It is ignored for asynchronous operations.
55 /// <returns> The maximum number of referrals to follow in sequence
58 /// <seealso cref="HopLimit">
60 /// <seealso cref="LdapException.REFERRAL_LIMIT_EXCEEDED">
62 /// <summary> Sets the maximum number of referrals to follow in sequence during
63 /// automatic referral following.
66 /// <param name="hop_limit">The maximum number of referrals to follow in a
67 /// sequence during automatic referral following.
68 /// The default value is 10. A value of 0 means no limit.
69 /// The operation will be abandoned and terminated by the
70 /// API with a result code of
71 /// LdapException.REFERRAL_LIMIT_EXCEEDED if the
72 /// number of referrals in a sequence exceeds the limit.
73 /// It is ignored for asynchronous operations.
76 /// <seealso cref="LdapException.REFERRAL_LIMIT_EXCEEDED">
78 virtual public int HopLimit
87 this.hopLimit
= value;
92 /// <summary> Gets all the properties of the constraints object which has been
93 /// assigned with {@link #setProperty(String, Object)}.
94 /// A value of <code>null</code> is returned if no properties are defined.
97 /// <seealso cref="Object">
99 /// <seealso cref="LdapConnection.getProperty">
101 /// <summary> Sets all the properties of the constraints object.
104 /// <param name="props">the properties represented by the Hashtable object to set.
106 virtual internal System
.Collections
.Hashtable Properties
119 properties
= (System
.Collections
.Hashtable
) value.Clone();
124 /// <summary> Specified whether or not referrals are followed automatically.
127 /// <returns> True if referrals are followed automatically, or
128 /// false if referrals throw an LdapReferralException.
130 /// <summary> Specifies whether referrals are followed automatically or if
131 /// referrals throw an LdapReferralException.
133 /// Referrals of any type other than to an Ldap server (for example, a
134 /// referral URL other than ldap://something) are ignored on automatic
135 /// referral following.
137 /// The default is false.
140 /// <param name="doReferrals"> True to follow referrals automatically.
141 /// False to throw an LdapReferralException if
142 /// the server returns a referral.
144 virtual public bool ReferralFollowing
153 this.doReferrals
= value;
158 /// <summary> Returns the maximum number of milliseconds to wait for any operation
159 /// under these constraints.
161 /// If the value is 0, there is no maximum time limit on waiting
162 /// for operation results. The actual granularity of the timeout depends
163 /// platform. This limit is enforced the the API on an
164 /// operation, not by the server.
165 /// The operation will be abandoned and terminated by the
166 /// API with a result code of LdapException.Ldap_TIMEOUT if the
167 /// operation exceeds the time limit.
170 /// <returns> The maximum number of milliseconds to wait for the operation.
173 /// <seealso cref="LdapException.Ldap_TIMEOUT">
175 /// <summary> Sets the maximum number of milliseconds the client waits for
176 /// any operation under these constraints to complete.
178 /// If the value is 0, there is no maximum time limit enforced by the
179 /// API on waiting for the operation results. The actual granularity of
180 /// the timeout depends on the platform.
181 /// The operation will be abandoned and terminated by the
182 /// API with a result code of LdapException.Ldap_TIMEOUT if the
183 /// operation exceeds the time limit.
186 /// <param name="msLimit"> The maximum milliseconds to wait.
189 /// <seealso cref="LdapException.Ldap_TIMEOUT">
191 virtual public int TimeLimit
200 this.msLimit
= value;
206 private int msLimit
= 0;
207 private int hopLimit
= 10;
208 private bool doReferrals
= false;
209 private LdapReferralHandler refHandler
= null;
210 private LdapControl
[] controls
= null;
211 private static System
.Object nameLock
; // protect agentNum
212 private static int lConsNum
= 0; // Debug, LdapConstraints num
213 private System
.String name
; // String name for debug
214 private System
.Collections
.Hashtable properties
= null; // Properties
216 /// <summary> Constructs a new LdapConstraints object that specifies the default
217 /// set of constraints.
219 public LdapConstraints()
221 // Get a unique constraints name for debug
225 /// <summary> Constructs a new LdapConstraints object specifying constraints that
226 /// control wait time, and referral handling.
229 /// <param name="msLimit"> The maximum time in milliseconds to wait for results.
230 /// The default is 0, which means that there is no
231 /// maximum time limit. This limit is enforced for an
232 /// operation by the API, not by the server.
233 /// The operation will be abandoned and terminated by the
234 /// API with a result code of LdapException.Ldap_TIMEOUT
235 /// if the operation exceeds the time limit.
238 /// <param name="doReferrals">Determines whether to automatically follow
239 /// referrals or not. Specify true to follow
240 /// referrals automatically, and false to throw
241 /// an LdapReferralException if the server responds
242 /// with a referral. False is the default value.
243 /// The way referrals are followed automatically is
244 /// determined by the setting of the handler parameter.
245 /// It is ignored for asynchronous operations.
248 /// <param name="handler"> The custom authentication handler called when
249 /// LdapConnection needs to authenticate, typically on
250 /// following a referral. A null may be specified to
251 /// indicate default authentication processing, i.e.
252 /// referrals are followed with anonymous authentication.
253 /// The handler object may be an implemention of either the
254 /// LdapBindHandler or LdapAuthHandler interface.
255 /// The implementation of these interfaces determines how
256 /// authentication is performed when following referrals.
257 /// It is ignored for asynchronous operations.
260 /// <param name="hop_limit">The maximum number of referrals to follow in a
261 /// sequence during automatic referral following.
262 /// The default value is 10. A value of 0 means no limit.
263 /// The operation will be abandoned and terminated by the
264 /// API with a result code of
265 /// LdapException.REFERRAL_LIMIT_EXCEEDED if the
266 /// number of referrals in a sequence exceeds the limit.
267 /// It is ignored for asynchronous operations.
270 /// <seealso cref="LdapException.Ldap_TIMEOUT">
272 /// <seealso cref="LdapException.REFERRAL_LIMIT_EXCEEDED">
274 /// <seealso cref="LdapException.REFERRAL">
276 /// <seealso cref="LdapReferralException">
278 /// <seealso cref="LdapBindHandler">
280 /// <seealso cref="LdapAuthHandler">
282 public LdapConstraints(int msLimit
, bool doReferrals
, LdapReferralHandler handler
, int hop_limit
)
284 this.msLimit
= msLimit
;
285 this.doReferrals
= doReferrals
;
286 this.refHandler
= handler
;
287 this.hopLimit
= hop_limit
;
288 // Get a unique constraints name for debug
292 /// <summary> Returns the controls to be sent to the server.
295 /// <returns> The controls to be sent to the server, or null if none.
298 /// <seealso cref="Controls">
300 public virtual LdapControl
[] getControls()
305 /// <summary> Gets a property of the constraints object which has been
306 /// assigned with {@link #setProperty(String, Object)}.
309 /// <param name="name"> Name of the property to be returned.
312 /// <returns> the object associated with the property,
313 /// or <code>null</code> if the property is not set.
316 /// <seealso cref="Object">
318 /// <seealso cref="LdapConnection.getProperty(String)">
320 public virtual System
.Object
getProperty(System
.String name
)
322 if (properties
== null)
324 return null; // Requested property not available.
326 return properties
[name
];
329 /// <summary> Returns an object that can process authentication for automatic
330 /// referral handling.
335 /// <returns> An LdapReferralHandler object that can process authentication.
338 internal virtual LdapReferralHandler
getReferralHandler()
343 /// <summary> Sets a single control to be sent to the server.
346 /// <param name="control"> A single control to be sent to the server or
349 public virtual void setControls(LdapControl control
)
353 this.controls
= null;
356 this.controls
= new LdapControl
[1];
357 this.controls
[0] = (LdapControl
) control
.Clone();
361 /// <summary> Sets controls to be sent to the server.
364 /// <param name="controls"> An array of controls to be sent to the server or
367 public virtual void setControls(LdapControl
[] controls
)
369 if ((controls
== null) || (controls
.Length
== 0))
371 this.controls
= null;
374 this.controls
= new LdapControl
[controls
.Length
];
375 for (int i
= 0; i
< controls
.Length
; i
++)
377 this.controls
[i
] = (LdapControl
) controls
[i
].Clone();
382 /// <summary> Sets a property of the constraints object.
384 /// No property names have been defined at this time, but the
385 /// mechanism is in place in order to support revisional as well as
386 /// dynamic and proprietary extensions to operation modifiers.
389 /// <param name="name"> Name of the property to set.
392 /// <param name="value"> Value to assign to the property.
393 /// property is not supported.
395 /// @throws NullPointerException if name or value are null
398 /// <seealso cref="LdapConnection.getProperty">
400 public virtual void setProperty(System
.String name
, System
.Object value_Renamed
)
402 if (properties
== null)
404 properties
= new System
.Collections
.Hashtable();
406 SupportClass
.PutElement(properties
, name
, value_Renamed
);
410 /// <summary> Specifies the object that will process authentication requests
411 /// during automatic referral following.
413 /// The default is null.
416 /// <param name="handler"> An object that implements LdapBindHandler or
420 /// <seealso cref="LdapAuthHandler">
422 /// <seealso cref="LdapBindHandler">
424 public virtual void setReferralHandler(LdapReferralHandler handler
)
426 refHandler
= handler
;
430 /// <summary> Clones an LdapConstraints object.
433 /// <returns> An LdapConstraints object.
435 public System
.Object
Clone()
439 System
.Object newObj
= base.MemberwiseClone();
440 if (controls
!= null)
442 ((LdapConstraints
) newObj
).controls
= new LdapControl
[controls
.Length
];
443 controls
.CopyTo(((LdapConstraints
) newObj
).controls
, 0);
445 if (properties
!= null)
447 ((LdapConstraints
) newObj
).properties
= (System
.Collections
.Hashtable
) properties
.Clone();
451 catch (System
.Exception ce
)
453 throw new System
.SystemException("Internal error, cannot create clone");
456 static LdapConstraints()
458 nameLock
= new System
.Object();