mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

vharseko
16.43.2024 dd1841195f67fc79787673d6c1dbd9ae84306315
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2012-2016 ForgeRock AS.
 */
package org.opends.dsml.protocol;
 
import java.util.HashMap;
 
/**
 * A utility class to help creating ResultCode objects containing a
 * code value (integer) and a descr value (String).
 */
public class ResultCodeFactory
{
  static final HashMap<Integer, LDAPResultCode> codeToDescr = new HashMap<>();
  static
  {
    codeToDescr.put(0, LDAPResultCode.SUCCESS);
    codeToDescr.put(1, LDAPResultCode.OPERATIONS_ERROR);
    codeToDescr.put(2, LDAPResultCode.PROTOCOL_ERROR);
    codeToDescr.put(3, LDAPResultCode.TIME_LIMIT_EXCEEDED);
    codeToDescr.put(4, LDAPResultCode.SIZE_LIMIT_EXCEEDED);
    codeToDescr.put(5, LDAPResultCode.COMPARE_FALSE);
    codeToDescr.put(6, LDAPResultCode.COMPARE_TRUE);
    codeToDescr.put(7, LDAPResultCode.AUTH_METHOD_NOT_SUPPORTED);
    // Note not STRONGER_AUTH_REQUIRED, that's the RFC 4511 name
    codeToDescr.put(8, LDAPResultCode.STRONG_AUTH_REQUIRED);
    codeToDescr.put(10, LDAPResultCode.REFERRAL);
    codeToDescr.put(11, LDAPResultCode.ADMIN_LIMIT_EXCEEDED);
    codeToDescr.put(12, LDAPResultCode.UNAVAILABLE_CRITICAL_EXTENSION);
    codeToDescr.put(13, LDAPResultCode.CONFIDENTIALITY_REQUIRED);
    codeToDescr.put(14, LDAPResultCode.SASL_BIND_IN_PROGRESS);
    codeToDescr.put(16, LDAPResultCode.NO_SUCH_ATTRIBUTE);
    codeToDescr.put(17, LDAPResultCode.UNDEFINED_ATTRIBUTE_TYPE);
    codeToDescr.put(18, LDAPResultCode.INAPPROPRIATE_MATCHING);
    codeToDescr.put(19, LDAPResultCode.CONSTRAINT_VIOLATION);
    codeToDescr.put(20, LDAPResultCode.ATTRIBUTE_OR_VALUE_EXISTS);
    codeToDescr.put(21, LDAPResultCode.INVALID_ATTRIBUTE_SYNTAX);
    codeToDescr.put(32, LDAPResultCode.NO_SUCH_OBJECT);
    codeToDescr.put(33, LDAPResultCode.ALIAS_PROBLEM);
    codeToDescr.put(34, LDAPResultCode.INVALID_DN_SYNTAX);
    codeToDescr.put(36, LDAPResultCode.ALIAS_DEREFERENCING_PROBLEM);
    codeToDescr.put(48, LDAPResultCode.INAPPROPRIATE_AUTHENTICATION);
    codeToDescr.put(49, LDAPResultCode.INVALID_CREDENTIALS);
    codeToDescr.put(50, LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS);
    codeToDescr.put(51, LDAPResultCode.BUSY);
    codeToDescr.put(52, LDAPResultCode.UNAVAILABLE);
    codeToDescr.put(53, LDAPResultCode.UNWILLING_TO_PERFORM);
    codeToDescr.put(54, LDAPResultCode.LOOP_DETECT);
    codeToDescr.put(64, LDAPResultCode.NAMING_VIOLATION);
    codeToDescr.put(65, LDAPResultCode.OBJECT_CLASS_VIOLATION);
    codeToDescr.put(66, LDAPResultCode.NOT_ALLOWED_ON_NON_LEAF);
    codeToDescr.put(67, LDAPResultCode.NOT_ALLOWED_ON_RDN);
    codeToDescr.put(68, LDAPResultCode.ENTRY_ALREADY_EXISTS);
    codeToDescr.put(69, LDAPResultCode.OBJECT_CLASS_MODS_PROHIBITED);
    // Note not AFFECTS_MULTIPLE_DSAS, xjc mangles the string.
    codeToDescr.put(71, LDAPResultCode.AFFECT_MULTIPLE_DS_AS);
    codeToDescr.put(80, LDAPResultCode.OTHER);
  }
 
  /**
   * Create a ResultCode object that contains the resultCode, and, if valid,
   * a text description (from RFC 2251) of the resultCode.
   *
   * @param objFactory
   *                  The JAXB factory used to create the underlying object.
   * @param resultCode
   *                  The LDAP result code.
   * @return A ResultCode object with a code and possibly a description.
   */
  public static ResultCode create(ObjectFactory objFactory, int resultCode)
  {
    ResultCode result = objFactory.createResultCode();
    result.setCode(resultCode);
    Integer r = Integer.valueOf(resultCode);
    if (ResultCodeFactory.codeToDescr.containsKey(r))
    {
      result.setDescr(ResultCodeFactory.codeToDescr.get(r));
    }
    return result;
  }
}