001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.protocols.ldap;
018import org.forgerock.i18n.LocalizableMessage;
019
020import static org.opends.messages.CoreMessages.*;
021/**
022 * This class defines a set of constants that correspond to the result codes
023 * defined in the LDAP protocol.  Note that many (but not all) of the result
024 * codes numbered 81 and higher come from the LDAP C API specification and are
025 * only intended for client-side use and should not be returned from the
026 * Directory Server.  These are denoted with a "CLIENT_SIDE_" prefix.
027 */
028public class LDAPResultCode
029{
030  /** The LDAP result code for successful operations. */
031  public static final int SUCCESS = 0;
032
033  /** The LDAP result code for operations that fail due to an operations error. */
034  public static final int OPERATIONS_ERROR = 1;
035
036  /** The LDAP result code for operations that fail due to a protocol error. */
037  public static final int PROTOCOL_ERROR = 2;
038
039  /** The LDAP result code for operations that fail as a result of exceeding a time limit. */
040  public static final int TIME_LIMIT_EXCEEDED = 3;
041
042  /** The LDAP result code for operations that fail as a result of exceeding a size limit. */
043  public static final int SIZE_LIMIT_EXCEEDED = 4;
044
045  /** The LDAP result code for compare operations in which the assertion is false. */
046  public static final int COMPARE_FALSE = 5;
047
048  /** The LDAP result code for compare operations in which the assertion is true. */
049  public static final int COMPARE_TRUE = 6;
050
051  /**
052   * The LDAP result code for operations that fail because the requested
053   * authentication method is not supported.
054   */
055  public static final int AUTH_METHOD_NOT_SUPPORTED = 7;
056
057  /** The LDAP result code for operations that fail because strong authentication is required. */
058  public static final int STRONG_AUTH_REQUIRED = 8;
059
060  /** The LDAP result code for operations that encountered a referral. */
061  public static final int REFERRAL = 10;
062
063  /**
064   * The LDAP result code for operations that fail as a result of exceeding an
065   * administrative limit.
066   */
067  public static final int ADMIN_LIMIT_EXCEEDED = 11;
068
069  /**
070   * The LDAP result code for operations that fail because they contain an
071   * unavailable critical extension.
072   */
073  public static final int UNAVAILABLE_CRITICAL_EXTENSION = 12;
074
075  /** The LDAP result code for operations that fail because confidentiality is required. */
076  public static final int CONFIDENTIALITY_REQUIRED = 13;
077
078  /** The LDAP result code used for multi-stage SASL bind operations that are not yet complete. */
079  public static final int SASL_BIND_IN_PROGRESS = 14;
080
081  /** The LDAP result code for operations that fail because a specified attribute does not exist. */
082  public static final int NO_SUCH_ATTRIBUTE = 16;
083
084  /**
085   * The LDAP result code for operations that fail because a specified attribute
086   * type is not defined in the server schema.
087   */
088  public static final int UNDEFINED_ATTRIBUTE_TYPE = 17;
089
090  /**
091   * The LDAP result code for operations that fail as a result of attempting an
092   * inappropriate form of matching on an attribute.
093   */
094  public static final int INAPPROPRIATE_MATCHING = 18;
095
096  /**
097   * The LDAP result code for operations that fail because a defined constraint
098   * has been violated.
099   */
100  public static final int CONSTRAINT_VIOLATION = 19;
101
102  /**
103   * The LDAP result code for operations that fail because of a conflict with an
104   * existing attribute or value.
105   */
106  public static final int ATTRIBUTE_OR_VALUE_EXISTS = 20;
107
108  /** The LDAP result code for operations that fail because of an invalid attribute syntax. */
109  public static final int INVALID_ATTRIBUTE_SYNTAX = 21;
110
111  /** The LDAP result code for operations that fail because a targeted entry does not exist. */
112  public static final int NO_SUCH_OBJECT = 32;
113
114  /**
115   * The LDAP result code for operations that fail because the an alias was
116   * encountered in an illegal context.
117   */
118  public static final int ALIAS_PROBLEM = 33;
119
120  /** The LDAP result code for operations that fail because the request included a malformed DN. */
121  public static final int INVALID_DN_SYNTAX = 34;
122
123  /**
124   * The LDAP result code for operations that fail because a problem occurred
125   * while attempting to dereference an alias.
126   */
127  public static final int ALIAS_DEREFERENCING_PROBLEM = 36;
128
129  /**
130   * The LDAP result code for operations that fail because the user attempted to
131   * perform a type of authentication that was inappropriate for the targeted
132   * entry.
133   */
134  public static final int INAPPROPRIATE_AUTHENTICATION = 48;
135
136  /**
137   * The LDAP result code for operations that fail because the user supplied
138   * invalid credentials for an authentication attempt.
139   */
140  public static final int INVALID_CREDENTIALS = 49;
141
142  /**
143   * The LDAP result code for operations that fail because the client does not
144   * have permission to perform the requested operation.
145   */
146  public static final int INSUFFICIENT_ACCESS_RIGHTS = 50;
147
148  /** The LDAP result code for operations that fail because the server was too busy to process it. */
149  public static final int BUSY = 51;
150
151  /**
152   * The LDAP result code for operations that fail because the server or a
153   * required resource was unavailable.
154   */
155  public static final int UNAVAILABLE = 52;
156
157  /**
158   * The LDAP result code for operations that fail because the server was
159   * unwilling to perform the requested operation.
160   */
161  public static final int UNWILLING_TO_PERFORM = 53;
162
163  /**
164   * The LDAP result code for operations that fail because a referral or
165   * chaining loop was detected.
166   */
167  public static final int LOOP_DETECT = 54;
168
169  /**
170   * The LDAP result code for operations that fail because the request included
171   * a VLV request control without a server-side sort control.
172   */
173  public static final int SORT_CONTROL_MISSING = 60;
174
175  /**
176   * The LDAP result code for operations that fail because the request included
177   * a VLV request control with an invalid offset.
178   */
179  public static final int OFFSET_RANGE_ERROR = 61;
180
181  /** The LDAP result code for operations that fail due to a naming violation. */
182  public static final int NAMING_VIOLATION = 64;
183
184  /**
185   * The LDAP result code for operations that fail because the requested
186   * operation would have resulted in an entry that violates the server schema.
187   */
188  public static final int OBJECTCLASS_VIOLATION = 65;
189
190  /**
191   * The LDAP result code for operations that fail because the requested
192   * operation is not allowed on non-leaf entries.
193   */
194  public static final int NOT_ALLOWED_ON_NONLEAF = 66;
195
196  /**
197   * The LDAP result code for operations that fail because the requested
198   * operation is not allowed on an RDN attribute.
199   */
200  public static final int NOT_ALLOWED_ON_RDN = 67;
201
202  /**
203   * The LDAP result code for operations that fail because the requested
204   * operation would have resulted in an entry that conflicts with one that
205   * already exists.
206   */
207  public static final int ENTRY_ALREADY_EXISTS = 68;
208
209  /**
210   * The LDAP result code for operations that fail because the requested
211   * operation attempted to modify objectclass values in an illegal manner.
212   */
213  public static final int OBJECTCLASS_MODS_PROHIBITED = 69;
214
215  /**
216   * The LDAP result code for operations that fail because the requested
217   * operation would have required interaction with multiple DSAs.
218   */
219  public static final int AFFECTS_MULTIPLE_DSAS = 71;
220
221  /**
222   * The LDAP result code for operations that fail due to an error in
223   * virtual list view processing.
224   */
225  public static final int VIRTUAL_LIST_VIEW_ERROR = 76;
226
227  /**
228   * The LDAP result code for use in cases in which none of the other defined
229   * result codes are appropriate.
230   */
231  public static final int OTHER = 80;
232
233  /**
234   * The client-side result code that indicates that a previously-established
235   * connection to the server was lost.  This is for client-side use only and
236   * should never be transferred over protocol.
237   */
238  public static final int CLIENT_SIDE_SERVER_DOWN = 81;
239
240  /**
241   * The client-side result code that indicates that a local error occurred that
242   * had nothing to do with interaction with the server.  This is for
243   * client-side use only and should never be transferred over protocol.
244   */
245  public static final int CLIENT_SIDE_LOCAL_ERROR = 82;
246
247  /**
248   * The client-side result code that indicates that an error occurred while
249   * encoding a request to send to the server.  This is for client-side use only
250   * and should never be transferred over protocol.
251   */
252  public static final int CLIENT_SIDE_ENCODING_ERROR = 83;
253
254  /**
255   * The client-side result code that indicates that an error occurred while
256   * decoding a response from the server.  This is for client-side use only and
257   * should never be transferred over protocol.
258   */
259  public static final int CLIENT_SIDE_DECODING_ERROR = 84;
260
261  /**
262   * The client-side result code that indicates that the client did not receive
263   * an expected response in a timely manner.  This is for client-side use only
264   * and should never be transferred over protocol.
265   */
266  public static final int CLIENT_SIDE_TIMEOUT = 85;
267
268  /**
269   * The client-side result code that indicates that the user requested an
270   * unknown or unsupported authentication mechanism.  This is for client-side
271   * use only and should never be transferred over protocol.
272   */
273  public static final int CLIENT_SIDE_AUTH_UNKNOWN = 86;
274
275  /**
276   * The client-side result code that indicates that the filter provided by the
277   * user was malformed and could not be parsed.  This is for client-side use
278   * only and should never be transferred over protocol.
279   */
280  public static final int CLIENT_SIDE_FILTER_ERROR = 87;
281
282  /**
283   * The client-side result code that indicates that the user cancelled an
284   * operation.  This is for client-side use only and should never be
285   * transferred over protocol.
286   */
287  public static final int CLIENT_SIDE_USER_CANCELLED = 88;
288
289  /**
290   * The client-side result code that indicates that there was a problem with
291   * one or more of the parameters provided by the user.  This is for
292   * client-side use only and should never be transferred over protocol.
293   */
294  public static final int CLIENT_SIDE_PARAM_ERROR = 89;
295
296  /**
297   * The client-side result code that indicates that the client application was
298   * not able to allocate enough memory for the requested operation.  This is
299   * for client-side use only and should never be transferred over protocol.
300   */
301  public static final int CLIENT_SIDE_NO_MEMORY = 90;
302
303  /**
304   * The client-side result code that indicates that the client was not able to
305   * establish a connection to the server.  This is for client-side use only and
306   * should never be transferred over protocol.
307   */
308  public static final int CLIENT_SIDE_CONNECT_ERROR = 91;
309
310  /**
311   * The client-side result code that indicates that the user requested an
312   * operation that is not supported.  This is for client-side use only and
313   * should never be transferred over protocol.
314   */
315  public static final int CLIENT_SIDE_NOT_SUPPORTED = 92;
316
317  /**
318   * The client-side result code that indicates that the client expected a
319   * control to be present in the response from the server but it was not
320   * included.  This is for client-side use only and should never be transferred
321   * over protocol.
322   */
323  public static final int CLIENT_SIDE_CONTROL_NOT_FOUND = 93;
324
325  /**
326   * The client-side result code that indicates that the server did not return
327   * any results for a search operation that was expected to match at least one
328   * entry.  This is for client-side use only and should never be transferred
329   * over protocol.
330   */
331  public static final int CLIENT_SIDE_NO_RESULTS_RETURNED = 94;
332
333  /**
334   * The client-side result code that indicates that the server has returned
335   * more matching entries for a search operation than have been processed so
336   * far.  This is for client-side use only and should never be transferred over
337   * protocol.
338   */
339  public static final int CLIENT_SIDE_MORE_RESULTS_TO_RETURN = 95;
340
341  /**
342   * The client-side result code that indicates that the client detected a
343   * referral loop caused by servers referencing each other in a circular
344   * manner.  This is for client-side use only and should never be transferred
345   * over protocol.
346   */
347  public static final int CLIENT_SIDE_CLIENT_LOOP = 96;
348
349  /**
350   * The client-side result code that indicates that the client reached the
351   * maximum number of hops allowed when attempting to follow a referral (i.e.,
352   * following one referral resulted in another referral which resulted in
353   * another referral and so on).  This is for client-side use only and should
354   * never be transferred over protocol.
355   */
356  public static final int CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED = 97;
357
358  /**
359   * The LDAP result code for cancel operations that are successful, or for
360   * operations that are canceled.
361   */
362  public static final int CANCELED = 118;
363
364  /**
365   * The LDAP result code for cancel operations that fail because the specified
366   * operation could not be found.
367   */
368  public static final int NO_SUCH_OPERATION = 119;
369
370  /**
371   * The LDAP result code for cancel operations that fail because the specified
372   * operation has already progressed too far to be canceled.
373   */
374  public static final int TOO_LATE = 120;
375
376  /**
377   * The LDAP result code for cancel operations that fail because the specified
378   * operation cannot be canceled.
379   */
380  public static final int CANNOT_CANCEL = 121;
381
382  /**
383   * The LDAP result code for operations that are rejected because the
384   * filter in the LDAP assertion control did not match the target entry.
385   */
386  public static final int ASSERTION_FAILED = 122;
387
388  /**
389   * The LDAP result code for operations that fail because the server refused
390   * the client's requested authorization.
391   */
392  public static final int AUTHORIZATION_DENIED = 123;
393
394  /**
395   * The LDAP result code for operations in which no action is taken because the
396   * request include the LDAP no-op control.
397   *
398   * FIXME -- This is a temporary result code for use until
399   *          draft-zeilenga-ldap-noop is updated and an official result code is
400   *          allocated for it.  In the meantime, this result appears to be the
401   *          one used by OpenLDAP as per the message at
402   *          http://www.openldap.org/lists/openldap-devel/200601/msg00143.html
403   *          (0x410e = 16654).
404   */
405  public static final int NO_OPERATION = 16654;
406
407  /**
408   * Retrieves a string representation of the provided LDAP result code.
409   *
410   * @param  resultCode  The LDAP result code value for which to obtain the
411   *                     string representation.
412   *
413   * @return  The string representation of the provided LDAP result code.
414   */
415  public static String toString(int resultCode)
416  {
417    return toLocalizableMessage(resultCode).toString();
418  }
419
420  private static LocalizableMessage toLocalizableMessage(int resultCode)
421  {
422    switch (resultCode)
423    {
424      case SUCCESS:
425        return INFO_RESULT_SUCCESS.get();
426      case OPERATIONS_ERROR:
427        return INFO_RESULT_OPERATIONS_ERROR.get();
428      case PROTOCOL_ERROR:
429        return INFO_RESULT_PROTOCOL_ERROR.get();
430      case TIME_LIMIT_EXCEEDED:
431        return INFO_RESULT_TIME_LIMIT_EXCEEDED.get();
432      case SIZE_LIMIT_EXCEEDED:
433        return INFO_RESULT_SIZE_LIMIT_EXCEEDED.get();
434      case COMPARE_FALSE:
435        return INFO_RESULT_COMPARE_FALSE.get();
436      case COMPARE_TRUE:
437        return INFO_RESULT_COMPARE_TRUE.get();
438      case AUTH_METHOD_NOT_SUPPORTED:
439        return INFO_RESULT_AUTH_METHOD_NOT_SUPPORTED.get();
440      case STRONG_AUTH_REQUIRED:
441        return INFO_RESULT_STRONG_AUTH_REQUIRED.get();
442      case REFERRAL:
443        return INFO_RESULT_REFERRAL.get();
444      case ADMIN_LIMIT_EXCEEDED:
445        return INFO_RESULT_ADMIN_LIMIT_EXCEEDED.get();
446      case UNAVAILABLE_CRITICAL_EXTENSION:
447        return INFO_RESULT_UNAVAILABLE_CRITICAL_EXTENSION.get();
448      case CONFIDENTIALITY_REQUIRED:
449        return INFO_RESULT_CONFIDENTIALITY_REQUIRED.get();
450      case SASL_BIND_IN_PROGRESS:
451        return INFO_RESULT_SASL_BIND_IN_PROGRESS.get();
452      case NO_SUCH_ATTRIBUTE:
453        return INFO_RESULT_NO_SUCH_ATTRIBUTE.get();
454      case UNDEFINED_ATTRIBUTE_TYPE:
455        return INFO_RESULT_UNDEFINED_ATTRIBUTE_TYPE.get();
456      case INAPPROPRIATE_MATCHING:
457        return INFO_RESULT_INAPPROPRIATE_MATCHING.get();
458      case CONSTRAINT_VIOLATION:
459        return INFO_RESULT_CONSTRAINT_VIOLATION.get();
460      case ATTRIBUTE_OR_VALUE_EXISTS:
461        return INFO_RESULT_ATTRIBUTE_OR_VALUE_EXISTS.get();
462      case INVALID_ATTRIBUTE_SYNTAX:
463        return INFO_RESULT_INVALID_ATTRIBUTE_SYNTAX.get();
464      case NO_SUCH_OBJECT:
465        return INFO_RESULT_NO_SUCH_OBJECT.get();
466      case ALIAS_PROBLEM:
467        return INFO_RESULT_ALIAS_PROBLEM.get();
468      case INVALID_DN_SYNTAX:
469        return INFO_RESULT_INVALID_DN_SYNTAX.get();
470      case ALIAS_DEREFERENCING_PROBLEM:
471        return INFO_RESULT_ALIAS_DEREFERENCING_PROBLEM.get();
472      case INAPPROPRIATE_AUTHENTICATION:
473        return INFO_RESULT_INAPPROPRIATE_AUTHENTICATION.get();
474      case INVALID_CREDENTIALS:
475        return INFO_RESULT_INVALID_CREDENTIALS.get();
476      case INSUFFICIENT_ACCESS_RIGHTS:
477        return INFO_RESULT_INSUFFICIENT_ACCESS_RIGHTS.get();
478      case BUSY:
479        return INFO_RESULT_BUSY.get();
480      case UNAVAILABLE:
481        return INFO_RESULT_UNAVAILABLE.get();
482      case UNWILLING_TO_PERFORM:
483        return INFO_RESULT_UNWILLING_TO_PERFORM.get();
484      case LOOP_DETECT:
485        return INFO_RESULT_LOOP_DETECT.get();
486      case SORT_CONTROL_MISSING:
487        return INFO_RESULT_SORT_CONTROL_MISSING.get();
488      case OFFSET_RANGE_ERROR:
489        return INFO_RESULT_OFFSET_RANGE_ERROR.get();
490      case NAMING_VIOLATION:
491        return INFO_RESULT_NAMING_VIOLATION.get();
492      case OBJECTCLASS_VIOLATION:
493        return INFO_RESULT_OBJECTCLASS_VIOLATION.get();
494      case NOT_ALLOWED_ON_NONLEAF:
495        return INFO_RESULT_NOT_ALLOWED_ON_NONLEAF.get();
496      case NOT_ALLOWED_ON_RDN:
497        return INFO_RESULT_NOT_ALLOWED_ON_RDN.get();
498      case ENTRY_ALREADY_EXISTS:
499        return INFO_RESULT_ENTRY_ALREADY_EXISTS.get();
500      case OBJECTCLASS_MODS_PROHIBITED:
501        return INFO_RESULT_OBJECTCLASS_MODS_PROHIBITED.get();
502      case AFFECTS_MULTIPLE_DSAS:
503        return INFO_RESULT_AFFECTS_MULTIPLE_DSAS.get();
504      case VIRTUAL_LIST_VIEW_ERROR:
505        return INFO_RESULT_VIRTUAL_LIST_VIEW_ERROR.get();
506      case CLIENT_SIDE_SERVER_DOWN:
507        return INFO_RESULT_CLIENT_SIDE_SERVER_DOWN.get();
508      case CLIENT_SIDE_LOCAL_ERROR:
509        return INFO_RESULT_CLIENT_SIDE_LOCAL_ERROR.get();
510      case CLIENT_SIDE_ENCODING_ERROR:
511        return INFO_RESULT_CLIENT_SIDE_ENCODING_ERROR.get();
512      case CLIENT_SIDE_DECODING_ERROR:
513        return INFO_RESULT_CLIENT_SIDE_DECODING_ERROR.get();
514      case CLIENT_SIDE_TIMEOUT:
515        return INFO_RESULT_CLIENT_SIDE_TIMEOUT.get();
516      case CLIENT_SIDE_AUTH_UNKNOWN:
517        return INFO_RESULT_CLIENT_SIDE_AUTH_UNKNOWN.get();
518      case CLIENT_SIDE_FILTER_ERROR:
519        return INFO_RESULT_CLIENT_SIDE_FILTER_ERROR.get();
520      case CLIENT_SIDE_USER_CANCELLED:
521        return INFO_RESULT_CLIENT_SIDE_USER_CANCELLED.get();
522      case CLIENT_SIDE_PARAM_ERROR:
523        return INFO_RESULT_CLIENT_SIDE_PARAM_ERROR.get();
524      case CLIENT_SIDE_NO_MEMORY:
525        return INFO_RESULT_CLIENT_SIDE_NO_MEMORY.get();
526      case CLIENT_SIDE_CONNECT_ERROR:
527        return INFO_RESULT_CLIENT_SIDE_CONNECT_ERROR.get();
528      case CLIENT_SIDE_NOT_SUPPORTED:
529        return INFO_RESULT_CLIENT_SIDE_NOT_SUPPORTED.get();
530      case CLIENT_SIDE_CONTROL_NOT_FOUND:
531        return INFO_RESULT_CLIENT_SIDE_CONTROL_NOT_FOUND.get();
532      case CLIENT_SIDE_NO_RESULTS_RETURNED:
533        return INFO_RESULT_CLIENT_SIDE_NO_RESULTS_RETURNED.get();
534      case CLIENT_SIDE_MORE_RESULTS_TO_RETURN:
535        return INFO_RESULT_CLIENT_SIDE_MORE_RESULTS_TO_RETURN.get();
536      case CLIENT_SIDE_CLIENT_LOOP:
537        return INFO_RESULT_CLIENT_SIDE_CLIENT_LOOP.get();
538      case CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED:
539        return INFO_RESULT_CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED.get();
540      case CANCELED:
541        return INFO_RESULT_CANCELED.get();
542      case NO_SUCH_OPERATION:
543        return INFO_RESULT_NO_SUCH_OPERATION.get();
544      case TOO_LATE:
545        return INFO_RESULT_TOO_LATE.get();
546      case CANNOT_CANCEL:
547        return INFO_RESULT_CANNOT_CANCEL.get();
548      case ASSERTION_FAILED:
549        return INFO_RESULT_ASSERTION_FAILED.get();
550      case AUTHORIZATION_DENIED:
551        return INFO_RESULT_AUTHORIZATION_DENIED.get();
552      case NO_OPERATION:
553        return INFO_RESULT_NO_OPERATION.get();
554      default:
555        return INFO_RESULT_OTHER.get();
556    }
557  }
558}