1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.server.kerberos.shared.exceptions;
21
22
23 /**
24 * The root of the Kerberos exception hierarchy.
25 *
26 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27 * @version $Rev: 542350 $, $Date: 2007-05-29 00:24:16 +0200 (Di, 29 Mai 2007) $
28 */
29 public class KerberosException extends Exception
30 {
31 private static final long serialVersionUID = 2968072183596955597L;
32
33 /**
34 * The Kerberos error code associated with this exception.
35 */
36 private final int errorCode;
37
38 /**
39 * Additional data about the error for use by the application
40 * to help it recover from or handle the error.
41 */
42 private byte[] explanatoryData;
43
44
45 /**
46 * Creates a KerberosException with an {@link ErrorType}.
47 *
48 * @param errorType The error type associated with this KerberosException.
49 */
50 public KerberosException( ErrorType errorType )
51 {
52 super( errorType.getMessage() );
53
54 this.errorCode = errorType.getOrdinal();
55 }
56
57
58 /**
59 * Creates a KerberosException with an {@link ErrorType} and an
60 * underlying {@link Throwable} that caused this fault.
61 *
62 * @param errorType The error type associated with this KerberosException.
63 * @param cause The underlying failure, if any.
64 */
65 public KerberosException( ErrorType errorType, Throwable cause )
66 {
67 super( errorType.getMessage(), cause );
68
69 this.errorCode = errorType.getOrdinal();
70 }
71
72
73 /**
74 * Creates a KerberosException with an {@link ErrorType} and a custom error message.
75 *
76 * @param errorType The {@link ErrorType} associated with this KerberosException.
77 * @param msg A custom error message for this KerberosException.
78 */
79 public KerberosException( ErrorType errorType, String msg )
80 {
81 super( msg );
82
83 this.errorCode = errorType.getOrdinal();
84 }
85
86
87 /**
88 * Creates a KerberosException with an {@link ErrorType}, a custom error message, and an
89 * underlying {@link Throwable} that caused this fault.
90 *
91 * @param errorType The error type associated with this KerberosException.
92 * @param msg A custom error message for this KerberosException.
93 * @param cause The underlying failure, if any.
94 */
95 public KerberosException( ErrorType errorType, String msg, Throwable cause )
96 {
97 super( msg, cause );
98
99 this.errorCode = errorType.getOrdinal();
100 }
101
102
103 /**
104 * Creates a KerberosException with an {@link ErrorType} and data helping to
105 * explain what caused this fault.
106 *
107 * @param errorType The error type associated with this KerberosException.
108 * @param explanatoryData Data helping to explain this fault, if any.
109 */
110 public KerberosException( ErrorType errorType, byte[] explanatoryData )
111 {
112 super( errorType.getMessage() );
113
114 this.errorCode = errorType.getOrdinal();
115 this.explanatoryData = explanatoryData;
116 }
117
118
119 /**
120 * Creates a KerberosException with an {@link ErrorType}, data helping to
121 * explain what caused this fault, and an underlying {@link Throwable} that caused this fault.
122 *
123 * @param errorType The error type associated with this KerberosException.
124 * @param explanatoryData Data helping to explain this fault, if any.
125 * @param cause The underlying failure, if any.
126 */
127 public KerberosException( ErrorType errorType, byte[] explanatoryData, Throwable cause )
128 {
129 super( errorType.getMessage(), cause );
130
131 this.errorCode = errorType.getOrdinal();
132 this.explanatoryData = explanatoryData;
133 }
134
135
136 /**
137 * Gets the protocol error code associated with this KerberosException.
138 *
139 * @return The error code associated with this KerberosException.
140 */
141 public int getErrorCode()
142 {
143 return this.errorCode;
144 }
145
146
147 /**
148 * Gets the explanatory data associated with this KerberosException.
149 *
150 * @return The explanatory data associated with this KerberosException.
151 */
152 public byte[] getExplanatoryData()
153 {
154 return explanatoryData;
155 }
156
157
158 /**
159 * Creates a KerberosException with an error code and a message.
160 *
161 * @param errorCode The error code associated with this KerberosException.
162 * @param msg The standard Kerberos error message for this KerberosException.
163 */
164 protected KerberosException( int errorCode, String msg )
165 {
166 super( msg );
167
168 this.errorCode = errorCode;
169 }
170
171
172 /**
173 * Creates a KerberosException with an error code, a message and an
174 * underlying {@link Throwable} that caused this fault.
175 *
176 * @param errorCode The error code associated with this KerberosException.
177 * @param msg The standard Kerberos error message for this KerberosException.
178 * @param cause The underlying failure, if any.
179 */
180 protected KerberosException( int errorCode, String msg, Throwable cause )
181 {
182 super( msg, cause );
183
184 this.errorCode = errorCode;
185 }
186
187
188 /**
189 * Creates a KerberosException with an error code, a message, and data
190 * helping to explain what caused this fault.
191 *
192 * @param errorCode The error code associated with this KerberosException.
193 * @param msg The standard Kerberos error message for this KerberosException.
194 * @param explanatoryData Data helping to explain this fault, if any.
195 */
196 protected KerberosException( int errorCode, String msg, byte[] explanatoryData )
197 {
198 super( msg );
199
200 this.errorCode = errorCode;
201 this.explanatoryData = explanatoryData;
202 }
203
204
205 /**
206 * Creates a KerberosException with an error code, a message, and data
207 * helping to explain what caused this fault.
208 *
209 * @param errorCode The error code associated with this KerberosException.
210 * @param msg The standard Kerberos error message for this KerberosException.
211 * @param explanatoryData Data helping to explain this fault, if any.
212 * @param cause The underlying failure, if any.
213 */
214 protected KerberosException( int errorCode, String msg, byte[] explanatoryData, Throwable cause )
215 {
216 super( msg, cause );
217
218 this.errorCode = errorCode;
219 this.explanatoryData = explanatoryData;
220 }
221 }