Reset branch to trunk.
[official-gcc.git] / trunk / libjava / classpath / org / ietf / jgss / GSSException.java
blob9c352e3e937e54fa51fea1b5435ed145ecd3a8a9
1 /* GSSException.java -- a general exception in GSS.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version.
38 The documentation comments of this class are derived from the text
39 of RFC 2853: Generic Security Service API Version 2: Java Bindings.
40 That document is covered under the following license notice:
42 Copyright (C) The Internet Society (2000). All Rights Reserved.
44 This document and translations of it may be copied and furnished to
45 others, and derivative works that comment on or otherwise explain it
46 or assist in its implementation may be prepared, copied, published and
47 distributed, in whole or in part, without restriction of any kind,
48 provided that the above copyright notice and this paragraph are
49 included on all such copies and derivative works. However, this
50 document itself may not be modified in any way, such as by removing
51 the copyright notice or references to the Internet Society or other
52 Internet organizations, except as needed for the purpose of developing
53 Internet standards in which case the procedures for copyrights defined
54 in the Internet Standards process must be followed, or as required to
55 translate it into languages other than English.
57 The limited permissions granted above are perpetual and will not be
58 revoked by the Internet Society or its successors or assigns.
60 This document and the information contained herein is provided on an
61 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
62 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
63 NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN
64 WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
65 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. */
68 package org.ietf.jgss;
70 import java.util.PropertyResourceBundle;
71 import java.util.ResourceBundle;
73 /**
74 * This exception is thrown whenever a fatal GSS-API error occurs
75 * including mechanism specific errors. It may contain both, the major
76 * and minor, GSS-API status codes. The mechanism implementers are
77 * responsible for setting appropriate minor status codes when throwing
78 * this exception. Aside from delivering the numeric error code(s) to
79 * the caller, this class performs the mapping from their numeric values
80 * to textual representations. All Java GSS-API methods are declared
81 * throwing this exception.
83 * @specnote Some of the constant values defined in this class were
84 * chosen to be compatible with J2SE 1.4, and not with RFC 2853.
86 public class GSSException extends Exception
88 /**
89 * For compatability with Sun's JDK 1.4.2 rev. 5
91 private static final long serialVersionUID = -2706218945227726672L;
93 // Constants and fields.
94 // -------------------------------------------------------------------------
96 /**
97 * Channel bindings mismatch error.
98 * @specnote Should be 4 according to RFC 2853.
100 public static final int BAD_BINDINGS = 1;
103 * Unsupported mechanism requested error.
104 * @specnote Should be 1 according to RFC 2853.
106 public static final int BAD_MECH = 2;
109 * Invalid name provided error.
110 * @specnote Should be 2 according to RFC 2853.
112 public static final int BAD_NAME = 3;
115 * Name of unsupported type provided error.
116 * @specnote Should be 3 according to RFC 2853.
118 public static final int BAD_NAMETYPE = 4;
121 * Invalid status code error - this is the default status value.
123 public static final int BAD_STATUS = 5;
126 * Token had invalid integrity check error.
128 public static final int BAD_MIC = 6;
131 * Specified security context expired error.
132 * @specnote Should be 12 according to RFC 2853.
134 public static final int CONTEXT_EXPIRED = 7;
137 * Expired credentials detected error.
138 * @specnote Should be 11 according to RFC 2853.
140 public static final int CREDENTIALS_EXPIRED = 8;
143 * Defective credential error.
144 * @specnote Should be 10 according to RFC 2853.
146 public static final int DEFECTIVE_CREDENTIAL = 9;
149 * Defective token error.
150 * @specnote Should be 9 according to RFC 2853.
152 public static final int DEFECTIVE_TOKEN = 10;
155 * General failure, unspecified at GSS-API level.
156 * @specnote Should be 13 according to RFC 2853.
158 public static final int FAILURE = 11;
161 * Invalid security context error.
162 * @specnote Should be 8 according to RFC 2853.
164 public static final int NO_CONTEXT = 12;
167 * Invalid credentials error.
168 * @specnote Should be 7 according to RFC 2853.
170 public static final int NO_CRED = 13;
173 * Unsupported QOP value error.
175 public static final int BAD_QOP = 14;
178 * Operation unauthorized error.
180 public static final int UNAUTHORIZED = 15;
183 * Operation unavailable error.
185 public static final int UNAVAILABLE = 16;
188 * Duplicate credential element requested error.
190 public static final int DUPLICATE_ELEMENT = 17;
193 * Name contains multi-mechanism elements error.
195 public static final int NAME_NOT_MN = 18;
198 * The token was a duplicate of an earlier token. This is a fatal error
199 * code that may occur during context establishment. It is not used to
200 * indicate supplementary status values. The MessageProp object is used
201 * for that purpose.
202 * @specnote Should be 20 according to RFC 2853.
204 public static final int DUPLICATE_TOKEN = 19;
207 * The token's validity period has expired. This is a fatal error code
208 * that may occur during context establishment. It is not used to
209 * indicate supplementary status values. The MessageProp object is used
210 * for that purpose.
211 * @specnote Should be 19 according to RFC 2853.
213 public static final int OLD_TOKEN = 20;
216 * A later token has already been processed. This is a fatal error code
217 * that may occur during context establishment. It is not used to
218 * indicate supplementary status values. The MessageProp object is used
219 * for that purpose.
221 public static final int UNSEQ_TOKEN = 21;
224 * An expected per-message token was not received. This is a fatal
225 * error code that may occur during context establishment. It is not
226 * used to indicate supplementary status values. The MessageProp object
227 * is used for that purpose.
229 public static final int GAP_TOKEN = 22;
231 private final int major;
232 private int minor;
233 private String minorString;
235 private ResourceBundle messages;
237 // Constructors.
238 // -------------------------------------------------------------------------
241 * Create a new GSS exception with the given major code.
243 * @param major The major GSS error code.
245 public GSSException(int major)
247 this(major, 0, null);
251 * Create a new GSS exception with the given major and minor codes, and a
252 * minor explanation string.
254 * @param major The major GSS error code.
255 * @param minor The minor application-specific error code.
256 * @param minorString An explanation of the minor error code.
258 public GSSException(int major, int minor, String minorString)
260 this.major = major;
261 this.minor = minor;
262 this.minorString = minorString;
265 messages = PropertyResourceBundle.getBundle("org/ietf/jgss/MessagesBundle");
267 catch (Exception e)
269 messages = null;
273 // Instance methods.
274 // -------------------------------------------------------------------------
277 * Returns the major code representing the GSS error code that caused
278 * this exception to be thrown.
280 * @return The major error code.
282 public int getMajor()
284 return major;
288 * Returns the mechanism error code that caused this exception. The
289 * minor code is set by the underlying mechanism. Value of 0 indicates
290 * that mechanism error code is not set.
292 * @return The minor error code, or 0 if not set.
294 public int getMinor()
296 return minor;
300 * Returns a string explaining the GSS major error code causing this
301 * exception to be thrown.
303 * @return The major error string.
305 public String getMajorString()
307 switch (major)
309 case BAD_MECH:
310 return getMsg("GSSException.BAD_MECH",
311 "An unsupported mechanism was requested.");
312 case BAD_NAME:
313 return getMsg("GSSException.BAD_NAME",
314 "An invalid name was supplied.");
315 case BAD_NAMETYPE:
316 return getMsg("GSSException.BAD_NAMETYPE",
317 "A supplied name was of an unsupported type.");
318 case BAD_BINDINGS:
319 return getMsg("GSSException.BAD_BINDINGS",
320 "Incorrect channel bindings were supplied.");
321 case BAD_STATUS:
322 return getMsg("GSSException.BAD_STATUS",
323 "An invalid status code was supplied.");
324 case BAD_MIC:
325 return getMsg("GSSException.BAD_MIC",
326 "A token had an invalid MIC.");
327 case NO_CRED:
328 return getMsg("GSSException.NO_CRED",
329 "No credentials were supplied, or the credentials were "+
330 "unavailable or inaccessible.");
331 case NO_CONTEXT:
332 return getMsg("GSSException.NO_CONTEXT",
333 "Invalid context has been supplied.");
334 case DEFECTIVE_TOKEN:
335 return getMsg("GSSException.DEFECTIVE_TOKEN",
336 "A supplied token was invalid.");
337 case DEFECTIVE_CREDENTIAL:
338 return getMsg("GSSException.DEFECTIVE_CREDENTIAL",
339 "A supplied credential was invalid.");
340 case CREDENTIALS_EXPIRED:
341 return getMsg("GSSException.CREDENTIALS_EXPIRED",
342 "The referenced credentials have expired.");
343 case CONTEXT_EXPIRED:
344 return getMsg("GSSException.CONTEXT_EXPIRED",
345 "The context has expired.");
346 case FAILURE:
347 return getMsg("GSSException.FAILURE",
348 "Miscellaneous failure.");
349 case BAD_QOP:
350 return getMsg("GSSException.BAD_QOP",
351 "The quality-of-protection requested could not be provided.");
352 case UNAUTHORIZED:
353 return getMsg("GSSException.UNAUTHORIZED",
354 "The operation is forbidden by local security policy.");
355 case UNAVAILABLE:
356 return getMsg("GSSException.UNAVAILABLE",
357 "The operation or option is unavailable.");
358 case DUPLICATE_ELEMENT:
359 return getMsg("GSSException.DUPLICATE_ELEMENT",
360 "The requested credential element already exists.");
361 case NAME_NOT_MN:
362 return getMsg("GSSException.NAME_NOT_MN",
363 "The provided name was not a mechanism name.");
364 case OLD_TOKEN:
365 return getMsg("GSSException.OLD_TOKEN",
366 "The token's validity period has expired.");
367 case DUPLICATE_TOKEN:
368 return getMsg("GSSException.DUPLICATE_TOKEN",
369 "The token was a duplicate of an earlier version.");
370 case UNSEQ_TOKEN:
371 return getMsg("GSSException.UNSEQ_TOKEN",
372 "A later token has already been processed.");
373 case GAP_TOKEN:
374 return getMsg("GSSException.GAP_TOKEN",
375 "An expected per-message token was not received.");
376 default: return "Unknown or invalid error code.";
381 * Returns a string explaining the mechanism specific error code.
382 * <code>null</code> will be returned when no mechanism error code has
383 * been set.
385 * @return The minor error string, or <code>null</code>.
387 public String getMinorString()
389 return minorString;
393 * Used internally by the GSS-API implementation and the underlying
394 * mechanisms to set the minor code and its textual representation.
396 * @param minorCode The mechanism specific error code.
397 * @param message A textual explanation of the mechanism error code.
399 public void setMinor(int minorCode, String message)
401 this.minor = minorCode;
402 this.minorString = message;
406 * Returns a textual representation of both the major and minor status
407 * codes.
409 * @return The textual representation.
411 public String toString()
413 return GSSException.class.getName() + ": " + getMessage();
417 * Returns a detailed message of this exception. Overrides {@link
418 * Throwable#getMessage()}. It is customary in Java to use this method to
419 * obtain exception information.
421 * @return The detail message.
423 public String getMessage()
425 if (minor == 0)
426 return getMajorString();
427 else
428 return getMajorString() + " (" + minorString + ")";
431 // Own methods.
432 // -------------------------------------------------------------------------
434 private String getMsg(String key, String defaultText)
436 if (messages != null)
440 return messages.getString(key);
442 catch (Exception e)
446 return defaultText;