KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ietf > jgss > GSSException


1 /*
2  * @(#)GSSException.java 1.11 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package org.ietf.jgss;
9
10 /**
11  * This exception is thrown whenever a GSS-API error occurs, including
12  * any mechanism specific error. It may contain both the major and the
13  * minor GSS-API status codes. Major error codes are those defined at the
14  * GSS-API level in this class. Minor error codes are mechanism specific
15  * error codes that can provide additional information. The underlying
16  * mechanism implementation is responsible for setting appropriate minor
17  * status codes when throwing this exception. Aside from delivering the
18  * numeric error codes to the caller, this class performs the mapping from
19  * their numeric values to textual representations. <p>
20  *
21  * @author Mayank Upadhyay
22  * @version 1.11, 12/19/03
23  * @since 1.4
24  */

25 public class GSSException extends Exception JavaDoc {
26
27     private static final long serialVersionUID = -2706218945227726672L;
28
29     /**
30      * Channel bindings mismatch.
31      */

32     public static final int BAD_BINDINGS = 1; //start with 1
33

34     /**
35      * Unsupported mechanism requested.
36      */

37     public static final int BAD_MECH = 2;
38
39     /**
40      * Invalid name provided.
41      */

42     public static final int BAD_NAME = 3;
43
44     /**
45      * Name of unsupported type provided.
46      */

47     public static final int BAD_NAMETYPE = 4;
48
49     /**
50      * Invalid status code.
51      */

52     /*
53      * This is meant to be thrown by display_status which displays
54      * major/minor status when an incorrect status type is passed in to it!
55      */

56     public static final int BAD_STATUS = 5;
57
58     /**
59      * Token had invalid integrity check.
60      */

61     public static final int BAD_MIC = 6;
62
63     /**
64      * Security context expired.
65      */

66     public static final int CONTEXT_EXPIRED = 7;
67
68     /**
69      * Expired credentials.
70      */

71     public static final int CREDENTIALS_EXPIRED = 8;
72
73     /**
74      * Defective credentials.
75      *
76      */

77     public static final int DEFECTIVE_CREDENTIAL = 9;
78
79     /**
80      * Defective token.
81      *
82      */

83     public static final int DEFECTIVE_TOKEN = 10;
84
85     /**
86      * General failure, unspecified at GSS-API level.
87      */

88     public static final int FAILURE = 11;
89
90     /**
91      * Invalid security context.
92      */

93     public static final int NO_CONTEXT = 12;
94
95     /**
96      * Invalid credentials.
97      */

98     public static final int NO_CRED = 13;
99         
100     /**
101      * Unsupported QOP value.
102      */

103     public static final int BAD_QOP = 14;
104
105     /**
106      * Operation unauthorized.
107      */

108     public static final int UNAUTHORIZED = 15;
109     
110     /**
111      * Operation unavailable.
112      */

113     public static final int UNAVAILABLE = 16;
114
115     /**
116      * Duplicate credential element requested.
117      */

118     public static final int DUPLICATE_ELEMENT = 17;
119
120     /**
121      * Name contains multi-mechanism elements.
122      */

123     public static final int NAME_NOT_MN = 18;
124
125     /**
126      * The token was a duplicate of an earlier token.
127      * This is a fatal error code that may occur during
128      * context establishment. It is not used to indicate
129      * supplementary status values. The MessageProp object is
130      * used for that purpose.
131      */

132     public static final int DUPLICATE_TOKEN = 19;
133
134     /**
135      * The token's validity period has expired. This is a
136      * fatal error code that may occur during context establishment.
137      * It is not used to indicate supplementary status values.
138      * The MessageProp object is used for that purpose.
139      */

140     public static final int OLD_TOKEN = 20;
141
142
143     /**
144      * A later token has already been processed. This is a
145      * fatal error code that may occur during context establishment.
146      * It is not used to indicate supplementary status values.
147      * The MessageProp object is used for that purpose.
148      */

149     public static final int UNSEQ_TOKEN = 21;
150
151     
152     /**
153      * An expected per-message token was not received. This is a
154      * fatal error code that may occur during context establishment.
155      * It is not used to indicate supplementary status values.
156      * The MessageProp object is used for that purpose.
157      */

158     public static final int GAP_TOKEN = 22;
159
160
161     private static String JavaDoc[] messages = {
162         "Channel binding mismatch", // BAD_BINDINGS
163
"Unsupported mechanism requested", // BAD_MECH
164
"Invalid name provided", // BAD_NAME
165
"Name of unsupported type provided", //BAD_NAMETYPE
166
"Invalid input status selector", // BAD_STATUS
167
"Token had invalid integrity check", // BAD_SIG
168
"Specified security context expired", // CONTEXT_EXPIRED
169
"Expired credentials detected", // CREDENTIALS_EXPIRED
170
"Defective credential detected", // DEFECTIVE_CREDENTIAL
171
"Defective token detected", // DEFECTIVE_TOKEN
172
"Failure unspecified at GSS-API level", // FAILURE
173
"Security context init/accept not yet called or context deleted",
174                         // NO_CONTEXT
175
"No valid credentials provided", // NO_CRED
176
"Unsupported QOP value", // BAD_QOP
177
"Operation unauthorized", // UNAUTHORIZED
178
"Operation unavailable", // UNAVAILABLE
179
"Duplicate credential element requested", //DUPLICATE_ELEMENT
180
"Name contains multi-mechanism elements", // NAME_NOT_MN
181
"The token was a duplicate of an earlier token", //DUPLICATE_TOKEN
182
"The token's validity period has expired", //OLD_TOKEN
183
"A later token has already been processed", //UNSEQ_TOKEN
184
"An expected per-message token was not received", //GAP_TOKEN
185
};
186
187    /**
188     * The major code for this exception
189     *
190     * @serial
191     */

192     private int major;
193
194    /**
195     * The minor code for this exception
196     *
197     * @serial
198     */

199     private int minor = 0;
200
201    /**
202     * The text string for minor code
203     *
204     * @serial
205     */

206     private String JavaDoc minorMessage = null;
207
208    /**
209     * Alternate text string for major code
210     *
211     * @serial
212     */

213
214     private String JavaDoc majorString = null;
215
216     /**
217      * Creates a GSSException object with a specified major code.
218      *
219      * @param majorCode the The GSS error code for the problem causing this
220      * exception to be thrown.
221      */

222     public GSSException (int majorCode) {
223         
224         if (validateMajor(majorCode))
225             major = majorCode;
226         else
227             major = FAILURE;
228     }
229
230     /**
231      * Construct a GSSException object with a specified major code and a
232      * specific major string for it.
233      *
234      * @param majorCode the fatal error code causing this exception.
235      * @param majorString an expicit message to be included in this exception
236      */

237     GSSException (int majorCode, String JavaDoc majorString) {
238         
239         if (validateMajor(majorCode))
240             major = majorCode;
241         else
242             major = FAILURE;
243     this.majorString = majorString;
244     }
245
246
247     /**
248      * Creates a GSSException object with the specified major code, minor
249      * code, and minor code textual explanation. This constructor is to be
250      * used when the exception is originating from the underlying mechanism
251      * level. It allows the setting of both the GSS code and the mechanism
252      * code.
253      *
254      * @param majorCode the GSS error code for the problem causing this
255      * exception to be thrown.
256      * @param minorCode the mechanism level error code for the problem
257      * causing this exception to be thrown.
258      * @param minorString the textual explanation of the mechanism error
259      * code.
260      */

261     public GSSException (int majorCode, int minorCode, String JavaDoc minorString) {
262         
263         if (validateMajor(majorCode))
264             major = majorCode;
265         else
266             major = FAILURE;
267
268         minor = minorCode;
269         minorMessage = minorString;
270     }
271
272     /**
273      * Returns the GSS-API level major error code for the problem causing
274      * this exception to be thrown. Major error codes are
275      * defined at the mechanism independent GSS-API level in this
276      * class. Mechanism specific error codes that might provide more
277      * information aer set as the minor error code.
278      *
279      * @return int the GSS-API level major error code causing this exception
280      * @see #getMajorString
281      * @see #getMinor
282      * @see #getMinorString
283      */

284     public int getMajor() {
285         return major;
286     }
287
288     /**
289      * Returns the mechanism level error code for the problem causing this
290      * exception to be thrown. The minor code is set by the underlying
291      * mechanism.
292      *
293      * @return int the mechanism error code; 0 indicates that it has not
294      * been set.
295      * @see #getMinorString
296      * @see #setMinor
297      */

298     public int getMinor(){
299         return minor;
300     }
301
302     /**
303      * Returns a string explaining the GSS-API level major error code in
304      * this exception.
305      *
306      * @return String explanation string for the major error code
307      * @see #getMajor
308      * @see #toString
309      */

310     public String JavaDoc getMajorString() {
311     
312     if (majorString != null)
313         return majorString;
314     else
315         return messages[major - 1];
316     }
317
318
319     /**
320      * Returns a string explaining the mechanism specific error code.
321      * If the minor status code is 0, then no mechanism level error details
322      * will be available.
323      *
324      * @return String a textual explanation of mechanism error code
325      * @see #getMinor
326      * @see #getMajorString
327      * @see #toString
328      */

329     public String JavaDoc getMinorString() {
330             
331         return minorMessage;
332     }
333
334
335     /**
336      * Used by the exception thrower to set the mechanism
337      * level minor error code and its string explanation. This is used by
338      * mechanism providers to indicate error details.
339      *
340      * @param minorCode the mechanism specific error code
341      * @param message textual explanation of the mechanism error code
342      * @see #getMinor
343      */

344     public void setMinor(int minorCode, String JavaDoc message) {
345     
346         minor = minorCode;
347         minorMessage = message;
348     }
349     
350
351     /**
352      * Returns a textual representation of both the major and the minor
353      * status codes.
354      *
355      * @return a String with the error descriptions
356      */

357     public String JavaDoc toString() {
358         return ("GSSException: " + getMessage());
359     }
360
361     /**
362      * Returns a textual representation of both the major and the minor
363      * status codes.
364      *
365      * @return a String with the error descriptions
366      */

367     public String JavaDoc getMessage() {
368         if (minor == 0)
369             return (getMajorString());
370         
371         return (getMajorString()
372         + " (Mechanism level: " + getMinorString() + ")");
373     }
374
375
376     /*
377      * Validates the major code in the proper range.
378      */

379     private boolean validateMajor(int major) {
380     
381         if (major > 0 && major <= messages.length)
382             return (true);
383             
384         return (false);
385     }
386 }
387
Popular Tags