2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
*
|
|
28 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved.
|
|
29 |
* Copyright 1997 The Open Group Research Institute. All rights reserved.
|
|
30 |
*/
|
|
31 |
|
|
32 |
package sun.security.krb5;
|
|
33 |
|
|
34 |
import sun.security.krb5.internal.Krb5;
|
|
35 |
import sun.security.krb5.internal.KRBError;
|
|
36 |
|
|
37 |
public class KrbException extends Exception {
|
|
38 |
|
|
39 |
private static final long serialVersionUID = -4993302876451928596L;
|
|
40 |
|
|
41 |
private int returnCode;
|
|
42 |
private KRBError error;
|
|
43 |
|
|
44 |
public KrbException(String s) {
|
|
45 |
super(s);
|
|
46 |
}
|
|
47 |
|
|
48 |
public KrbException(int i) {
|
|
49 |
returnCode = i;
|
|
50 |
}
|
|
51 |
|
|
52 |
public KrbException(int i, String s) {
|
|
53 |
this(s);
|
|
54 |
returnCode = i;
|
|
55 |
}
|
|
56 |
|
|
57 |
public KrbException(KRBError e) {
|
|
58 |
returnCode = e.getErrorCode();
|
|
59 |
error = e;
|
|
60 |
}
|
|
61 |
|
|
62 |
public KrbException(KRBError e, String s) {
|
|
63 |
this(s);
|
|
64 |
returnCode = e.getErrorCode();
|
|
65 |
error = e;
|
|
66 |
}
|
|
67 |
|
|
68 |
public KRBError getError() {
|
|
69 |
return error;
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
public int returnCode() {
|
|
74 |
return returnCode;
|
|
75 |
}
|
|
76 |
|
|
77 |
public String returnCodeSymbol() {
|
|
78 |
return returnCodeSymbol(returnCode);
|
|
79 |
}
|
|
80 |
|
|
81 |
public static String returnCodeSymbol(int i) {
|
|
82 |
return "not yet implemented";
|
|
83 |
}
|
|
84 |
|
|
85 |
public String returnCodeMessage() {
|
|
86 |
return Krb5.getErrorMessage(returnCode);
|
|
87 |
}
|
|
88 |
|
|
89 |
public static String errorMessage(int i) {
|
|
90 |
return Krb5.getErrorMessage(i);
|
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
public String krbErrorMessage() {
|
|
95 |
StringBuffer strbuf = new StringBuffer("krb_error " + returnCode);
|
|
96 |
String msg = getMessage();
|
|
97 |
if (msg != null) {
|
|
98 |
strbuf.append(" ");
|
|
99 |
strbuf.append(msg);
|
|
100 |
}
|
|
101 |
return strbuf.toString();
|
|
102 |
}
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Returns messages like:
|
|
106 |
* "Integrity check on decrypted field failed (31) - \
|
|
107 |
* Could not decrypt service ticket"
|
|
108 |
* If the error code is 0 then the first half is skipped.
|
|
109 |
*/
|
|
110 |
public String getMessage() {
|
|
111 |
StringBuffer message = new StringBuffer();
|
|
112 |
int returnCode = returnCode();
|
|
113 |
if (returnCode != 0) {
|
|
114 |
message.append(returnCodeMessage());
|
|
115 |
message.append(" (").append(returnCode()).append(')');
|
|
116 |
}
|
|
117 |
String consMessage = super.getMessage();
|
|
118 |
if (consMessage != null && consMessage.length() != 0) {
|
|
119 |
if (returnCode != 0)
|
|
120 |
message.append(" - ");
|
|
121 |
message.append(consMessage);
|
|
122 |
}
|
|
123 |
return message.toString();
|
|
124 |
}
|
|
125 |
|
|
126 |
public String toString() {
|
|
127 |
return ("KrbException: " + getMessage());
|
|
128 |
}
|
|
129 |
|
|
130 |
@Override public int hashCode() {
|
|
131 |
int result = 17;
|
|
132 |
result = 37 * result + returnCode;
|
|
133 |
if (error != null) {
|
|
134 |
result = 37 * result + error.hashCode();
|
|
135 |
}
|
|
136 |
return result;
|
|
137 |
}
|
|
138 |
|
|
139 |
@Override public boolean equals(Object obj) {
|
|
140 |
if (this == obj) {
|
|
141 |
return true;
|
|
142 |
}
|
|
143 |
|
|
144 |
if (!(obj instanceof KrbException)) {
|
|
145 |
return false;
|
|
146 |
}
|
|
147 |
|
|
148 |
KrbException other = (KrbException)obj;
|
|
149 |
if (returnCode != other.returnCode) {
|
|
150 |
return false;
|
|
151 |
}
|
|
152 |
return (error == null)?(other.error == null):
|
|
153 |
(error.equals(other.error));
|
|
154 |
}
|
|
155 |
}
|