001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.kerberos.shared.exceptions;
021
022
023 /**
024 * The root of the Kerberos exception hierarchy.
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 * @version $Rev: 542350 $, $Date: 2007-05-29 01:24:16 +0300 (Tue, 29 May 2007) $
028 */
029 public class KerberosException extends Exception
030 {
031 private static final long serialVersionUID = 2968072183596955597L;
032
033 /**
034 * The Kerberos error code associated with this exception.
035 */
036 private final int errorCode;
037
038 /**
039 * Additional data about the error for use by the application
040 * to help it recover from or handle the error.
041 */
042 private byte[] explanatoryData;
043
044
045 /**
046 * Creates a KerberosException with an {@link ErrorType}.
047 *
048 * @param errorType The error type associated with this KerberosException.
049 */
050 public KerberosException( ErrorType errorType )
051 {
052 super( errorType.getMessage() );
053
054 this.errorCode = errorType.getOrdinal();
055 }
056
057
058 /**
059 * Creates a KerberosException with an {@link ErrorType} and an
060 * underlying {@link Throwable} that caused this fault.
061 *
062 * @param errorType The error type associated with this KerberosException.
063 * @param cause The underlying failure, if any.
064 */
065 public KerberosException( ErrorType errorType, Throwable cause )
066 {
067 super( errorType.getMessage(), cause );
068
069 this.errorCode = errorType.getOrdinal();
070 }
071
072
073 /**
074 * Creates a KerberosException with an {@link ErrorType} and a custom error message.
075 *
076 * @param errorType The {@link ErrorType} associated with this KerberosException.
077 * @param msg A custom error message for this KerberosException.
078 */
079 public KerberosException( ErrorType errorType, String msg )
080 {
081 super( msg );
082
083 this.errorCode = errorType.getOrdinal();
084 }
085
086
087 /**
088 * Creates a KerberosException with an {@link ErrorType}, a custom error message, and an
089 * underlying {@link Throwable} that caused this fault.
090 *
091 * @param errorType The error type associated with this KerberosException.
092 * @param msg A custom error message for this KerberosException.
093 * @param cause The underlying failure, if any.
094 */
095 public KerberosException( ErrorType errorType, String msg, Throwable cause )
096 {
097 super( msg, cause );
098
099 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 }