View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.message;
21  
22  
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  import javax.naming.CommunicationException;
28  import javax.naming.LimitExceededException;
29  import javax.naming.PartialResultException;
30  import javax.naming.SizeLimitExceededException;
31  
32  import org.apache.directory.api.ldap.model.exception.LdapAdminLimitExceededException;
33  import org.apache.directory.api.ldap.model.exception.LdapAffectMultipleDsaException;
34  import org.apache.directory.api.ldap.model.exception.LdapAliasDereferencingException;
35  import org.apache.directory.api.ldap.model.exception.LdapAliasException;
36  import org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException;
37  import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
38  import org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException;
39  import org.apache.directory.api.ldap.model.exception.LdapCannotCancelException;
40  import org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException;
41  import org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException;
42  import org.apache.directory.api.ldap.model.exception.LdapException;
43  import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException;
44  import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
45  import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
46  import org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException;
47  import org.apache.directory.api.ldap.model.exception.LdapLoopDetectedException;
48  import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
49  import org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException;
50  import org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException;
51  import org.apache.directory.api.ldap.model.exception.LdapNoSuchOperationException;
52  import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
53  import org.apache.directory.api.ldap.model.exception.LdapOperationException;
54  import org.apache.directory.api.ldap.model.exception.LdapOtherException;
55  import org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException;
56  import org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException;
57  import org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException;
58  import org.apache.directory.api.ldap.model.exception.LdapSizeLimitExceededException;
59  import org.apache.directory.api.ldap.model.exception.LdapStrongAuthenticationRequiredException;
60  import org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException;
61  import org.apache.directory.api.ldap.model.exception.LdapTooLateException;
62  import org.apache.directory.api.ldap.model.exception.LdapUnknownException;
63  import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
64  
65  
66  /**
67   * Type safe LDAP message envelope result code enumeration. The resultCode is a
68   * parameter of the LDAPResult which is the construct used in this protocol to
69   * return success or failure indications from servers to clients. In response to
70   * various requests servers will return responses containing fields of type
71   * LDAPResult to indicate the final status of a protocol operation request. This
72   * enumeration represents the various status codes associated with an
73   * LDAPResult, hence it is called the ResultCodeEnum. Here are the definitions
74   * and values for error codes from section 4.1.10 of <a
75   * href="http://www.faqs.org/rfcs/rfc2251.html">RFC 2251</a>:
76   * 
77   * <pre><code>
78   *     resultCode
79   *        ENUMERATED {
80   *           success                      (0),
81   *           operationsError              (1),
82   *           protocolError                (2),
83   *           timeLimitExceeded            (3),
84   *           sizeLimitExceeded            (4),
85   *           compareFalse                 (5),
86   *           compareTrue                  (6),
87   *           authMethodNotSupported       (7),
88   *           strongAuthRequired           (8),
89   *           partialResults               (9),   -- new
90   *           referral                     (10),  -- new
91   *           adminLimitExceeded           (11),  -- new
92   *           unavailableCriticalExtension (12),  -- new
93   *           confidentialityRequired      (13),  -- new
94   *           saslBindInProgress           (14),  -- new
95   *           noSuchAttribute              (16),
96   *           undefinedAttributeType       (17),
97   *           inappropriateMatching        (18),
98   *           constraintViolation          (19),
99   *           attributeOrValueExists       (20),
100  *           invalidAttributeSyntax       (21),
101  *           -- 22-31 unused --
102  *           NO_SUCH_OBJECT               (32),
103  *           aliasProblem                 (33),
104  *           invalidDNSyntax              (34),
105  *           -- 35 reserved for undefined isLeaf --
106  *           aliasDereferencingProblem    (36),
107  *           -- 37-47 unused --
108  *           inappropriateAuthentication  (48),
109  *           invalidCredentials           (49),
110  *           insufficientAccessRights     (50),
111  *           busy                         (51),
112  *           unavailable                  (52),
113  *           unwillingToPerform           (53),
114  *           loopDetect                   (54),
115  *           -- 55-63 unused --
116  *           namingViolation              (64),
117  *           objectClassViolation         (65),
118  *           notAllowedOnNonLeaf          (66),
119  *           notAllowedOnRDN              (67),
120  *           entryAlreadyExists           (68),
121  *           objectClassModsProhibited    (69),
122  *           -- 70 reserved for CLDAP --
123  *           affectsMultipleDSAs          (71), -- new
124  *           -- 72-79 unused --
125  *           other                        (80) },
126  *           -- 81-90 reserved for APIs --
127  * </code></pre>
128  * 
129  * All the result codes with the exception of success, compareFalse and
130  * compareTrue are to be treated as meaning the operation could not be completed
131  * in its entirety. Most of the result codes are based on problem indications
132  * from X.511 error data types. Result codes from 16 to 21 indicate an
133  * AttributeProblem, codes 32, 33, 34 and 36 indicate a NameProblem, codes 48,
134  * 49 and 50 indicate a SecurityProblem, codes 51 to 54 indicate a
135  * ServiceProblem, and codes 64 to 69 and 71 indicates an UpdateProblem. If a
136  * client receives a result code which is not listed above, it is to be treated
137  * as an unknown error condition. The majority of this javadoc was pasted in
138  * from RFC 2251. There's and expired draft out there on error codes which makes
139  * alot of sense: <a
140  * href="http://www.alternic.org/drafts/drafts-j-k/draft-just-ldapv3-rescodes-02.html"> 
141  * ietf (expired) draft</a> on error codes (read at your discretion).
142  * Result codes have been identified and split into categories:
143  * <ul>
144  * <li> Non-Erroneous: Five result codes that may be returned in LDAPResult are
145  * not used to indicate an error. </li>
146  * <li> General: returned only when no suitable specific error exists. </li>
147  * <li> Specific: Specific errors are used to indicate that a particular type of
148  * error has occurred. These error types are:
149  * <ul>
150  * <li> Name, </li>
151  * <li> Update, </li>
152  * <li> Attribute </li>
153  * <li> Security, and </li>
154  * <li> Service </li>
155  * </ul>
156  * </li>
157  * </ul>
158  * The result codes are also grouped according to the following LDAP operations
159  * which return responses:
160  * <ul>
161  * <li> bind </li>
162  * <li> search </li>
163  * <li> modify </li>
164  * <li> modifyDn </li>
165  * <li> add </li>
166  * <li> delete </li>
167  * <li> compare </li>
168  * <li> extended </li>
169  * </ul>
170  * 
171  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
172  */
173 public enum ResultCodeEnum
174 {
175     // ------------------------------------------------------------------------
176     // Public Static Constants: Enumeration values and names.
177     // ------------------------------------------------------------------------
178     // ------------------------------------------------------------------------
179     // Non Erroneous Codes:
180     //
181     // Five result codes that may be returned in LDAPResult are not used to
182     // indicate an error. These result codes are listed below. The first
183     // three codes, indicate to the client that no further action is required
184     // in order to satisfy their request. In contrast, the last two errors
185     // require further action by the client in order to complete their original
186     // operation request.
187     // ------------------------------------------------------------------------
188 
189     /**
190      * It is returned when the client operation completed successfully without
191      * errors. This code is one of 5 result codes that may be returned in the
192      * LDAPResult which are not used to indicate an error. Applicable
193      * operations: all except for Compare. Result code type: Non-Erroneous
194      */
195     SUCCESS(0, "success"),
196 
197     /**
198      * Servers sends this result code to LDAP v2 clients to refer them to
199      * another LDAP server. When sending this code to a client, the server
200      * includes a newline-delimited list of LDAP URLs that identify another LDAP
201      * server. If the client identifies itself as an LDAP v3 client in the
202      * request, servers send an REFERRAL result code instead of this result
203      * code.
204      */
205     PARTIAL_RESULTS(9, "partialResults"),
206 
207     /**
208      * It is used to indicate that the result of a Compare operation is FALSE
209      * and does not indicate an error. 1 of 5 codes that do not indicate an
210      * error condition. Applicable operations: Compare. Result code type:
211      * Non-Erroneous
212      */
213     COMPARE_FALSE(5, "compareFalse"),
214 
215     /**
216      * It is used to indicate that the result of a Compare operation is TRUE and
217      * does not indicate an error. 1 of 5 codes that do not indicate an error
218      * condition. Applicable operations: Compare. Result code type:
219      * Non-Erroneous
220      */
221     COMPARE_TRUE(6, "compareTrue"),
222 
223     /**
224      * Rather than indicating an error, this result code is used to indicate
225      * that the server does not hold the target entry of the request but is able
226      * to provide alternative servers that may. A set of server(s) URLs may be
227      * returned in the referral field, which the client may subsequently query
228      * to attempt to complete their operation. 1 of 5 codes that do not indicate
229      * an error condition yet requires further action on behalf of the client to
230      * complete the request. This result code is new in LDAPv3. Applicable
231      * operations: all. Result code type: Non-Erroneous
232      */
233     REFERRAL(10, "referral"),
234 
235     /**
236      * This result code is not an error response from the server, but rather, is
237      * a request for bind continuation. The server requires the client to send a
238      * new bind request, with the same SASL mechanism, to continue the
239      * authentication process [RFC2251, Section 4.2.3]. This result code is new
240      * in LDAPv3. Applicable operations: Bind. Result code type: Non-Erroneous
241      */
242     SASL_BIND_IN_PROGRESS(14, "saslBindInProgress"),
243 
244     // ------------------------------------------------------------------------
245     // Problem Specific Error Codes:
246     //
247     // Specific errors are used to indicate that a particular type of error
248     // has occurred. These error types are Name, Update, Attribute, Security,
249     // and Service.
250     // ------------------------------------------------------------------------
251     // ------------------------------------------------------------------------
252     // Security Problem Specific Error Codes:
253     //
254     // A security error reports a problem in carrying out an operation for
255     // security reasons [X511, Section 12.7].
256     // ------------------------------------------------------------------------
257 
258     /**
259      * This error code should be returned if the client requests, in a Bind
260      * request, an authentication method which is not supported or recognized by
261      * the server. Applicable operations: Bind. Result code type: Specific
262      * (Security)
263      */
264     AUTH_METHOD_NOT_SUPPORTED(7, "authMethodNotSupported"),
265 
266     /**
267      * This error may be returned on a bind request if the server only accepts
268      * strong authentication or it may be returned when a client attempts an
269      * operation which requires the client to be strongly authenticated - for
270      * example Delete. This result code may also be returned in an unsolicited
271      * notice of disconnection if the server detects that an established
272      * underlying security association protecting communication between the
273      * client and server has unexpectedly failed or been compromised. [RFC2251,
274      * Section 4.4.1] Applicable operations: all. Result code type: Specific
275      * (Security)
276      */
277     STRONG_AUTH_REQUIRED(8, "strongAuthRequired"),
278 
279     /**
280      * This error code may be returned if the session is not protected by a
281      * protocol which provides session confidentiality. For example, if the
282      * client did not establish a TLS connection using a cipher suite which
283      * provides confidentiality of the session before sending any other
284      * requests, and the server requires session confidentiality then the server
285      * may reject that request with a result code of confidentialityRequired.
286      * This error code is new in LDAPv3. Applicable operations: all. Result code
287      * type: Specific (Security)
288      */
289     CONFIDENTIALITY_REQUIRED(13, "confidentialityRequired"),
290 
291     /**
292      * An alias was encountered in a situation where it was not allowed or where
293      * access was denied [X511, Section 12.5]. For example, if the client does
294      * not have read permission for the aliasedObjectName attribute and its
295      * value then the error aliasDereferencingProblem should be returned. [X511,
296      * Section 7.11.1.1] Notice that this error has similar meaning to
297      * INSUFFICIENT_ACCESS_RIGHTS (50), but is specific to Searching on an alias.
298      * Applicable operations: Search. Result code type: Specific (Security)
299      */
300     ALIAS_DEREFERENCING_PROBLEM(36, "aliasDereferencingProblem"),
301 
302     /**
303      * This error should be returned by the server when the client has tried to
304      * use a method of authentication that is inappropriate, that is a method of
305      * authentication which the client is unable to use correctly. In other
306      * words, the level of security associated with the requestor's credentials
307      * is inconsistent with the level of protection requested, e.g. simple
308      * credentials were supplied while strong credentials were required [X511,
309      * Section 12.7]. Applicable operations: Bind. Result code type: Specific
310      * (Security)
311      */
312     INAPPROPRIATE_AUTHENTICATION(48, "inappropriateAuthentication"),
313 
314     /**
315      * This error code is returned if the Dn or password used in a simple bind
316      * operation is incorrect, or if the Dn or password is incorrect for some
317      * other reason, e.g. the password has expired. This result code only
318      * applies to Bind operations -- it should not be returned for other
319      * operations if the client does not have sufficient permission to perform
320      * the requested operation - in this case the return code should be
321      * insufficientAccessRights. Applicable operations: Bind. Result code type:
322      * Specific (Security)
323      */
324     INVALID_CREDENTIALS(49, "invalidCredentials"),
325 
326     /**
327      * The requestor does not have the right to carry out the requested
328      * operation [X511, Section 12.7]. Note that the more specific
329      * aliasDereferencingProblem is returned in case of a Search on an alias
330      * where the requestor has insufficientAccessRights. Applicable operations:
331      * all except for Bind. Result code type: Specific (Security)
332      */
333     INSUFFICIENT_ACCESS_RIGHTS(50, "insufficientAccessRights"),
334 
335     // ------------------------------------------------------------------------
336     // Service Problem Specific Error Codes:
337     //
338     // A service error reports a problem related to the provision of the
339     // service [X511, Section 12.8].
340     // ------------------------------------------------------------------------
341 
342     /**
343      * If the server requires that the client bind before browsing or modifying
344      * the directory, the server MAY reject a request other than binding,
345      * unbinding or an extended request with the "operationsError" result.
346      * [RFC2251, Section 4.2.1] Applicable operations: all except Bind. Result
347      * code type: Specific (Service)
348      */
349     OPERATIONS_ERROR(1, "operationsError"),
350 
351     /**
352      * A protocol error should be returned by the server when an invalid or
353      * malformed request is received from the client. This may be a request that
354      * is not recognized as an LDAP request, for example, if a nonexistent
355      * operation were specified in LDAPMessage. As well, it may be the result of
356      * a request that is missing a required parameter, such as a search filter
357      * in a search request. If the server can return an error, which is more
358      * specific than protocolError, then this error should be returned instead.
359      * For example if the server does not recognize the authentication method
360      * requested by the client then the error authMethodNotSupported should be
361      * returned instead of protocolError. The server may return details of the
362      * error in the error string. Applicable operations: all. Result code type:
363      * Specific (Service)
364      */
365     PROTOCOL_ERROR(2, "protocolError"),
366 
367     /**
368      * This error should be returned when the time to perform an operation has
369      * exceeded either the time limit specified by the client (which may only be
370      * set by the client in a search operation) or the limit specified by the
371      * server. If the time limit is exceeded on a search operation then the
372      * result is an arbitrary selection of the accumulated results [X511,
373      * Section 7.5]. Note that an arbitrary selection of results may mean that
374      * no results are returned to the client. If the LDAP server is a front end
375      * for an X.500 server, any operation that is chained may exceed the
376      * timelimit, therefore clients can expect to receive timelimitExceeded for
377      * all operations. For stand alone LDAP- Servers that do not implement
378      * chaining it is unlikely that operations other than search operations will
379      * exceed the defined timelimit. Applicable operations: all. Result code
380      * type: Specific (Service)
381      */
382     TIME_LIMIT_EXCEEDED(3, "timeLimitExceeded"),
383 
384     /**
385      * This error should be returned when the number of results generated by a
386      * search exceeds the maximum number of results specified by either the
387      * client or the server. If the size limit is exceeded then the results of a
388      * search operation will be an arbitrary selection of the accumulated
389      * results, equal in number to the size limit [X511, Section 7.5].
390      * Applicable operations: Search. Result code type: Specific (Service)
391      */
392     SIZE_LIMIT_EXCEEDED(4, "sizeLimitExceeded"),
393 
394     /**
395      * The server has reached some limit set by an administrative authority, and
396      * no partial results are available to return to the user [X511, Section
397      * 12.8]. For example, there may be an administrative limit to the number of
398      * entries a server will check when gathering potential search result
399      * candidates [Net]. This error code is new in LDAPv3. Applicable
400      * operations: all. Result code type: Specific (Service)
401      */
402     ADMIN_LIMIT_EXCEEDED(11, "adminLimitExceeded"),
403 
404     /**
405      * The server was unable to satisfy the request because one or more critical
406      * extensions were not available [X511, Section 12.8]. This error is
407      * returned, for example, when a control submitted with a request is marked
408      * critical but is not recognized by a server or when such a control is not
409      * appropriate for the operation type. [RFC2251 section 4.1.12]. This error
410      * code is new in LDAPv3. Applicable operations: all. Result code type:
411      * Specific (Service)
412      */
413     UNAVAILABLE_CRITICAL_EXTENSION(12, "unavailableCriticalExtension"),
414 
415     /**
416      * This error code may be returned if the server is unable to process the
417      * client's request at this time. This implies that if the client retries
418      * the request shortly the server will be able to process it then.
419      * Applicable operations: all. Result code type: Specific (Service)
420      */
421     BUSY(51, "busy"),
422 
423     /**
424      * This error code is returned when the server is unavailable to process the
425      * client's request. This usually means that the LDAP server is shutting
426      * down [RFC2251, Section 4.2.3]. Applicable operations: all. Result code
427      * type: Specific (Service)
428      */
429     UNAVAILABLE(52, "unavailable"),
430 
431     /**
432      * This error code should be returned by the server when a client request is
433      * properly formed but which the server is unable to complete due to
434      * server-defined restrictions. For example, the server, or some part of it,
435      * is not prepared to execute this request, e.g. because it would lead to
436      * excessive consumption of resources or violates the policy of an
437      * Administrative Authority involved [X511, Section 12.8]. If the server is
438      * able to return a more specific error code such as adminLimitExceeded it
439      * should. This error may also be returned if the client attempts to modify
440      * attributes which can not be modified by users, e.g., operational
441      * attributes such as creatorsName or createTimestamp [X511, Section 7.12].
442      * If appropriate, details of the error should be provided in the error
443      * message. Applicable operations: all. Result code type: Specific (Service)
444      */
445     UNWILLING_TO_PERFORM(53, "unwillingToPerform"),
446 
447     /**
448      * This error may be returned by the server if it detects an alias or
449      * referral loop, and is unable to satisfy the client's request. Applicable
450      * operations: all. Result code type: Specific (Service)
451      */
452     LOOP_DETECT(54, "loopDetect"),
453 
454     // ------------------------------------------------------------------------
455     // Attribute Problem Specific Error Codes:
456     //
457     // An attribute error reports a problem related to an attribute specified
458     // by the client in their request message.
459     // ------------------------------------------------------------------------
460 
461     /**
462      * This error may be returned if the attribute specified as an argument of
463      * the operation does not exist in the entry. Applicable operations: Modify,
464      * Compare. Result code type: Specific (Attribute)
465      */
466     NO_SUCH_ATTRIBUTE(16, "noSuchAttribute"),
467 
468     /**
469      * This error may be returned if the specified attribute is unrecognized by
470      * the server, since it is not present in the server's defined schema. If
471      * the server doesn't recognize an attribute specified in a search request
472      * as the attribute to be returned the server should not return an error in
473      * this case - it should just return values for the requested attributes it
474      * does recognize. Note that this result code only applies to the Add and
475      * Modify operations [X.511, Section 12.4]. Applicable operations: Modify,
476      * Add. Result code type: Specific (Attribute)
477      */
478     UNDEFINED_ATTRIBUTE_TYPE(17, "undefinedAttributeType"),
479 
480     /**
481      * An attempt was made, e.g., in a filter, to use a matching rule not
482      * defined for the attribute type concerned [X511, Section 12.4]. Applicable
483      * operations: Search. Result code type: Specific (Attribute)
484      */
485     INAPPROPRIATE_MATCHING(18, "inappropriateMatching"),
486 
487     /**
488      * This error should be returned by the server if an attribute value
489      * specified by the client violates the constraints placed on the attribute
490      * as it was defined in the DSA - this may be a size constraint or a
491      * constraint on the content. Applicable operations: Modify, Add, ModifyDN.
492      * Result code type: Specific (Attribute)
493      */
494     CONSTRAINT_VIOLATION(19, "constraintViolation"),
495 
496     /**
497      * This error should be returned by the server if the value specified by the
498      * client already exists within the attribute. Applicable operations:
499      * Modify, Add. Result code type: Specific (Attribute)
500      */
501     ATTRIBUTE_OR_VALUE_EXISTS(20, "attributeOrValueExists"),
502 
503     /**
504      * This error should be returned by the server if the attribute syntax for
505      * the attribute value, specified as an argument of the operation, is
506      * unrecognized or invalid. Applicable operations: Modify, Add. Result code
507      * type: Specific (Attribute)
508      */
509     INVALID_ATTRIBUTE_SYNTAX(21, "invalidAttributeSyntax"),
510 
511     // ------------------------------------------------------------------------
512     // Name Problem Specific Error Codes:
513     //
514     // A name error reports a problem related to the distinguished name
515     // provided as an argument to an operation [X511, Section 12.5].
516     //
517     // For result codes of noSuchObject, aliasProblem, invalidDNSyntax and
518     // aliasDereferencingProblem (see Section 5.2.2.3.7), the matchedDN
519     // field is set to the name of the lowest entry (object or alias) in the
520     // directory that was matched. If no aliases were dereferenced while
521     // attempting to locate the entry, this will be a truncated form of the
522     // name provided, or if aliases were dereferenced, of the resulting
523     // name, as defined in section 12.5 of X.511 [X511]. The matchedDN field
524     // is to be set to a zero length string with all other result codes
525     // [RFC2251, Section 4.1.10].
526     // ------------------------------------------------------------------------
527 
528     /**
529      * This error should only be returned if the target object cannot be found.
530      * For example, in a search operation if the search base can not be located
531      * in the DSA the server should return NO_SUCH_OBJECT. If, however, the search
532      * base is found but does not match the search filter, success, with no
533      * resultant objects, should be returned instead of NO_SUCH_OBJECT. If the
534      * LDAP server is a front end for an X.500 DSA then NO_SUCH_OBJECT may also be
535      * returned if discloseOnError is not granted for an entry and the client
536      * does not have permission to view or modify the entry. Applicable
537      * operations: all except for Bind. Result code type: Specific (Name)
538      */
539     NO_SUCH_OBJECT(32, "noSuchObject"),
540 
541     /**
542      * An alias has been dereferenced which names no object [X511, Section 12.5]
543      * Applicable operations: Search. Result code type: Specific (Name)
544      */
545     ALIAS_PROBLEM(33, "aliasProblem"),
546 
547     /**
548      * This error should be returned by the server if the Dn syntax is
549      * incorrect. It should not be returned if the Dn is correctly formed but
550      * represents an entry which is not permitted by the structure rules at the
551      * DSA ; in this case namingViolation should be returned instead. Applicable
552      * operations: all. Result code type: Specific (Name)
553      */
554     INVALID_DN_SYNTAX(34, "invalidDNSyntax"),
555 
556     // ------------------------------------------------------------------------
557     // Update Problem Specific Error Codes:
558     //
559     // An update error reports problems related to attempts to add, delete, or
560     // modify information in the DIB [X511, Section 12.9].
561     // ------------------------------------------------------------------------
562 
563     /**
564      * The attempted addition or modification would violate the structure rules
565      * of the DIT as defined in the directory schema and X.501. That is, it
566      * would place an entry as the subordinate of an alias entry, or in a region
567      * of the DIT not permitted to a member of its object class, or would define
568      * an Rdn for an entry to include a forbidden attribute type [X511, Section
569      * 12.9]. Applicable operations: Add, ModifyDN. Result code type: Specific
570      * (Update)
571      */
572     NAMING_VIOLATION(64, "namingViolation"),
573 
574     /**
575      * This error should be returned if the operation requested by the user
576      * would violate the objectClass requirements for the entry if carried out.
577      * On an add or modify operation this would result from trying to add an
578      * object class without a required attribute, or by trying to add an
579      * attribute which is not permitted by the current object class set in the
580      * entry. On a modify operation this may result from trying to remove a
581      * required attribute without removing the associated auxiliary object
582      * class, or by attempting to remove an object class while the attributes it
583      * permits are still present. Applicable operations: Add, Modify, ModifyDN.
584      * Result code type: Specific (Update)
585      */
586     OBJECT_CLASS_VIOLATION(65, "objectClassViolation"),
587 
588     /**
589      * This error should be returned if the client attempts to perform an
590      * operation which is permitted only on leaf entries - e.g., if the client
591      * attempts to delete a non-leaf entry. If the directory does not permit
592      * ModifyDN for non-leaf entries then this error may be returned if the
593      * client attempts to change the Dn of a non-leaf entry. (Note that 1988
594      * edition X.500 servers only permitted change of the Rdn of an entry's Dn
595      * [X.511, Section 11.4.1]). Applicable operations: Delete, ModifyDN. Result
596      * code type: Specific (Update)
597      */
598     NOT_ALLOWED_ON_NON_LEAF(66, "notAllowedOnNonLeaf"),
599 
600     /**
601      * The attempted operation would affect the Rdn (e.g., removal of an
602      * attribute which is a part of the Rdn) [X511, Section 12.9]. If the client
603      * attempts to remove from an entry any of its distinguished values, those
604      * values which form the entry's relative distinguished name the server
605      * should return the error notAllowedOnRDN. [RFC2251, Section 4.6]
606      * Applicable operations: Modify. Result code type: Specific (Update)
607      */
608     NOT_ALLOWED_ON_RDN(67, "notAllowedOnRDN"),
609 
610     /**
611      * This error should be returned by the server when the client attempts to
612      * add an entry which already exists, or if the client attempts to rename an
613      * entry with the name of an entry which exists. Applicable operations: Add,
614      * ModifyDN. Result code type: Specific (Update)
615      */
616     ENTRY_ALREADY_EXISTS(68, "entryAlreadyExists"),
617 
618     /**
619      * An operation attempted to modify an object class that should not be
620      * modified, e.g., the structural object class of an entry. Some servers may
621      * not permit object class modifications, especially modifications to the
622      * structural object class since this may change the entry entirely, name
623      * forms, structure rules etc. [X.511, Section 12.9]. Applicable operations:
624      * Modify. Result code type: Specific (Update)
625      */
626     OBJECT_CLASS_MODS_PROHIBITED(69, "objectClassModsProhibited"),
627 
628     /**
629      * This error code should be returned to indicate that the operation could
630      * not be performed since it affects more than one DSA. This error code is
631      * new for LDAPv3. X.500 restricts the ModifyDN operation to only affect
632      * entries that are contained within a single server. If the LDAP server is
633      * mapped onto DAP, then this restriction will apply, and the resultCode
634      * affectsMultipleDSAs will be returned if this error occurred. In general
635      * clients MUST NOT expect to be able to perform arbitrary movements of
636      * entries and subtrees between servers [RFC2251, Section 4.9]. Applicable
637      * operations: ModifyDN. Result code type: Specific (Update)
638      */
639     AFFECTS_MULTIPLE_DSAS(71, "affectsMultipleDSAs"),
640 
641     // ------------------------------------------------------------------------
642     // General Error Codes:
643     //
644     // A general error code typically specifies an error condition for which
645     // there is no suitable specific error code. If the server can return an
646     // error, which is more specific than the following general errors, then
647     // the specific error should be returned instead.
648     // ------------------------------------------------------------------------
649 
650     /**
651      * This error code should be returned only if no other error code is
652      * suitable. Use of this error code should be avoided if possible. Details
653      * of the error should be provided in the error message. Applicable
654      * operations: all. Result code type: General
655      */
656     OTHER(80, "other"),
657 
658     /**
659      * This error code is returned when an operation has been canceled using
660      * the Cancel extended operation. 
661      */
662     CANCELED(118, "canceled"),
663 
664     /**
665      * This error code is returned if the server has no knowledge of
666      * the operation requested for cancelation.
667      */
668     NO_SUCH_OPERATION(119, "noSuchOperation"),
669 
670     /**
671      * The tooLate resultCode is returned to indicate that it is too late to
672      * cancel the outstanding operation.  For example, the server may return
673      * tooLate for a request to cancel an outstanding modify operation which
674      * has already committed updates to the underlying data store.
675      */
676     TOO_LATE(120, "tooLate"),
677 
678     /**
679      * The cannotCancel resultCode is returned if the identified operation
680      * does not support cancelation or the cancel operation could not be
681      * performed.  The following classes of operations are not cancelable:
682      *
683      * -  operations which have no response,
684      *
685      * -  operations which create, alter, or destroy authentication and/or
686      *    authorization associations,
687      *
688      * -  operations which establish, alter, or tear-down security services,
689      *    and
690      *
691      * -  operations which abandon or cancel other operations.
692      */
693     CANNOT_CANCEL(121, "cannotCancel"),
694 
695     /**
696      * The server may return this result code on the initial content poll
697      * if it is safe to do so when it is unable to perform the operation
698      * due to various reasons. For more detailed explanation refer 
699      * <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533 (a.k.a syncrepl)</a>
700      */
701     E_SYNC_REFRESH_REQUIRED(4096, "eSyncRefreshRequired"),
702 
703     /**
704      * A unknown result code to cover all the other cases
705      */
706     // -- 15 unused --
707     // -- 22-31 unused --
708     // -- 35 reserved for undefined isLeaf --
709     // -- 37-47 unused --
710     // -- 55-63 unused --
711     // -- 70 reserved for CLDAP --
712     // -- 72-79 unused --
713     // -- 81-90 reserved for APIs --
714     UNKNOWN(122, "unknown");
715 
716     /** Stores the integer value of each element of the enumeration */
717     private int value;
718 
719     /** Stores the description of each element of the enumeration */
720     private String message;
721 
722     private static final Set<ResultCodeEnum> EMPTY_RESULT_CODE_SET = new HashSet<>();
723 
724     // ------------------------------------------------------------------------
725     // Error Codes Grouped Into Categories & Static Accessors
726     // ------------------------------------------------------------------------
727 
728     /**
729      * Five result codes that may be returned in LDAPResult are not used to
730      * indicate an error. The first three codes, indicate to the client that no
731      * further action is required in order to satisfy their request. In
732      * contrast, the last two errors require further action by the client in
733      * order to complete their original operation request. The set contains:
734      * <ul>
735      * <li><a href="#SUCCESS">SUCCESS</a></li>
736      * <li><a href="#COMPARETRUE">COMPARETRUE</a></li>
737      * <li><a href="#COMPAREFALSE">COMPAREFALSE</a></li>
738      * <li><a href="#REFERRAL">REFERRAL</a></li>
739      * <li><a href="#SASL_BIND_IN_PROGRESS">SASL_BIND_IN_PROGRESS</a></li>
740      * </ul>
741      */
742     private static final Set<ResultCodeEnum> NON_ERRONEOUS_CODES;
743 
744     static
745     {
746         Set<ResultCodeEnum> set = new HashSet<>();
747         set.add( ResultCodeEnum.SUCCESS );
748         set.add( ResultCodeEnum.COMPARE_TRUE );
749         set.add( ResultCodeEnum.COMPARE_FALSE );
750         set.add( ResultCodeEnum.REFERRAL );
751         set.add( ResultCodeEnum.SASL_BIND_IN_PROGRESS );
752         set.add( ResultCodeEnum.CANCELED );
753         NON_ERRONEOUS_CODES = Collections.unmodifiableSet( set );
754     }
755 
756     /**
757      * A set of result code enumerations that may result from bind operations.
758      * The set contains:
759      * <ul>
760      * <li><a href="#BUSY">BUSY</a></li>
761      * <li><a href="#OTHER">OTHER</a></li>
762      * <li><a href="#SUCCESS">SUCCESS</a></li>
763      * <li><a href="#REFERRAL">REFERRAL</a></li>
764      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
765      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
766      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
767      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
768      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
769      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
770      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
771      * <li><a href="#SASL_BIND_IN_PROGRESS">SASL_BIND_IN_PROGRESS</a></li>
772      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
773      * <li><a href="#INVALID_CREDENTIALS">INVALID_CREDENTIALS</a></li>
774      * <li><a href="#AUTH_METHOD_NOT_SUPPORTED">AUTH_METHOD_NOT_SUPPORTED</a></li>
775      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
776      * <li><a href="#INAPPROPRIATE_AUTHENTICATION">INAPPROPRIATE_AUTHENTICATION</a></li>
777      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
778      * </ul>
779      */
780     private static final Set<ResultCodeEnum> BIND_CODES;
781 
782     static
783     {
784         Set<ResultCodeEnum> set = new HashSet<>();
785         set.add( ResultCodeEnum.BUSY );
786         set.add( ResultCodeEnum.OTHER );
787         set.add( ResultCodeEnum.SUCCESS );
788         set.add( ResultCodeEnum.REFERRAL );
789         set.add( ResultCodeEnum.LOOP_DETECT );
790         set.add( ResultCodeEnum.UNAVAILABLE );
791         set.add( ResultCodeEnum.PROTOCOL_ERROR );
792         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
793         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
794         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
795         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
796         set.add( ResultCodeEnum.SASL_BIND_IN_PROGRESS );
797         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
798         set.add( ResultCodeEnum.INVALID_CREDENTIALS );
799         set.add( ResultCodeEnum.AUTH_METHOD_NOT_SUPPORTED );
800         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
801         set.add( ResultCodeEnum.INAPPROPRIATE_AUTHENTICATION );
802         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
803         set.add( ResultCodeEnum.CANCELED );
804         BIND_CODES = Collections.unmodifiableSet( set );
805     }
806 
807     /**
808      * A set of result code enumerations that may result from search operations.
809      * The set contains:
810      * <ul>
811      * <li><a href="#BUSY">BUSY</a></li>
812      * <li><a href="#OTHER">OTHER</a></li>
813      * <li><a href="#SUCCESS">SUCCESS</a></li>
814      * <li><a href="#REFERRAL">REFERRAL</a></li>
815      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
816      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
817      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
818      * <li><a href="#ALIAS_PROBLEM">ALIAS_PROBLEM</a></li>
819      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
820      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
821      * <li><a href="#SIZE_LIMIT_EXCEEDED">SIZE_LIMIT_EXCEEDED</a></li>
822      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
823      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
824      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
825      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
826      * <li><a href="#INAPPROPRIATE_MATCHING">INAPPROPRIATE_MATCHING</a></li>
827      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
828      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
829      * <li><a href="#ALIAS_DEREFERENCING_PROBLEM">ALIAS_DEREFERENCING_PROBLEM</a></li>
830      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
831      * </ul>
832      */
833     private static final Set<ResultCodeEnum> SEARCH_CODES;
834 
835     static
836     {
837         Set<ResultCodeEnum> set = new HashSet<>();
838         set.add( ResultCodeEnum.BUSY );
839         set.add( ResultCodeEnum.OTHER );
840         set.add( ResultCodeEnum.SUCCESS );
841         set.add( ResultCodeEnum.REFERRAL );
842         set.add( ResultCodeEnum.LOOP_DETECT );
843         set.add( ResultCodeEnum.UNAVAILABLE );
844         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
845         set.add( ResultCodeEnum.ALIAS_PROBLEM );
846         set.add( ResultCodeEnum.PROTOCOL_ERROR );
847         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
848         set.add( ResultCodeEnum.SIZE_LIMIT_EXCEEDED );
849         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
850         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
851         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
852         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
853         set.add( ResultCodeEnum.INAPPROPRIATE_MATCHING );
854         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
855         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
856         set.add( ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM );
857         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
858         set.add( ResultCodeEnum.CANCELED );
859         set.add( ResultCodeEnum.E_SYNC_REFRESH_REQUIRED );
860         SEARCH_CODES = Collections.unmodifiableSet( set );
861     }
862 
863     /**
864      * A set of result code enumerations that may result from modify operations.
865      * The set contains:
866      * <ul>
867      * <li><a href="#BUSY">BUSY</a></li>
868      * <li><a href="#OTHER">OTHER</a></li>
869      * <li><a href="#SUCCESS">SUCCESS</a></li>
870      * <li><a href="#REFERRAL">REFERRAL</a></li>
871      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
872      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
873      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
874      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
875      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
876      * <li><a href="#NOT_ALLOWED_ON_RDN">NOT_ALLOWED_ON_RDN</a></li>
877      * <li><a href="#NO_SUCH_ATTRIBUTE">NO_SUCH_ATTRIBUTE</a></li>
878      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
879      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
880      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
881      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
882      * <li><a href="#CONSTRAINT_VIOLATION">CONSTRAINT_VIOLATION</a></li>
883      * <li><a href="#OBJECT_CLASS_VIOLATION">OBJECT_CLASS_VIOLATION</a></li>
884      * <li><a href="#INVALID_ATTRIBUTE_SYNTAX">INVALID_ATTRIBUTE_SYNTAX</a></li>
885      * <li><a href="#UNDEFINED_ATTRIBUTE_TYPE">UNDEFINED_ATTRIBUTE_TYPE</a></li>
886      * <li><a href="#ATTRIBUTE_OR_VALUE_EXISTS">ATTRIBUTE_OR_VALUE_EXISTS</a></li>
887      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
888      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
889      * <li><a href="#OBJECT_CLASS_MODS_PROHIBITED">OBJECT_CLASS_MODS_PROHIBITED</a></li>
890      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
891      * </ul>
892      */
893     private static final Set<ResultCodeEnum> MODIFY_CODES;
894 
895     static
896     {
897         Set<ResultCodeEnum> set = new HashSet<>();
898         set.add( ResultCodeEnum.BUSY );
899         set.add( ResultCodeEnum.OTHER );
900         set.add( ResultCodeEnum.SUCCESS );
901         set.add( ResultCodeEnum.REFERRAL );
902         set.add( ResultCodeEnum.LOOP_DETECT );
903         set.add( ResultCodeEnum.UNAVAILABLE );
904         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
905         set.add( ResultCodeEnum.PROTOCOL_ERROR );
906         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
907         set.add( ResultCodeEnum.NOT_ALLOWED_ON_RDN );
908         set.add( ResultCodeEnum.NO_SUCH_ATTRIBUTE );
909         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
910         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
911         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
912         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
913         set.add( ResultCodeEnum.CONSTRAINT_VIOLATION );
914         set.add( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
915         set.add( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
916         set.add( ResultCodeEnum.UNDEFINED_ATTRIBUTE_TYPE );
917         set.add( ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS );
918         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
919         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
920         set.add( ResultCodeEnum.OBJECT_CLASS_MODS_PROHIBITED );
921         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
922         set.add( ResultCodeEnum.CANCELED );
923         MODIFY_CODES = Collections.unmodifiableSet( set );
924     }
925 
926     /**
927      * A set of result code enumerations that may result from add operations.
928      * The set contains:
929      * <ul>
930      * <li><a href="#BUSY">BUSY</a></li>
931      * <li><a href="#OTHER">OTHER</a></li>
932      * <li><a href="#SUCCESS">SUCCESS</a></li>
933      * <li><a href="#REFERRAL">REFERRAL</a></li>
934      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
935      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
936      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
937      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
938      * <li><a href="#NAMING_VIOLATION">NAMING_VIOLATION</a></li>
939      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
940      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
941      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
942      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
943      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
944      * <li><a href="#ENTRY_ALREADY_EXISTS">ENTRY_ALREADY_EXISTS</a></li>
945      * <li><a href="#CONSTRAINT_VIOLATION">CONSTRAINT_VIOLATION</a></li>
946      * <li><a href="#OBJECT_CLASS_VIOLATION">OBJECT_CLASS_VIOLATION</a></li>
947      * <li><a href="#INVALID_ATTRIBUTE_SYNTAX">INVALID_ATTRIBUTE_SYNTAX</a></li>
948      * <li><a href="#ATTRIBUTE_OR_VALUE_EXISTS">ATTRIBUTE_OR_VALUE_EXISTS</a></li>
949      * <li><a href="#UNDEFINED_ATTRIBUTE_TYPE">UNDEFINED_ATTRIBUTE_TYPE</a></li>
950      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
951      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
952      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
953      * </ul>
954      */
955     private static final Set<ResultCodeEnum> ADD_CODES;
956 
957     static
958     {
959         Set<ResultCodeEnum> set = new HashSet<>();
960         set.add( ResultCodeEnum.BUSY );
961         set.add( ResultCodeEnum.OTHER );
962         set.add( ResultCodeEnum.SUCCESS );
963         set.add( ResultCodeEnum.REFERRAL );
964         set.add( ResultCodeEnum.LOOP_DETECT );
965         set.add( ResultCodeEnum.UNAVAILABLE );
966         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
967         set.add( ResultCodeEnum.PROTOCOL_ERROR );
968         set.add( ResultCodeEnum.NAMING_VIOLATION );
969         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
970         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
971         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
972         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
973         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
974         set.add( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
975         set.add( ResultCodeEnum.CONSTRAINT_VIOLATION );
976         set.add( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
977         set.add( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
978         set.add( ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS );
979         set.add( ResultCodeEnum.UNDEFINED_ATTRIBUTE_TYPE );
980         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
981         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
982         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
983         set.add( ResultCodeEnum.CANCELED );
984         ADD_CODES = Collections.unmodifiableSet( set );
985     }
986 
987     /**
988      * A set of result code enumerations that may result from delete operations.
989      * The set may contain:
990      * <ul>
991      * <li><a href="#BUSY">BUSY</a></li>
992      * <li><a href="#OTHER">OTHER</a></li>
993      * <li><a href="#SUCCESS">SUCCESS</a></li>
994      * <li><a href="#REFERRAL">REFERRAL</a></li>
995      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
996      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
997      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
998      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
999      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
1000      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
1001      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
1002      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
1003      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
1004      * <li><a href="#NOT_ALLOWED_ON_NON_LEAF">NOT_ALLOWED_ON_NON_LEAF</a></li>
1005      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
1006      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
1007      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
1008      * </ul>
1009      */
1010     private static final Set<ResultCodeEnum> DELETE_CODES;
1011 
1012     static
1013     {
1014         Set<ResultCodeEnum> set = new HashSet<>();
1015         set.add( ResultCodeEnum.BUSY );
1016         set.add( ResultCodeEnum.OTHER );
1017         set.add( ResultCodeEnum.SUCCESS );
1018         set.add( ResultCodeEnum.REFERRAL );
1019         set.add( ResultCodeEnum.LOOP_DETECT );
1020         set.add( ResultCodeEnum.UNAVAILABLE );
1021         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
1022         set.add( ResultCodeEnum.PROTOCOL_ERROR );
1023         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
1024         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
1025         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
1026         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
1027         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
1028         set.add( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF );
1029         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
1030         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
1031         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
1032         set.add( ResultCodeEnum.CANCELED );
1033         DELETE_CODES = Collections.unmodifiableSet( set );
1034     }
1035 
1036     /**
1037      * A set of result code enumerations resulting from modifyDn operations. The
1038      * set contains:
1039      * <ul>
1040      * <li><a href="#BUSY">BUSY</a></li>
1041      * <li><a href="#OTHER">OTHER</a></li>
1042      * <li><a href="#SUCCESS">SUCCESS</a></li>
1043      * <li><a href="#REFERRAL">REFERRAL</a></li>
1044      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
1045      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
1046      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
1047      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
1048      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
1049      * <li><a href="#NAMING_VIOLATION">NAMING_VIOLATION</a></li>
1050      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
1051      * <li><a href="#ENTRY_ALREADY_EXISTS">ENTRY_ALREADY_EXISTS</a></li>
1052      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
1053      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
1054      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
1055      * <li><a href="#NOT_ALLOWED_ON_NON_LEAF">NOT_ALLOWED_ON_NON_LEAF</a></li>
1056      * <li><a href="#AFFECTS_MULTIPLE_DSAS">AFFECTS_MULTIPLE_DSAS</a></li>
1057      * <li><a href="#CONSTRAINT_VIOLATION">CONSTRAINT_VIOLATION</a></li>
1058      * <li><a href="#OBJECT_CLASS_VIOLATION">OBJECT_CLASS_VIOLATION</a></li>
1059      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
1060      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
1061      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
1062      * </ul>
1063      */
1064     private static final Set<ResultCodeEnum> MODIFYDN_CODES;
1065 
1066     static
1067     {
1068         Set<ResultCodeEnum> set = new HashSet<>();
1069         set.add( ResultCodeEnum.BUSY );
1070         set.add( ResultCodeEnum.OTHER );
1071         set.add( ResultCodeEnum.SUCCESS );
1072         set.add( ResultCodeEnum.REFERRAL );
1073         set.add( ResultCodeEnum.LOOP_DETECT );
1074         set.add( ResultCodeEnum.UNAVAILABLE );
1075         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
1076         set.add( ResultCodeEnum.PROTOCOL_ERROR );
1077         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
1078         set.add( ResultCodeEnum.NAMING_VIOLATION );
1079         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
1080         set.add( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
1081         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
1082         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
1083         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
1084         set.add( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF );
1085         set.add( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
1086         set.add( ResultCodeEnum.CONSTRAINT_VIOLATION );
1087         set.add( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
1088         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
1089         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
1090         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
1091         set.add( ResultCodeEnum.CANCELED );
1092         MODIFYDN_CODES = Collections.unmodifiableSet( set );
1093     }
1094 
1095     /**
1096      * A set of result code enumerations that may result from compare
1097      * operations. The set contains:
1098      * <ul>
1099      * <li><a href="#OPERATIONSERROR">OPERATIONSERROR</a></li>
1100      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
1101      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
1102      * <li><a href="#COMPAREFALSE">COMPAREFALSE</a></li>
1103      * <li><a href="#COMPARETRUE">COMPARETRUE</a></li>
1104      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
1105      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
1106      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
1107      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
1108      * <li><a href="#NO_SUCH_ATTRIBUTE">NO_SUCH_ATTRIBUTE</a></li>
1109      * <li><a href="#INVALID_ATTRIBUTE_SYNTAX">INVALID_ATTRIBUTE_SYNTAX</a></li>
1110      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
1111      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
1112      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
1113      * <li><a href="#BUSY">BUSY</a></li>
1114      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
1115      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
1116      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
1117      * <li><a href="#REFERRAL">REFERRAL</a></li>
1118      * <li><a href="#OTHER">OTHER</a></li>
1119      * </ul>
1120      */
1121     private static final Set<ResultCodeEnum> COMPARE_CODES;
1122 
1123     static
1124     {
1125         Set<ResultCodeEnum> set = new HashSet<>();
1126         set.add( ResultCodeEnum.OPERATIONS_ERROR );
1127         set.add( ResultCodeEnum.PROTOCOL_ERROR );
1128         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
1129         set.add( ResultCodeEnum.COMPARE_FALSE );
1130         set.add( ResultCodeEnum.COMPARE_TRUE );
1131         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
1132         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
1133         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
1134         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
1135         set.add( ResultCodeEnum.NO_SUCH_ATTRIBUTE );
1136         set.add( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
1137         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
1138         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
1139         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
1140         set.add( ResultCodeEnum.BUSY );
1141         set.add( ResultCodeEnum.UNAVAILABLE );
1142         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
1143         set.add( ResultCodeEnum.LOOP_DETECT );
1144         set.add( ResultCodeEnum.REFERRAL );
1145         set.add( ResultCodeEnum.OTHER );
1146         set.add( ResultCodeEnum.CANCELED );
1147         COMPARE_CODES = Collections.unmodifiableSet( set );
1148     }
1149 
1150     /**
1151      * A set of result code enumerations that could result from extended
1152      * operations. The set contains:
1153      * <ul>
1154      * <li></li>
1155      * <li><a href="#SUCCESS">SUCCESS</a></li>
1156      * <li><a href="#OPERATIONSERROR">OPERATIONSERROR</a></li>
1157      * <li><a href="#PROTOCOL_ERROR">PROTOCOL_ERROR</a></li>
1158      * <li><a href="#TIME_LIMIT_EXCEEDED">TIME_LIMIT_EXCEEDED</a></li>
1159      * <li><a href="#SIZE_LIMIT_EXCEEDED">SIZE_LIMIT_EXCEEDED</a></li>
1160      * <li><a href="#COMPAREFALSE">COMPAREFALSE</a></li>
1161      * <li><a href="#COMPARETRUE">COMPARETRUE</a></li>
1162      * <li><a href="#AUTH_METHOD_NOT_SUPPORTED">AUTH_METHOD_NOT_SUPPORTED</a></li>
1163      * <li><a href="#STRONG_AUTH_REQUIRED">STRONG_AUTH_REQUIRED</a></li>
1164      * <li><a href="#REFERRAL">REFERRAL</a></li>
1165      * <li><a href="#ADMIN_LIMIT_EXCEEDED">ADMIN_LIMIT_EXCEEDED</a></li>
1166      * <li><a href="#UNAVAILABLE_CRITICAL_EXTENSION">UNAVAILABLE_CRITICAL_EXTENSION</a></li>
1167      * <li><a href="#CONFIDENTIALITY_REQUIRED">CONFIDENTIALITY_REQUIRED</a></li>
1168      * <li><a href="#SASL_BIND_IN_PROGRESS">SASL_BIND_IN_PROGRESS</a></li>
1169      * <li><a href="#NO_SUCH_ATTRIBUTE">NO_SUCH_ATTRIBUTE</a></li>
1170      * <li><a href="#UNDEFINED_ATTRIBUTE_TYPE">UNDEFINED_ATTRIBUTE_TYPE</a></li>
1171      * <li><a href="#INAPPROPRIATE_MATCHING">INAPPROPRIATE_MATCHING</a></li>
1172      * <li><a href="#CONSTRAINT_VIOLATION">CONSTRAINT_VIOLATION</a></li>
1173      * <li><a href="#ATTRIBUTE_OR_VALUE_EXISTS">ATTRIBUTE_OR_VALUE_EXISTS</a></li>
1174      * <li><a href="#INVALID_ATTRIBUTE_SYNTAX">INVALID_ATTRIBUTE_SYNTAX</a></li>
1175      * <li><a href="#NO_SUCH_OBJECT">NO_SUCH_OBJECT</a></li>
1176      * <li><a href="#ALIAS_PROBLEM">ALIAS_PROBLEM</a></li>
1177      * <li><a href="#INVALID_DN_SYNTAX">INVALID_DN_SYNTAX</a></li>
1178      * <li><a href="#ALIAS_DEREFERENCING_PROBLEM">ALIAS_DEREFERENCING_PROBLEM</a></li>
1179      * <li><a href="#INAPPROPRIATE_AUTHENTICATION">INAPPROPRIATE_AUTHENTICATION</a></li>
1180      * <li><a href="#INVALID_CREDENTIALS">INVALID_CREDENTIALS</a></li>
1181      * <li><a href="#INSUFFICIENT_ACCESS_RIGHTS">INSUFFICIENT_ACCESS_RIGHTS</a></li>
1182      * <li><a href="#BUSY">BUSY</a></li>
1183      * <li><a href="#UNAVAILABLE">UNAVAILABLE</a></li>
1184      * <li><a href="#UNWILLING_TO_PERFORM">UNWILLING_TO_PERFORM</a></li>
1185      * <li><a href="#LOOP_DETECT">LOOP_DETECT</a></li>
1186      * <li><a href="#NAMING_VIOLATION">NAMING_VIOLATION</a></li>
1187      * <li><a href="#OBJECT_CLASS_VIOLATION">OBJECT_CLASS_VIOLATION</a></li>
1188      * <li><a href="#NOT_ALLOWED_ON_NON_LEAF">NOT_ALLOWED_ON_NON_LEAF</a></li>
1189      * <li><a href="#NOT_ALLOWED_ON_RDN">NOT_ALLOWED_ON_RDN</a></li>
1190      * <li><a href="#ENTRY_ALREADY_EXISTS">ENTRY_ALREADY_EXISTS</a></li>
1191      * <li><a href="#OBJECT_CLASS_MODS_PROHIBITED">OBJECT_CLASS_MODS_PROHIBITED</a></li>
1192      * <li><a href="#AFFECTS_MULTIPLE_DSAS">AFFECTS_MULTIPLE_DSAS</a></li>
1193      * <li><a href="#OTHER">OTHER</a></li>
1194      * </ul>
1195      */
1196     private static final Set<ResultCodeEnum> EXTENDED_CODES;
1197 
1198     static
1199     {
1200         Set<ResultCodeEnum> set = new HashSet<>();
1201         set.add( ResultCodeEnum.SUCCESS );
1202         set.add( ResultCodeEnum.OPERATIONS_ERROR );
1203         set.add( ResultCodeEnum.PROTOCOL_ERROR );
1204         set.add( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
1205         set.add( ResultCodeEnum.SIZE_LIMIT_EXCEEDED );
1206         set.add( ResultCodeEnum.COMPARE_FALSE );
1207         set.add( ResultCodeEnum.COMPARE_TRUE );
1208         set.add( ResultCodeEnum.AUTH_METHOD_NOT_SUPPORTED );
1209         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
1210         set.add( ResultCodeEnum.REFERRAL );
1211         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
1212         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
1213         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
1214         set.add( ResultCodeEnum.SASL_BIND_IN_PROGRESS );
1215         set.add( ResultCodeEnum.NO_SUCH_ATTRIBUTE );
1216         set.add( ResultCodeEnum.UNDEFINED_ATTRIBUTE_TYPE );
1217         set.add( ResultCodeEnum.INAPPROPRIATE_MATCHING );
1218         set.add( ResultCodeEnum.CONSTRAINT_VIOLATION );
1219         set.add( ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS );
1220         set.add( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
1221         set.add( ResultCodeEnum.NO_SUCH_OBJECT );
1222         set.add( ResultCodeEnum.ALIAS_PROBLEM );
1223         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
1224         set.add( ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM );
1225         set.add( ResultCodeEnum.INAPPROPRIATE_AUTHENTICATION );
1226         set.add( ResultCodeEnum.INVALID_CREDENTIALS );
1227         set.add( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
1228         set.add( ResultCodeEnum.BUSY );
1229         set.add( ResultCodeEnum.UNAVAILABLE );
1230         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
1231         set.add( ResultCodeEnum.LOOP_DETECT );
1232         set.add( ResultCodeEnum.NAMING_VIOLATION );
1233         set.add( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
1234         set.add( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF );
1235         set.add( ResultCodeEnum.NOT_ALLOWED_ON_RDN );
1236         set.add( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
1237         set.add( ResultCodeEnum.OBJECT_CLASS_MODS_PROHIBITED );
1238         set.add( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
1239         set.add( ResultCodeEnum.OTHER );
1240         set.add( ResultCodeEnum.CANCELED );
1241         EXTENDED_CODES = Collections.unmodifiableSet( set );
1242     }
1243     // ------------------------------------------------------------------------
1244     // Getting Result Code Enumeration Object Using Integer Values
1245     // ------------------------------------------------------------------------
1246     // ------------------------------------------------------------------------
1247     // JNDI Exception to ResultCodeEnum Mappings
1248     // ------------------------------------------------------------------------
1249 
1250     /**
1251      * A set of ResultCodes containing those that may correspond to NamingException.
1252      * <ul>
1253      * <li><a href="#OPERATIONSERROR">operationsError(1)</a></li>
1254      * <li><a href="#ALIAS_PROBLEM">aliasProblem(33)</a></li>
1255      * <li><a href="#ALIAS_DEREFERENCING_PROBLEM">aliasDereferencingProblem(36)</a></li>
1256      * <li><a href="#LOOP_DETECT">loopDetect(54)</a></li>
1257      * <li><a href="#AFFECTS_MULTIPLE_DSAS">affectsMultipleDSAs(71)</a></li>
1258      * <li><a href="#OTHER">other(80)</a></li>
1259      * </ul>
1260      */
1261     private static final Set<ResultCodeEnum> NAMING_EXCEPTION_CODES;
1262 
1263     static
1264     {
1265         Set<ResultCodeEnum> set = new HashSet<>();
1266         set.add( ResultCodeEnum.OPERATIONS_ERROR );
1267         set.add( ResultCodeEnum.ALIAS_PROBLEM );
1268         set.add( ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM );
1269         set.add( ResultCodeEnum.LOOP_DETECT );
1270         set.add( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
1271         set.add( ResultCodeEnum.OTHER );
1272         NAMING_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1273     }
1274 
1275     /**
1276      * A set of ResultCodes containing those that may correspond to a
1277      * {@link Exception}.
1278      * <ul>
1279      * <li><a href="#AUTH_METHOD_NOT_SUPPORTED">authMethodNotSupported(7)</a></li>
1280      * <li><a href="#STRONG_AUTH_REQUIRED">strongAuthRequired(8)</a></li>
1281      * <li><a href="#CONFIDENTIALITY_REQUIRED">confidentialityRequired(13)</a></li>
1282      * <li><a
1283      * href="#INAPPROPRIATE_AUTHENTICATION">inappropriateAuthentication(48)</a></li>
1284      * </ul>
1285      */
1286     private static final Set<ResultCodeEnum> AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_CODES;
1287 
1288     static
1289     {
1290         Set<ResultCodeEnum> set = new HashSet<>();
1291         set.add( ResultCodeEnum.AUTH_METHOD_NOT_SUPPORTED );
1292         set.add( ResultCodeEnum.STRONG_AUTH_REQUIRED );
1293         set.add( ResultCodeEnum.CONFIDENTIALITY_REQUIRED );
1294         set.add( ResultCodeEnum.INAPPROPRIATE_AUTHENTICATION );
1295         AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1296     }
1297 
1298     /**
1299      * A set of ResultCodes containing those that may correspond to a
1300      * {@link Exception}.
1301      * <ul>
1302      * <li><a href="#BUSY">busy(51)</a></li>
1303      * <li><a href="#UNAVAILABLE">unavailable(52)</a></li>
1304      * </ul>
1305      */
1306     private static final Set<ResultCodeEnum> SERVICE_UNAVAILABLE_CODES;
1307 
1308     static
1309     {
1310         Set<ResultCodeEnum> set = new HashSet<>();
1311         set.add( ResultCodeEnum.BUSY );
1312         set.add( ResultCodeEnum.UNAVAILABLE );
1313         SERVICE_UNAVAILABLE_CODES = Collections.unmodifiableSet( set );
1314     }
1315 
1316     /**
1317      * A set of ResultCodes containing those that may correspond to a
1318      * {@link Exception}.
1319      * <ul>
1320      * <li><a href="#CONSTRAINT_VIOLATION">constraintViolation(19)</a></li>
1321      * <li><a href="#INVALID_ATTRIBUTE_SYNTAX">invalidAttributeSyntax(21)</a></li>
1322      * </ul>
1323      */
1324     private static final Set<ResultCodeEnum> INVALID_ATTRIBUTE_VALUE_EXCEPTION_CODES;
1325 
1326     static
1327     {
1328         Set<ResultCodeEnum> set = new HashSet<>();
1329         set.add( ResultCodeEnum.CONSTRAINT_VIOLATION );
1330         set.add( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
1331         INVALID_ATTRIBUTE_VALUE_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1332     }
1333 
1334     
1335     /**
1336      * A set of ResultCodes containing those that may correspond to a
1337      * {@link Exception}.
1338      * <ul>
1339      * <li><a href="#PARTIAL_RESULTS">partialResults(9)</a></li>
1340      * <li><a href="#REFERRAL">referral(10)</a></li>
1341      * </ul>
1342      */
1343     private static final Set<ResultCodeEnum> PARTIAL_RESULTS_EXCEPTION_CODES;
1344 
1345     static
1346     {
1347         Set<ResultCodeEnum> set = new HashSet<>();
1348         set.add( ResultCodeEnum.PARTIAL_RESULTS );
1349         set.add( ResultCodeEnum.REFERRAL );
1350         PARTIAL_RESULTS_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1351     }
1352 
1353     /**
1354      * A set of ResultCodes containing those that may correspond to a
1355      * {@link Exception}.
1356      * <ul>
1357      * <li><a href="#REFERRAL">referal(9)</a></li>
1358      * <li><a href="#ADMIN_LIMIT_EXCEEDED">adminLimitExceeded(11)</a></li>
1359      * </ul>
1360      */
1361     private static final Set<ResultCodeEnum> LIMIT_EXCEEDED_EXCEPTION_CODES;
1362 
1363     static
1364     {
1365         Set<ResultCodeEnum> set = new HashSet<>();
1366         set.add( ResultCodeEnum.REFERRAL );
1367         set.add( ResultCodeEnum.ADMIN_LIMIT_EXCEEDED );
1368         LIMIT_EXCEEDED_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1369     }
1370 
1371     /**
1372      * A set of ResultCodes containing those that may correspond to a
1373      * {@link Exception}.
1374      * <ul>
1375      * <li><a
1376      * href="#UNAVAILABLECRITICALEXTENTION">unavailableCriticalExtention(12)</a></li>
1377      * <li><a href="#UNWILLING_TO_PERFORM">unwillingToPerform(53)</a></li>
1378      * </ul>
1379      */
1380     private static final Set<ResultCodeEnum> OPERATION_NOT_SUPPORTED_EXCEPTION_CODES;
1381 
1382     static
1383     {
1384         Set<ResultCodeEnum> set = new HashSet<>();
1385         set.add( ResultCodeEnum.UNAVAILABLE_CRITICAL_EXTENSION );
1386         set.add( ResultCodeEnum.UNWILLING_TO_PERFORM );
1387         OPERATION_NOT_SUPPORTED_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1388     }
1389 
1390     /**
1391      * A set of ResultCodes containing those that may correspond to a
1392      * {@link Exception}.
1393      * <ul>
1394      * <li><a href="#INVALID_DN_SYNTAX">invalidDNSyntax(34)</a></li>
1395      * <li><a href="#NAMING_VIOLATION">namingViolation(64)</a></li>
1396      * </ul>
1397      */
1398     private static final Set<ResultCodeEnum> INVALID_NAME_EXCEPTION_CODES;
1399 
1400     static
1401     {
1402         Set<ResultCodeEnum> set = new HashSet<>();
1403         set.add( ResultCodeEnum.INVALID_DN_SYNTAX );
1404         set.add( ResultCodeEnum.NAMING_VIOLATION );
1405         INVALID_NAME_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1406     }
1407 
1408     /**
1409      * A set of ResultCodes containing those that may correspond to a
1410      * {@link javax.naming.directory.SchemaViolationException}.
1411      * <ul>
1412      * <li><a href="#OBJECT_CLASS_VIOLATION">objectClassViolation(65)</a></li>
1413      * <li><a href="#NOT_ALLOWED_ON_RDN">notAllowedOnRDN(67)</a></li>
1414      * <li><a href="#OBJECT_CLASS_MODS_PROHIBITED">objectClassModsProhibited(69)</a></li>
1415      * </ul>
1416      */
1417     private static final Set<ResultCodeEnum> SCHEMA_VIOLATION_EXCEPTION_CODES;
1418 
1419     static
1420     {
1421         Set<ResultCodeEnum> set = new HashSet<>();
1422         set.add( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
1423         set.add( ResultCodeEnum.NOT_ALLOWED_ON_RDN );
1424         set.add( ResultCodeEnum.OBJECT_CLASS_MODS_PROHIBITED );
1425         SCHEMA_VIOLATION_EXCEPTION_CODES = Collections.unmodifiableSet( set );
1426     }
1427 
1428 
1429     /**
1430      * Private construct so no other instances can be created other than the
1431      * public static constants in this class.
1432      * 
1433      * @param value the integer value of the enumeration.
1434      * @param message the description of the enumeration.
1435      */
1436     ResultCodeEnum( int value, String message )
1437     {
1438         this.value = value;
1439         this.message = message;
1440     }
1441 
1442 
1443     /**
1444      * @return The integer associated with the result code
1445      */
1446     public int getResultCode()
1447     {
1448         return value;
1449     }
1450 
1451 
1452     /**
1453      * Gets the ResultCode enum from its integer value
1454      * 
1455      * @param value the ResultCode numneric value
1456      * @return The integer associated with the result code
1457      */
1458     public static ResultCodeEnum getResultCode( int value )
1459     {
1460         switch ( value )
1461         {
1462             case 0:
1463                 return SUCCESS;
1464             case 1:
1465                 return OPERATIONS_ERROR;
1466             case 2:
1467                 return PROTOCOL_ERROR;
1468             case 3:
1469                 return TIME_LIMIT_EXCEEDED;
1470             case 4:
1471                 return SIZE_LIMIT_EXCEEDED;
1472             case 5:
1473                 return COMPARE_FALSE;
1474             case 6:
1475                 return COMPARE_TRUE;
1476             case 7:
1477                 return AUTH_METHOD_NOT_SUPPORTED;
1478             case 8:
1479                 return STRONG_AUTH_REQUIRED;
1480             case 9:
1481                 return PARTIAL_RESULTS;
1482             case 10:
1483                 return REFERRAL;
1484             case 11:
1485                 return ADMIN_LIMIT_EXCEEDED;
1486             case 12:
1487                 return UNAVAILABLE_CRITICAL_EXTENSION;
1488             case 13:
1489                 return CONFIDENTIALITY_REQUIRED;
1490             case 14:
1491                 return SASL_BIND_IN_PROGRESS;
1492             case 16:
1493                 return NO_SUCH_ATTRIBUTE;
1494             case 17:
1495                 return UNDEFINED_ATTRIBUTE_TYPE;
1496             case 18:
1497                 return INAPPROPRIATE_MATCHING;
1498             case 19:
1499                 return CONSTRAINT_VIOLATION;
1500             case 20:
1501                 return ATTRIBUTE_OR_VALUE_EXISTS;
1502             case 21:
1503                 return INVALID_ATTRIBUTE_SYNTAX;
1504             case 32:
1505                 return NO_SUCH_OBJECT;
1506             case 33:
1507                 return ALIAS_PROBLEM;
1508             case 34:
1509                 return INVALID_DN_SYNTAX;
1510             case 35:
1511                 return UNKNOWN;
1512             case 36:
1513                 return ALIAS_DEREFERENCING_PROBLEM;
1514             case 48:
1515                 return INAPPROPRIATE_AUTHENTICATION;
1516             case 49:
1517                 return INVALID_CREDENTIALS;
1518             case 50:
1519                 return INSUFFICIENT_ACCESS_RIGHTS;
1520             case 51:
1521                 return BUSY;
1522             case 52:
1523                 return UNAVAILABLE;
1524             case 53:
1525                 return UNWILLING_TO_PERFORM;
1526             case 54:
1527                 return LOOP_DETECT;
1528             case 64:
1529                 return NAMING_VIOLATION;
1530             case 65:
1531                 return OBJECT_CLASS_VIOLATION;
1532             case 66:
1533                 return NOT_ALLOWED_ON_NON_LEAF;
1534             case 67:
1535                 return NOT_ALLOWED_ON_RDN;
1536             case 68:
1537                 return ENTRY_ALREADY_EXISTS;
1538             case 69:
1539                 return OBJECT_CLASS_MODS_PROHIBITED;
1540             case 71:
1541                 return AFFECTS_MULTIPLE_DSAS;
1542             case 80:
1543                 return OTHER;
1544             case 118:
1545                 return CANCELED;
1546             case 119:
1547                 return NO_SUCH_OPERATION;
1548             case 120:
1549                 return TOO_LATE;
1550             case 121:
1551                 return CANNOT_CANCEL;
1552             case 4096:
1553                 return E_SYNC_REFRESH_REQUIRED;
1554             default:
1555                 return UNKNOWN;
1556         }
1557     }
1558 
1559 
1560 
1561     /**
1562      * @return The value associated with the current element.
1563      */
1564     public int getValue()
1565     {
1566         return value;
1567     }
1568 
1569 
1570     /**
1571      * @return The description associated with the current element.
1572      */
1573     public String getMessage()
1574     {
1575         return message;
1576     }
1577 
1578 
1579     /**
1580      * Takes a guess at the result code to use if it cannot figure it out from
1581      * known Throwable to result code mappings. Some however are ambiguous
1582      * mapping the same Throwable to multiple codes. If no code can be resolved
1583      * then {@link ResultCodeEnum#OTHER} is returned.
1584      * 
1585      * @param t
1586      *            the throwable to estimate a result code for
1587      * @param type
1588      *            the type of operation being performed
1589      * @return the result code or a good estimate of one
1590      */
1591     public static ResultCodeEnum getBestEstimate( Throwable t, MessageTypeEnum type )
1592     {
1593         Set<ResultCodeEnum> set = getResultCodes( t );
1594 
1595         if ( set.isEmpty() )
1596         {
1597             return ResultCodeEnum.OTHER;
1598         }
1599 
1600         if ( set.size() == 1 )
1601         {
1602             return set.iterator().next();
1603         }
1604 
1605         if ( type == null )
1606         {
1607             Set<ResultCodeEnum> tmp = new HashSet<>();
1608             tmp.addAll( set );
1609             tmp.removeAll( NON_ERRONEOUS_CODES );
1610 
1611             if ( tmp.isEmpty() )
1612             {
1613                 return ResultCodeEnum.OTHER;
1614             }
1615 
1616             return tmp.iterator().next();
1617         }
1618 
1619         Set<ResultCodeEnum> candidates;
1620 
1621         switch ( type )
1622         {
1623             case ABANDON_REQUEST:
1624                 return set.iterator().next();
1625 
1626             case ADD_REQUEST:
1627                 candidates = intersection( set, ADD_CODES );
1628                 break;
1629 
1630             case ADD_RESPONSE:
1631                 candidates = intersection( set, ADD_CODES );
1632                 break;
1633 
1634             case BIND_REQUEST:
1635                 candidates = intersection( set, BIND_CODES );
1636                 break;
1637 
1638             case BIND_RESPONSE:
1639                 candidates = intersection( set, BIND_CODES );
1640                 break;
1641 
1642             case COMPARE_REQUEST:
1643                 candidates = intersection( set, COMPARE_CODES );
1644                 break;
1645 
1646             case COMPARE_RESPONSE:
1647                 candidates = intersection( set, COMPARE_CODES );
1648                 break;
1649 
1650             case DEL_REQUEST:
1651                 candidates = intersection( set, DELETE_CODES );
1652                 break;
1653 
1654             case DEL_RESPONSE:
1655                 candidates = intersection( set, DELETE_CODES );
1656                 break;
1657 
1658             case EXTENDED_REQUEST:
1659                 candidates = intersection( set, EXTENDED_CODES );
1660                 break;
1661 
1662             case EXTENDED_RESPONSE:
1663                 candidates = intersection( set, EXTENDED_CODES );
1664                 break;
1665 
1666             case MODIFYDN_REQUEST:
1667                 candidates = intersection( set, MODIFYDN_CODES );
1668                 break;
1669 
1670             case MODIFYDN_RESPONSE:
1671                 candidates = intersection( set, MODIFYDN_CODES );
1672                 break;
1673 
1674             case MODIFY_REQUEST:
1675                 candidates = intersection( set, MODIFY_CODES );
1676                 break;
1677 
1678             case MODIFY_RESPONSE:
1679                 candidates = intersection( set, MODIFY_CODES );
1680                 break;
1681 
1682             case SEARCH_REQUEST:
1683                 candidates = intersection( set, SEARCH_CODES );
1684                 break;
1685 
1686             case SEARCH_RESULT_DONE:
1687                 candidates = intersection( set, SEARCH_CODES );
1688                 break;
1689 
1690             case SEARCH_RESULT_ENTRY:
1691                 candidates = intersection( set, SEARCH_CODES );
1692                 break;
1693 
1694             case SEARCH_RESULT_REFERENCE:
1695                 candidates = intersection( set, SEARCH_CODES );
1696                 break;
1697 
1698             case UNBIND_REQUEST:
1699                 return set.iterator().next();
1700 
1701             case INTERMEDIATE_RESPONSE:
1702                 candidates = intersection( set, SEARCH_CODES );
1703                 break;
1704 
1705             default:
1706                 throw new IllegalArgumentException( "Unexpected MessageTypeEnum " + type );
1707         }
1708 
1709         // we don't want any codes that do not have anything to do w/ errors
1710         candidates.removeAll( NON_ERRONEOUS_CODES );
1711 
1712         if ( candidates.isEmpty() )
1713         {
1714             return ResultCodeEnum.OTHER;
1715         }
1716 
1717         return candidates.iterator().next();
1718     }
1719 
1720 
1721     private static Set<ResultCodeEnum> intersection( Set<ResultCodeEnum> s1, Set<ResultCodeEnum> s2 )
1722     {
1723         if ( s1.isEmpty() || s2.isEmpty() )
1724         {
1725             return new HashSet<>();
1726         }
1727 
1728         Set<ResultCodeEnum> intersection = new HashSet<>();
1729 
1730         if ( s1.size() <= s2.size() )
1731         {
1732             for ( ResultCodeEnum item : s1 )
1733             {
1734                 if ( s2.contains( item ) )
1735                 {
1736                     intersection.add( item );
1737                 }
1738             }
1739         }
1740         else
1741         {
1742             for ( ResultCodeEnum item : s2 )
1743             {
1744                 if ( s1.contains( item ) )
1745                 {
1746                     intersection.add( item );
1747                 }
1748             }
1749         }
1750 
1751         return intersection;
1752     }
1753 
1754 
1755     /**
1756      * Gets the set of result codes a Throwable may map to. If the throwable
1757      * does not map to any result code at all an empty set is returned. The
1758      * following Throwables and their subclasses map to result codes:
1759      * 
1760      * <pre>
1761      * 
1762      *  Unambiguous Exceptions
1763      *  ======================
1764      * 
1765      *  CommunicationException              ==&gt; operationsError(1)
1766      *  TimeLimitExceededException          ==&gt; timeLimitExceeded(3)
1767      *  SizeLimitExceededException          ==&gt; sizeLimitExceeded(4)
1768      *  AuthenticationException             ==&gt; invalidCredentials(49)
1769      *  NoPermissionException               ==&gt; insufficientAccessRights(50)
1770      *  NoSuchAttributeException            ==&gt; noSuchAttribute(16)
1771      *  InvalidAttributeIdentifierException ==&gt; undefinedAttributeType(17)
1772      *  InvalidSearchFilterException        ==&gt; inappropriateMatching(18)
1773      *  AttributeInUseException             ==&gt; attributeOrValueExists(20)
1774      *  NameNotFoundException               ==&gt; NO_SUCH_OBJECT(32)
1775      *  NameAlreadyBoundException           ==&gt; entryAlreadyExists(68)
1776      *  ContextNotEmptyException            ==&gt; notAllowedOnNonLeaf(66)
1777      * 
1778      * 
1779      *  Ambiguous Exceptions
1780      *  ====================
1781      * 
1782      *  NamingException
1783      *  ---------------
1784      *  operationsError(1)
1785      *  aliasProblem(33)
1786      *  aliasDereferencingProblem(36)
1787      *  loopDetect(54)
1788      *  affectsMultipleDSAs(71)
1789      *  other(80)
1790      * 
1791      *  AuthenticationNotSupportedException
1792      *  -----------------------------------
1793      *  authMethodNotSupported (7)
1794      *  strongAuthRequired (8)
1795      *  confidentialityRequired (13)
1796      *  inappropriateAuthentication(48)
1797      * 
1798      *  ServiceUnavailableException
1799      *  ---------------------------
1800      *  busy(51)
1801      *  unavailable(52)
1802      * 
1803      *  InvalidAttributeValueException
1804      *  ------------------------------
1805      *  constraintViolation(19)
1806      *  invalidAttributeSyntax(21)
1807      * 
1808      *  PartialResultException
1809      *  ----------------------
1810      *  partialResults(9)
1811      *  referral(10)
1812      * 
1813      *  LimitExceededException
1814      *  ----------------------
1815      *  referal(9)
1816      *  adminLimitExceeded(11)
1817      * 
1818      *  OperationNotSupportedException
1819      *  ------------------------------
1820      *  unavailableCriticalExtention(12)
1821      *  unwillingToPerform(53)
1822      * 
1823      *  InvalidNameException
1824      *  --------------------
1825      *  invalidDNSyntax(34)
1826      *  namingViolation(64)
1827      * 
1828      *  SchemaViolationException
1829      *  ------------------------
1830      *  objectClassViolation(65)
1831      *  notAllowedOnRDN(67)
1832      *  objectClassModsProhibited(69)
1833      * 
1834      * </pre>
1835      * 
1836      * @param t
1837      *            the Throwable to find the result code mappings for
1838      * @return the set of mapped result codes
1839      */
1840     private static Set<ResultCodeEnum> getResultCodes( Throwable t )
1841     {
1842         ResultCodeEnum rc = getResultCode( t );
1843         if ( rc != null )
1844         {
1845             return Collections.singleton( rc );
1846         }
1847 
1848         if ( t instanceof LdapSchemaViolationException )
1849         {
1850             return SCHEMA_VIOLATION_EXCEPTION_CODES;
1851         }
1852 
1853         if ( t instanceof LdapInvalidDnException )
1854         {
1855             return INVALID_NAME_EXCEPTION_CODES;
1856         }
1857 
1858         if ( t instanceof LdapUnwillingToPerformException )
1859         {
1860             return OPERATION_NOT_SUPPORTED_EXCEPTION_CODES;
1861         }
1862 
1863         if ( t instanceof LimitExceededException )
1864         {
1865             return LIMIT_EXCEEDED_EXCEPTION_CODES;
1866         }
1867 
1868         if ( t instanceof PartialResultException )
1869         {
1870             return PARTIAL_RESULTS_EXCEPTION_CODES;
1871         }
1872 
1873         if ( t instanceof LdapInvalidAttributeValueException )
1874         {
1875             return INVALID_ATTRIBUTE_VALUE_EXCEPTION_CODES;
1876         }
1877 
1878         if ( t instanceof LdapServiceUnavailableException )
1879         {
1880             return SERVICE_UNAVAILABLE_CODES;
1881         }
1882 
1883         if ( t instanceof LdapAuthenticationNotSupportedException )
1884         {
1885             return AUTHENTICATION_NOT_SUPPORTED_EXCEPTION_CODES;
1886         }
1887 
1888         // keep this last because others are subtypes and thier evaluation
1889         // may be shorted otherwise by this comparison here
1890         if ( t instanceof LdapException )
1891         {
1892             return NAMING_EXCEPTION_CODES;
1893         }
1894 
1895         return EMPTY_RESULT_CODE_SET;
1896     }
1897 
1898 
1899     /**
1900      * Gets an LDAP result code from a Throwable if it can resolve it
1901      * unambiguously or returns null if it cannot resolve the exception to a
1902      * single ResultCode. If the Throwable is an instance of LdapException this
1903      * is already done for us, otherwise we use the following mapping:
1904      * 
1905      * <pre>
1906      * 
1907      *  Unambiguous Exceptions
1908      *  ======================
1909      * 
1910      *  CommunicationException              ==&gt; operationsError(1)
1911      *  TimeLimitExceededException          ==&gt; timeLimitExceeded(3)
1912      *  SizeLimitExceededException          ==&gt; sizeLimitExceeded(4)
1913      *  AuthenticationException             ==&gt; invalidCredentials(49)
1914      *  NoPermissionException               ==&gt; insufficientAccessRights(50)
1915      *  NoSuchAttributeException            ==&gt; noSuchAttribute(16)
1916      *  InvalidAttributeIdentifierException ==&gt; undefinedAttributeType(17)
1917      *  InvalidSearchFilterException        ==&gt; inappropriateMatching(18)
1918      *  AttributeInUseException             ==&gt; attributeOrValueExists(20)
1919      *  NameNotFoundException               ==&gt; NO_SUCH_OBJECT(32)
1920      *  NameAlreadyBoundException           ==&gt; entryAlreadyExists(68)
1921      *  ContextNotEmptyException            ==&gt; notAllowedOnNonLeaf(66)
1922      * </pre>
1923      * 
1924      * If we cannot find a mapping then null is returned.
1925      * 
1926      * @param t The exception for which we need a ResultCodeEnum
1927      * @return The ResultCodeEnum associated wit the given exception 
1928      */
1929     public static ResultCodeEnum getResultCode( Throwable t )
1930     {
1931         if ( t instanceof LdapOperationException )
1932         {
1933             return ( ( LdapOperationException ) t ).getResultCode();
1934         }
1935 
1936         if ( t instanceof CommunicationException )
1937         {
1938             return ResultCodeEnum.PROTOCOL_ERROR;
1939         }
1940 
1941         if ( t instanceof LdapTimeLimitExceededException )
1942         {
1943             return ResultCodeEnum.TIME_LIMIT_EXCEEDED;
1944         }
1945 
1946         if ( t instanceof SizeLimitExceededException )
1947         {
1948             return ResultCodeEnum.SIZE_LIMIT_EXCEEDED;
1949         }
1950 
1951         if ( t instanceof LdapAuthenticationException )
1952         {
1953             return ResultCodeEnum.INVALID_CREDENTIALS;
1954         }
1955 
1956         if ( t instanceof LdapNoPermissionException )
1957         {
1958             return ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS;
1959         }
1960 
1961         if ( t instanceof LdapNoSuchAttributeException )
1962         {
1963             return ResultCodeEnum.NO_SUCH_ATTRIBUTE;
1964         }
1965 
1966         if ( t instanceof LdapInvalidAttributeTypeException )
1967         {
1968             return ResultCodeEnum.UNDEFINED_ATTRIBUTE_TYPE;
1969         }
1970 
1971         if ( t instanceof LdapInvalidSearchFilterException )
1972         {
1973             return ResultCodeEnum.INAPPROPRIATE_MATCHING;
1974         }
1975 
1976         if ( t instanceof LdapAttributeInUseException )
1977         {
1978             return ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS;
1979         }
1980 
1981         if ( t instanceof LdapNoSuchObjectException )
1982         {
1983             return ResultCodeEnum.NO_SUCH_OBJECT;
1984         }
1985 
1986         if ( t instanceof LdapEntryAlreadyExistsException )
1987         {
1988             return ResultCodeEnum.ENTRY_ALREADY_EXISTS;
1989         }
1990 
1991         if ( t instanceof LdapContextNotEmptyException )
1992         {
1993             return ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF;
1994         }
1995 
1996         return null;
1997     }
1998 
1999 
2000     /**
2001      * Process the response, throwing the associated exception if needed. If the result
2002      * was SUCCESS, does not return anything but true. 
2003      * 
2004      * @param response The response to process
2005      * @return For the COMPARE_TRUE or COMPARE_FALSE results, return true or false
2006      * @throws LdapException The associated exception
2007      */
2008     public static boolean processResponse( ResultResponse response ) throws LdapException
2009     {
2010         LdapResult ldapResult = response.getLdapResult();
2011 
2012         switch ( ldapResult.getResultCode() )
2013         {
2014         // Not erroneous code
2015             case SUCCESS:
2016             case PARTIAL_RESULTS:
2017             case REFERRAL:
2018             case SASL_BIND_IN_PROGRESS:
2019             case CANCELED:
2020             case COMPARE_TRUE:
2021                 return true;
2022 
2023             case COMPARE_FALSE:
2024                 return false;
2025 
2026             case INVALID_CREDENTIALS:
2027                 LdapAuthenticationException authenticationException = new LdapAuthenticationException(
2028                     ldapResult.getDiagnosticMessage() );
2029                 authenticationException.setResolvedDn( ldapResult.getMatchedDn() );
2030 
2031                 throw authenticationException;
2032 
2033             case UNWILLING_TO_PERFORM:
2034             case UNAVAILABLE_CRITICAL_EXTENSION:
2035                 LdapUnwillingToPerformException unwillingToPerformException =
2036                     new LdapUnwillingToPerformException( ldapResult.getResultCode(), ldapResult.getDiagnosticMessage() );
2037                 unwillingToPerformException.setResolvedDn( ldapResult.getMatchedDn() );
2038 
2039                 throw unwillingToPerformException;
2040 
2041             case INSUFFICIENT_ACCESS_RIGHTS:
2042                 LdapNoPermissionException ldapNoPermissionException = new LdapNoPermissionException(
2043                     ldapResult.getDiagnosticMessage() );
2044                 ldapNoPermissionException.setResolvedDn( ldapResult.getMatchedDn() );
2045 
2046                 throw ldapNoPermissionException;
2047 
2048             case NOT_ALLOWED_ON_NON_LEAF:
2049                 LdapContextNotEmptyException ldapContextNotEmptyException = new LdapContextNotEmptyException(
2050                     ldapResult.getDiagnosticMessage() );
2051                 ldapContextNotEmptyException.setResolvedDn( ldapResult.getMatchedDn() );
2052 
2053                 throw ldapContextNotEmptyException;
2054 
2055             case NO_SUCH_OBJECT:
2056                 LdapNoSuchObjectException ldapNoSuchObjectException = new LdapNoSuchObjectException(
2057                     ldapResult.getDiagnosticMessage() );
2058                 ldapNoSuchObjectException.setResolvedDn( ldapResult.getMatchedDn() );
2059 
2060                 throw ldapNoSuchObjectException;
2061 
2062             case NO_SUCH_ATTRIBUTE:
2063                 LdapNoSuchAttributeException ldapNoSuchAttributeException = new LdapNoSuchAttributeException(
2064                     ldapResult.getDiagnosticMessage() );
2065                 ldapNoSuchAttributeException.setResolvedDn( ldapResult.getMatchedDn() );
2066 
2067                 throw ldapNoSuchAttributeException;
2068 
2069             case ATTRIBUTE_OR_VALUE_EXISTS:
2070                 LdapAttributeInUseException ldapAttributeInUseException = new LdapAttributeInUseException(
2071                     ldapResult.getDiagnosticMessage() );
2072                 ldapAttributeInUseException.setResolvedDn( ldapResult.getMatchedDn() );
2073 
2074                 throw ldapAttributeInUseException;
2075 
2076             case ENTRY_ALREADY_EXISTS:
2077                 LdapEntryAlreadyExistsException ldapEntryAlreadyExistsException = new LdapEntryAlreadyExistsException(
2078                     ldapResult.getDiagnosticMessage() );
2079                 ldapEntryAlreadyExistsException.setResolvedDn( ldapResult.getMatchedDn() );
2080 
2081                 throw ldapEntryAlreadyExistsException;
2082 
2083             case OBJECT_CLASS_VIOLATION:
2084             case NOT_ALLOWED_ON_RDN:
2085             case OBJECT_CLASS_MODS_PROHIBITED:
2086                 LdapSchemaViolationException ldapSchemaViolationException =
2087                     new LdapSchemaViolationException( ldapResult.getResultCode(), ldapResult.getDiagnosticMessage() );
2088                 ldapSchemaViolationException.setResolvedDn( ldapResult.getMatchedDn() );
2089 
2090                 throw ldapSchemaViolationException;
2091 
2092             case ALIAS_PROBLEM:
2093                 LdapAliasException ldapAliasException = new LdapAliasException( ldapResult.getDiagnosticMessage() );
2094                 ldapAliasException.setResolvedDn( ldapResult.getMatchedDn() );
2095 
2096                 throw ldapAliasException;
2097 
2098             case AFFECTS_MULTIPLE_DSAS:
2099                 LdapAffectMultipleDsaException ldapAffectMultipleDsaException = new LdapAffectMultipleDsaException(
2100                     ldapResult.getDiagnosticMessage() );
2101                 ldapAffectMultipleDsaException.setResolvedDn( ldapResult.getMatchedDn() );
2102 
2103                 throw ldapAffectMultipleDsaException;
2104 
2105             case ALIAS_DEREFERENCING_PROBLEM:
2106                 LdapAliasDereferencingException ldapAliasDereferencingException = new LdapAliasDereferencingException(
2107                     ldapResult.getDiagnosticMessage() );
2108                 ldapAliasDereferencingException.setResolvedDn( ldapResult.getMatchedDn() );
2109 
2110                 throw ldapAliasDereferencingException;
2111 
2112             case AUTH_METHOD_NOT_SUPPORTED:
2113             case INAPPROPRIATE_AUTHENTICATION:
2114             case CONFIDENTIALITY_REQUIRED:
2115                 LdapAuthenticationNotSupportedException ldapAuthenticationNotSupportedException =
2116                     new LdapAuthenticationNotSupportedException( ldapResult.getResultCode(),
2117                         ldapResult.getDiagnosticMessage() );
2118                 ldapAuthenticationNotSupportedException.setResolvedDn( ldapResult.getMatchedDn() );
2119 
2120                 throw ldapAuthenticationNotSupportedException;
2121 
2122             case BUSY:
2123             case UNAVAILABLE:
2124                 LdapServiceUnavailableException ldapServiceUnavailableException =
2125                     new LdapServiceUnavailableException( ldapResult.getResultCode(), ldapResult.getDiagnosticMessage() );
2126                 ldapServiceUnavailableException.setResolvedDn( ldapResult.getMatchedDn() );
2127 
2128                 throw ldapServiceUnavailableException;
2129 
2130             case CONSTRAINT_VIOLATION:
2131             case INVALID_ATTRIBUTE_SYNTAX:
2132                 LdapInvalidAttributeValueException ldapInvalidAttributeValueException =
2133                     new LdapInvalidAttributeValueException( ldapResult.getResultCode(),
2134                         ldapResult.getDiagnosticMessage() );
2135                 ldapInvalidAttributeValueException.setResolvedDn( ldapResult.getMatchedDn() );
2136 
2137                 throw ldapInvalidAttributeValueException;
2138 
2139             case INAPPROPRIATE_MATCHING:
2140                 LdapInvalidSearchFilterException ldapInvalidSearchFilterException = new LdapInvalidSearchFilterException(
2141                     ldapResult.getDiagnosticMessage() );
2142                 ldapInvalidSearchFilterException.setResolvedDn( ldapResult.getMatchedDn() );
2143 
2144                 throw ldapInvalidSearchFilterException;
2145 
2146             case INVALID_DN_SYNTAX:
2147             case NAMING_VIOLATION:
2148                 LdapInvalidDnException ldapInvalidDnException =
2149                     new LdapInvalidDnException( ldapResult.getResultCode(), ldapResult.getDiagnosticMessage() );
2150                 ldapInvalidDnException.setResolvedDn( ldapResult.getMatchedDn() );
2151 
2152                 throw ldapInvalidDnException;
2153 
2154             case LOOP_DETECT:
2155                 LdapLoopDetectedException ldapLoopDetectedException = new LdapLoopDetectedException(
2156                     ldapResult.getDiagnosticMessage() );
2157                 ldapLoopDetectedException.setResolvedDn( ldapResult.getMatchedDn() );
2158 
2159                 throw ldapLoopDetectedException;
2160 
2161             case OPERATIONS_ERROR:
2162                 LdapOperationErrorException ldapOperationErrorException = new LdapOperationErrorException(
2163                     ldapResult.getDiagnosticMessage() );
2164                 ldapOperationErrorException.setResolvedDn( ldapResult.getMatchedDn() );
2165 
2166                 throw ldapOperationErrorException;
2167 
2168             case PROTOCOL_ERROR:
2169                 LdapProtocolErrorException ldapProtocolErrorException = new LdapProtocolErrorException(
2170                     ldapResult.getDiagnosticMessage() );
2171                 ldapProtocolErrorException.setResolvedDn( ldapResult.getMatchedDn() );
2172 
2173                 throw ldapProtocolErrorException;
2174 
2175             case TIME_LIMIT_EXCEEDED:
2176                 LdapTimeLimitExceededException ldapTimeLimitExceededException = new LdapTimeLimitExceededException(
2177                     ldapResult.getDiagnosticMessage() );
2178                 ldapTimeLimitExceededException.setResolvedDn( ldapResult.getMatchedDn() );
2179 
2180                 throw ldapTimeLimitExceededException;
2181 
2182             case UNDEFINED_ATTRIBUTE_TYPE:
2183                 LdapInvalidAttributeTypeException ldapInvalidAttributeTypeException = new LdapInvalidAttributeTypeException(
2184                     ldapResult.getDiagnosticMessage() );
2185                 ldapInvalidAttributeTypeException.setResolvedDn( ldapResult.getMatchedDn() );
2186 
2187                 throw ldapInvalidAttributeTypeException;
2188 
2189             case OTHER:
2190                 LdapOtherException ldapOtherException = new LdapOtherException( ldapResult.getDiagnosticMessage() );
2191                 ldapOtherException.setResolvedDn( ldapResult.getMatchedDn() );
2192 
2193                 throw ldapOtherException;
2194 
2195             case SIZE_LIMIT_EXCEEDED:
2196                 LdapSizeLimitExceededException ldapSizeLimitExceededException = new LdapSizeLimitExceededException(
2197                     ldapResult.getDiagnosticMessage() );
2198                 ldapSizeLimitExceededException.setResolvedDn( ldapResult.getMatchedDn() );
2199 
2200                 throw ldapSizeLimitExceededException;
2201 
2202             case STRONG_AUTH_REQUIRED:
2203                 LdapStrongAuthenticationRequiredException ldapStrongAuthenticationRequiredException =
2204                     new LdapStrongAuthenticationRequiredException( ldapResult.getDiagnosticMessage() );
2205                 ldapStrongAuthenticationRequiredException.setResolvedDn( ldapResult.getMatchedDn() );
2206 
2207                 throw ldapStrongAuthenticationRequiredException;
2208 
2209             case ADMIN_LIMIT_EXCEEDED:
2210                 LdapAdminLimitExceededException ldapAdminLimitExceededException =
2211                     new LdapAdminLimitExceededException( ldapResult.getDiagnosticMessage() );
2212                 ldapAdminLimitExceededException.setResolvedDn( ldapResult.getMatchedDn() );
2213 
2214                 throw ldapAdminLimitExceededException;
2215 
2216             case TOO_LATE:
2217                 LdapTooLateException ldapTooLateException = new LdapTooLateException( ldapResult.getDiagnosticMessage() );
2218                 ldapTooLateException.setResolvedDn( ldapResult.getMatchedDn() );
2219 
2220                 throw ldapTooLateException;
2221 
2222             case UNKNOWN:
2223                 LdapUnknownException ldapUnknownException = new LdapUnknownException( ldapResult.getDiagnosticMessage() );
2224                 ldapUnknownException.setResolvedDn( ldapResult.getMatchedDn() );
2225 
2226                 throw ldapUnknownException;
2227 
2228             case CANNOT_CANCEL:
2229                 LdapCannotCancelException ldapCannotCancelException = new LdapCannotCancelException(
2230                     ldapResult.getDiagnosticMessage() );
2231                 ldapCannotCancelException.setResolvedDn( ldapResult.getMatchedDn() );
2232 
2233                 throw ldapCannotCancelException;
2234 
2235             case NO_SUCH_OPERATION:
2236                 LdapNoSuchOperationException ldapNoSuchOperationException = new LdapNoSuchOperationException(
2237                     ldapResult.getDiagnosticMessage() );
2238                 ldapNoSuchOperationException.setResolvedDn( ldapResult.getMatchedDn() );
2239 
2240                 throw ldapNoSuchOperationException;
2241 
2242             case E_SYNC_REFRESH_REQUIRED:
2243                 // This is a specific error message. We won't encapsulate it in a dedicated exception
2244                 // Fallthrough
2245 
2246             default:
2247                 LdapOperationException exception = new LdapOperationException( ldapResult.getResultCode(),
2248                     ldapResult.getDiagnosticMessage() );
2249                 exception.setResolvedDn( ldapResult.getMatchedDn() );
2250 
2251                 throw exception;
2252         }
2253     }
2254 }