src/java.security.sasl/share/classes/javax/security/sasl/SaslException.java
author mbalao
Tue, 12 Nov 2019 12:36:16 -0300
changeset 59036 642d7d7ed426
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233946: Add @since 13 annotation to KerberosPrincipal.KRB_NT_ENTERPRISE field Reviewed-by: clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.security.sasl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class represents an error that has occurred when using SASL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Rob Weltman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class SaslException extends IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * The possibly null root cause exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // Required for serialization interoperability with JSR 28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private Throwable _exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    48
     * Constructs a new instance of {@code SaslException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * The root exception and the detailed message are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public SaslException () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    56
     * Constructs a new instance of {@code SaslException} with a detailed message.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * The root exception is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param detail A possibly null string containing details of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @see java.lang.Throwable#getMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public SaslException (String detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(detail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    67
     * Constructs a new instance of {@code SaslException} with a detailed message
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * and a root exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * For example, a SaslException might result from a problem with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * the callback handler, which might throw a NoSuchCallbackException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * it does not support the requested callback, or throw an IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * if it had problems obtaining data for the callback. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * SaslException's root exception would be then be the exception thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * by the callback handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param detail A possibly null string containing details of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param ex A possibly null root exception that caused this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @see java.lang.Throwable#getMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @see #getCause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public SaslException (String detail, Throwable ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        super(detail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (ex != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            initCause(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Override Throwable.getCause() to ensure deserialized object from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * JSR 28 would return same value for getCause() (i.e., _exception).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public Throwable getCause() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return _exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Override Throwable.initCause() to match getCause() by updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * _exception as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public Throwable initCause(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        super.initCause(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        _exception = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the string representation of this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * The string representation contains
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18830
diff changeset
   110
     * this exception's class name, its detailed message, and if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * it has a root exception, the string representation of the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * exception. This string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * is meant for debugging and not meant to be interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * programmatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return The non-null string representation of this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see java.lang.Throwable#getMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // Override Throwable.toString() to conform to JSR 28
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        String answer = super.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (_exception != null && _exception != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            answer += " [Caused by " + _exception.toString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /** Use serialVersionUID from JSR 28 RI for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final long serialVersionUID = 4579784287983423626L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}