src/java.security.jgss/share/classes/org/ietf/jgss/GSSException.java
author weijun
Thu, 04 Jul 2019 07:25:47 +0800
changeset 55599 e6c430d4d217
parent 47216 71c04702a3d5
permissions -rw-r--r--
8226963: More clarification on possible sequencing error in GSSContext::unwrap Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29820
7a3f0268f55b 8076223: Rest of tidy warning in javax.security / java.security
avstepan
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, 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 org.ietf.jgss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This exception is thrown whenever a GSS-API error occurs, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * any mechanism specific error.  It may contain both the major and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * minor GSS-API status codes.  Major error codes are those defined at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * GSS-API level in this class. Minor error codes are mechanism specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * error codes that can provide additional information. The underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * mechanism implementation is responsible for setting appropriate minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * status codes when throwing this exception.  Aside from delivering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * numeric error codes to the caller, this class performs the mapping from
29820
7a3f0268f55b 8076223: Rest of tidy warning in javax.security / java.security
avstepan
parents: 25859
diff changeset
    37
 * their numeric values to textual representations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Mayank Upadhyay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class GSSException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final long serialVersionUID = -2706218945227726672L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Channel bindings mismatch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final int BAD_BINDINGS = 1; //start with 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Unsupported mechanism requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int BAD_MECH = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Invalid name provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static final int BAD_NAME = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Name of unsupported type provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final int BAD_NAMETYPE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Invalid status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * This is meant to be thrown by display_status which displays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * major/minor status when an incorrect status type is passed in to it!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final int BAD_STATUS = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Token had invalid integrity check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int BAD_MIC = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Security context expired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final int CONTEXT_EXPIRED = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Expired credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final int CREDENTIALS_EXPIRED  = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Defective credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final int DEFECTIVE_CREDENTIAL = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Defective token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final int DEFECTIVE_TOKEN = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * General failure, unspecified at GSS-API level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final int FAILURE = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Invalid security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final int NO_CONTEXT = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Invalid credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final int NO_CRED = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Unsupported QOP value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final int BAD_QOP = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Operation unauthorized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final int UNAUTHORIZED = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Operation unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static final int UNAVAILABLE = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Duplicate credential element requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final int DUPLICATE_ELEMENT = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Name contains multi-mechanism elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static final int NAME_NOT_MN = 18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * The token was a duplicate of an earlier token.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * This is a fatal error code that may occur during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * context establishment.  It is not used to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * supplementary status values. The MessageProp object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * used for that purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static final int DUPLICATE_TOKEN = 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * The token's validity period has expired.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * fatal error code that may occur during context establishment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * It is not used to indicate supplementary status values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * The MessageProp object is used for that purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final int OLD_TOKEN = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * A later token has already been processed.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * fatal error code that may occur during context establishment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * It is not used to indicate supplementary status values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * The MessageProp object is used for that purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static final int UNSEQ_TOKEN = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * An expected per-message token was not received.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * fatal error code that may occur during context establishment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * It is not used to indicate supplementary status values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * The MessageProp object is used for that purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static final int GAP_TOKEN = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static String[] messages = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        "Channel binding mismatch", // BAD_BINDINGS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        "Unsupported mechanism requested", // BAD_MECH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        "Invalid name provided", // BAD_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        "Name of unsupported type provided", //BAD_NAMETYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        "Invalid input status selector", // BAD_STATUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        "Token had invalid integrity check", // BAD_SIG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        "Specified security context expired", // CONTEXT_EXPIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        "Expired credentials detected", // CREDENTIALS_EXPIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        "Defective credential detected", // DEFECTIVE_CREDENTIAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        "Defective token detected", // DEFECTIVE_TOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        "Failure unspecified at GSS-API level", // FAILURE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        "Security context init/accept not yet called or context deleted",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                // NO_CONTEXT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        "No valid credentials provided", // NO_CRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        "Unsupported QOP value", // BAD_QOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        "Operation unauthorized", // UNAUTHORIZED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        "Operation unavailable", // UNAVAILABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        "Duplicate credential element requested", //DUPLICATE_ELEMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        "Name contains multi-mechanism elements", // NAME_NOT_MN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        "The token was a duplicate of an earlier token", //DUPLICATE_TOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        "The token's validity period has expired", //OLD_TOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        "A later token has already been processed", //UNSEQ_TOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        "An expected per-message token was not received", //GAP_TOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    * The major code for this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private int major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    * The minor code for this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private int minor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    * The text string for minor code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private String minorMessage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    * Alternate text string for major code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private String majorString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *  Creates a GSSException object with a specified major code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param majorCode the The GSS error code for the problem causing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * exception to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public GSSException (int majorCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (validateMajor(majorCode))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            major = majorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            major = FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Construct a GSSException object with a specified major code and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * specific major string for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param majorCode the fatal error code causing this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param majorString an expicit message to be included in this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    GSSException (int majorCode, String majorString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (validateMajor(majorCode))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            major = majorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            major = FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        this.majorString = majorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Creates a GSSException object with the specified major code, minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * code, and minor code textual explanation.  This constructor is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * used when the exception is originating from the underlying mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * level. It allows the setting of both the GSS code and the mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param majorCode the GSS error code for the problem causing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * exception to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param minorCode the mechanism level error code for the problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * causing this exception to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param minorString the textual explanation of the mechanism error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public GSSException (int majorCode, int minorCode, String minorString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (validateMajor(majorCode))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            major = majorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            major = FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        minor = minorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        minorMessage = minorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the GSS-API level major error code for the problem causing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * this exception to be thrown. Major error codes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * defined at the mechanism independent GSS-API level in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * class. Mechanism specific error codes that might provide more
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   294
     * information are set as the minor error code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return int the GSS-API level major error code causing this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see #getMajorString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #getMinor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see #getMinorString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public int getMajor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Returns the mechanism level error code for the problem causing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * exception to be thrown. The minor code is set by the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return int the mechanism error code; 0 indicates that it has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see #getMinorString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see #setMinor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public int  getMinor(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Returns a string explaining the GSS-API level major error code in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @return String explanation string for the major error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see #getMajor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see #toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public String getMajorString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (majorString != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            return majorString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return messages[major - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Returns a string explaining the mechanism specific error code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * If the minor status code is 0, then no mechanism level error details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * will be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @return String a textual explanation of mechanism error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see #getMinor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see #getMajorString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public String getMinorString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return minorMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Used by the exception thrower to set the mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * level minor error code and its string explanation.  This is used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * mechanism providers to indicate error details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param minorCode the mechanism specific error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param message textual explanation of the mechanism error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see #getMinor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public void setMinor(int minorCode, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        minor = minorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        minorMessage = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns a textual representation of both the major and the minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * status codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @return a String with the error descriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return ("GSSException: " + getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns a textual representation of both the major and the minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * status codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return a String with the error descriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (minor == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return (getMajorString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return (getMajorString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                + " (Mechanism level: " + getMinorString() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Validates the major code in the proper range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private boolean validateMajor(int major) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (major > 0 && major <= messages.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return (true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return (false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
}