Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/client/opers/JDAPResult.java

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is mozilla.org code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38 package org.ietf.ldap.client.opers;
39
40 import java.io.IOException;
41
42 import org.ietf.ldap.ber.stream.BERElement;
43 import org.ietf.ldap.ber.stream.BEREnumerated;
44 import org.ietf.ldap.ber.stream.BEROctetString;
45 import org.ietf.ldap.ber.stream.BERSequence;
46 import org.ietf.ldap.ber.stream.BERTag;
47
48 /**
49 * This class implements the ldap result where stores
50 * the request status. It is the base class for all
51 * the response except search response. This object is
52 * sent from the server to the client interface.
53 * <pre>
54 * LDAPResult ::= SEQUENCE {
55 * resultCode ENUMERATED {
56 * success (0),
57 * ...
58 * },
59 * matchedDN LDAPDN,
60 * errorMessage LDAPString
61 * }
62 * </pre>
63 *
64 * Note that LDAPv3 supports referral within the LDAP
65 * Result. The added component is:
66 *
67 * <pre>
68 * LDAPResult ::= SEQUENCE {
69 * ...
70 * errorMessage LDAPString,
71 * referral [3] Referral OPTIONAL
72 * }
73 * </pre>
74 *
75 */
76 public class JDAPResult {
77 /**
78 * Result code based on RFC1777
79 */
80 public final static int SUCCESS = 0;
81 public final static int OPERATION_ERROR = 1;
82 public final static int PROTOCOL_ERROR = 2;
83 public final static int TIME_LIMIT_EXCEEDED = 3;
84 public final static int SIZE_LIMIT_EXCEEDED = 4;
85 public final static int COMPARE_FALSE = 5;
86 public final static int COMPARE_TRUE = 6;
87 public final static int AUTH_METHOD_NOT_SUPPORTED = 7;
88 public final static int STRONG_AUTH_REQUIRED = 8;
89 /* Referrals Within the LDAPv2 Protocol */
90 public final static int LDAP_PARTIAL_RESULTS = 9;
91 /* Added for LDAPv3 - BEGIN */
92 public final static int REFERRAL = 10;
93 public final static int ADMIN_LIMIT_EXCEEDED = 11;
94 public final static int UNAVAILABLE_CRITICAL_EXTENSION = 12;
95 public final static int CONFIDENTIALITY_REQUIRED = 13;
96 public final static int SASL_BIND_IN_PROGRESS = 14;
97 /* Added for LDAPv3 - END */
98 public final static int NO_SUCH_ATTRIBUTE = 16;
99 public final static int UNDEFINED_ATTRIBUTE_TYPE = 17;
100 public final static int INAPPROPRIATE_MATCHING = 18;
101 public final static int CONSTRAINT_VIOLATION = 19;
102 public final static int ATTRIBUTE_OR_VALUE_EXISTS = 20;
103 public final static int INVALID_ATTRIBUTE_SYNTAX = 21;
104 public final static int NO_SUCH_OBJECT = 32;
105 public final static int ALIAS_PROBLEM = 33;
106 public final static int INVALID_DN_SYNTAX = 34;
107 public final static int IS_LEAF = 35;
108 public final static int ALIAS_DEREFERENCING_PROBLEM = 36;
109 public final static int INAPPROPRIATE_AUTHENTICATION = 48;
110 public final static int INVALID_CREDENTIALS = 49;
111 public final static int INSUFFICIENT_ACCESS_RIGHTS = 50;
112 public final static int BUSY = 51;
113 public final static int UNAVAILABLE = 52;
114 public final static int UNWILLING_TO_PERFORM = 53;
115 public final static int LOOP_DETECT = 54;
116 public final static int NAMING_VIOLATION = 64;
117 public final static int OBJECT_CLASS_VIOLATION = 65;
118 public final static int NOT_ALLOWED_ON_NONLEAF = 66;
119 public final static int NOT_ALLOWED_ON_RDN = 67;
120 public final static int ENTRY_ALREADY_EXISTS = 68;
121 public final static int OBJECT_CLASS_MODS_PROHIBITED = 69;
122 public final static int AFFECTS_MULTIPLE_DSAS = 71;
123 public final static int OTHER = 80;
124 public final static int SERVER_DOWN = 81;
125 public final static int PARAM_ERROR = 89;
126 public final static int CONNECT_ERROR = 91;
127 public final static int LDAP_NOT_SUPPORTED = 92;
128 public final static int CONTROL_NOT_FOUND = 93;
129 public final static int NO_RESULTS_RETURNED = 94;
130 public final static int MORE_RESULTS_TO_RETURN = 95;
131 public final static int CLIENT_LOOP = 96;
132 public final static int REFERRAL_LIMIT_EXCEEDED = 97;
133
134 /**
135 * Private variable
136 */
137 protected BERElement m_element = null;
138 protected int m_result_code;
139 protected String m_matched_dn = null;
140 protected String m_error_message = null;
141 protected String m_referrals[] = null;
142
143 /**
144 * Constructs ldap result.
145 * @param element ber element
146 */
147 public JDAPResult(BERElement element) throws IOException {
148 /* Result from a successful bind request.
149 * [*] umich-ldap-v3.3
150 * 0x0a 0x07 (implicit [APPLICATION 1] OctetString)
151 * 0x0a 0x01 0x00 (result code)
152 * 0x04 0x00 (matched dn)
153 * 0x04 0x00 (error message)
154 * Referrals in ldap-v2.0
155 * [*] umich-ldap-v3.3
156 * 0x65 0x2a
157 * 0x0a 0x01 0x09
158 * 0x04 0x00
159 * 0x04 0x23 R e f e r r a l : 0x0a
160 * l d a p : / / l d a p .
161 * i t d . u m i c h . e d u
162 */
163 m_element = element;
164 BERSequence seq = (BERSequence)element;
165 /*
166 * Possible return from [x500.arc.nasa.gov]:
167 * SEQUENCE {SEQUENCE {Enumerated{2} ... }}
168 */
169 BERElement e = seq.elementAt(0);
170 if (e.getType() == BERElement.SEQUENCE)
171 seq = (BERSequence)e;
172 m_result_code = ((BEREnumerated)seq.elementAt(0)).getValue();
173 byte buf[] = null;
174 buf = ((BEROctetString)seq.elementAt(1)).getValue();
175 if (buf == null)
176 m_matched_dn = null;
177 else {
178 try{
179 m_matched_dn = new String(buf, "UTF8");
180 } catch(Throwable x)
181 {}
182 }
183 buf = ((BEROctetString)seq.elementAt(2)).getValue();
184 if (buf == null)
185 m_error_message = null;
186 else {
187 try {
188 m_error_message = new String(buf, "UTF8");
189 } catch(Throwable x)
190 {}
191 }
192 /* 12/05/97 extract LDAPv3 referrals */
193 if (seq.size() >= 4) {
194 BERTag t = (BERTag)seq.elementAt(3);
195 BERElement v = t.getValue();
196 if (v.getType() == BERElement.INTEGER) {
197 /* MS - [CONTEXT-5] Integer {3} */
198 /* TBD */
199
200 // else if this element is BERSequence which contains referral information
201 } else if (v instanceof BERSequence) {
202 /* Netscape */
203 BERSequence rseq = (BERSequence)v;
204 if (rseq.size() > 0) {
205 m_referrals = new String[rseq.size()];
206 for (int i = 0; i < rseq.size(); i++) {
207 try{
208 m_referrals[i] = new
209 String(((BEROctetString)rseq.elementAt(i)).getValue(), "UTF8");
210 } catch(Throwable x)
211 {}
212 }
213 }
214 }
215 }
216 }
217
218 /**
219 * Gets the result code.
220 * @return result code
221 */
222 public int getResultCode() {
223 return m_result_code;
224 }
225
226 /**
227 * Gets the matched dn.
228 * @return matched dn
229 */
230 public String getMatchedDN() {
231 return m_matched_dn;
232 }
233
234 /**
235 * Gets the error message.
236 * @return error message
237 */
238 public String getErrorMessage() {
239 return m_error_message;
240 }
241
242 /**
243 * Retrieves referrals from the LDAP Result.
244 * @return list of referrals in URL format
245 */
246 public String[] getReferrals() {
247 return m_referrals;
248 }
249
250 /**
251 * Retrieves the ber representation of the result.
252 * @return ber representation of the result
253 */
254 public BERElement getBERElement() {
255 return m_element;
256 }
257
258 /**
259 * Retrieves string representation of the result. Usually,
260 * the inherited class calls this to retrieve the parameter
261 * string.
262 * @return string representation
263 */
264 public String getParamString() {
265 StringBuffer sb = new StringBuffer("{resultCode=");
266 sb.append(m_result_code);
267 if (m_matched_dn != null) {
268 sb.append(", matchedDN=");
269 sb.append(m_matched_dn);
270 }
271 if (m_error_message != null) {
272 sb.append(", errorMessage=");
273 sb.append(m_error_message);
274 }
275 if (m_referrals != null && m_referrals.length > 0) {
276 sb.append(", referrals=");
277 for (int i=0; i < m_referrals.length; i++) {
278 sb.append((i==0 ? "" : " "));
279 sb.append(m_referrals[i]);
280 }
281 }
282 sb.append("}");
283 return sb.toString();
284 }
285
286 /**
287 * Retrieves string representation of the result.
288 * @return string representation
289 */
290 public String toString() {
291 return "Result " + getParamString();
292 }
293 }