Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/KrbException.java
41159 views
/*1* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*27* (C) Copyright IBM Corp. 1999 All Rights Reserved.28* Copyright 1997 The Open Group Research Institute. All rights reserved.29*/3031package sun.security.krb5;3233import sun.security.krb5.internal.Krb5;34import sun.security.krb5.internal.KRBError;3536public class KrbException extends Exception {3738private static final long serialVersionUID = -4993302876451928596L;3940private int returnCode;41private KRBError error;4243public KrbException(String s) {44super(s);45}4647public KrbException(Throwable cause) {48super(cause);49}5051public KrbException(int i) {52returnCode = i;53}5455public KrbException(int i, String s) {56this(s);57returnCode = i;58}5960public KrbException(KRBError e) {61returnCode = e.getErrorCode();62error = e;63}6465public KrbException(KRBError e, String s) {66this(s);67returnCode = e.getErrorCode();68error = e;69}7071public KRBError getError() {72return error;73}747576public int returnCode() {77return returnCode;78}7980public String returnCodeSymbol() {81return returnCodeSymbol(returnCode);82}8384public static String returnCodeSymbol(int i) {85return "not yet implemented";86}8788public String returnCodeMessage() {89return Krb5.getErrorMessage(returnCode);90}9192public static String errorMessage(int i) {93return Krb5.getErrorMessage(i);94}959697public String krbErrorMessage() {98StringBuilder sb = new StringBuilder();99sb.append("krb_error ").append(returnCode);100String msg = getMessage();101if (msg != null) {102sb.append(" ");103sb.append(msg);104}105return sb.toString();106}107108/**109* Returns messages like:110* "Integrity check on decrypted field failed (31) - \111* Could not decrypt service ticket"112* If the error code is 0 then the first half is skipped.113*/114public String getMessage() {115StringBuilder message = new StringBuilder();116int returnCode = returnCode();117if (returnCode != 0) {118message.append(returnCodeMessage());119message.append(" (").append(returnCode()).append(')');120}121String consMessage = super.getMessage();122if (consMessage != null && consMessage.length() != 0) {123if (returnCode != 0)124message.append(" - ");125message.append(consMessage);126}127return message.toString();128}129130public String toString() {131return ("KrbException: " + getMessage());132}133134@Override public int hashCode() {135int result = 17;136result = 37 * result + returnCode;137if (error != null) {138result = 37 * result + error.hashCode();139}140return result;141}142143@Override public boolean equals(Object obj) {144if (this == obj) {145return true;146}147148if (!(obj instanceof KrbException)) {149return false;150}151152KrbException other = (KrbException)obj;153if (returnCode != other.returnCode) {154return false;155}156return (error == null)?(other.error == null):157(error.equals(other.error));158}159}160161162