jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 27771 360714d431ab
child 34687 d302ed125dc9
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
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) 2000, 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: 488
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: 488
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: 488
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 488
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 488
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.auth.kerberos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.security.auth.Refreshable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.security.auth.Destroyable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.security.auth.RefreshFailedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.security.auth.DestroyFailedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This class encapsulates a Kerberos ticket and associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * information as viewed from the client's point of view. It captures all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * information that the Key Distribution Center (KDC) sends to the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * in the reply message KDC-REP defined in the Kerberos Protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Specification (<a href=http://www.ietf.org/rfc/rfc4120.txt>RFC 4120</a>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * All Kerberos JAAS login modules that authenticate a user to a KDC should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * use this class. Where available, the login module might even read this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * information from a ticket cache in the operating system instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * directly communicating with the KDC. During the commit phase of the JAAS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * authentication process, the JAAS login module should instantiate this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * class and store the instance in the private credential set of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link javax.security.auth.Subject Subject}.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * It might be necessary for the application to be granted a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * {@link javax.security.auth.PrivateCredentialPermission
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
    56
 * PrivateCredentialPermission} if it needs to access a {@code KerberosTicket}
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
    57
 * instance from a {@code Subject}. This permission is not needed when the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * application depends on the default JGSS Kerberos mechanism to access the
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
    59
 * {@code KerberosTicket}. In that case, however, the application will need an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@link javax.security.auth.kerberos.ServicePermission ServicePermission}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Note that this class is applicable to both ticket granting tickets and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * other regular service tickets. A ticket granting ticket is just a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * special case of a more generalized service ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see javax.security.auth.Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see javax.security.auth.login.LoginContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see org.ietf.jgss.GSSCredential
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @see org.ietf.jgss.GSSManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @author Mayank Upadhyay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public class KerberosTicket implements Destroyable, Refreshable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final long serialVersionUID = 7395334370157380539L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // XXX Make these flag indices public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final int FORWARDABLE_TICKET_FLAG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final int FORWARDED_TICKET_FLAG   = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final int PROXIABLE_TICKET_FLAG   = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final int PROXY_TICKET_FLAG       = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final int POSTDATED_TICKET_FLAG   = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final int RENEWABLE_TICKET_FLAG   = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final int INITIAL_TICKET_FLAG     = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final int NUM_FLAGS = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * ASN.1 DER Encoding of the Ticket as defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Kerberos Protocol Specification RFC4120.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private byte[] asn1Encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   103
     *{@code KeyImpl} is serialized by writing out the ASN1 Encoded bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * of the encryption key. The ASN1 encoding is defined in RFC4120 and as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * EncryptionKey   ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *          keytype    [0] Int32 -- actually encryption type --,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *          keyvalue   [1] OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private KeyImpl sessionKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Ticket Flags as defined in the Kerberos Protocol Specification RFC4120.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private boolean[] flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Time of initial authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private Date authTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Time after which the ticket is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private Date startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Time after which the ticket will not be honored. (its expiration time).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private Date endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * For renewable Tickets it indicates the maximum endtime that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * included in a renewal. It can be thought of as the absolute expiration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * time for the ticket, including all renewals. This field may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * for tickets that are not renewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private Date renewTill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Client that owns the service ticket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private KerberosPrincipal client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * The service for which the ticket was issued.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private KerberosPrincipal server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * The addresses from where the ticket may be used by the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * This field may be null when the ticket is usable from any address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private InetAddress[] clientAddresses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private transient boolean destroyed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   196
     * Constructs a {@code KerberosTicket} using credentials information that a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * client either receives from a KDC or reads from a cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param asn1Encoding the ASN.1 encoding of the ticket as defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * the Kerberos protocol specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param client the client that owns this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * ticket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param server the service that this ticket is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param sessionKey the raw bytes for the session key that must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * used to encrypt the authenticator that will be sent to the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param keyType the key type for the session key as defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Kerberos protocol specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param flags the ticket flags. Each element in this array indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the value for the corresponding bit in the ASN.1 BitString that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * represents the ticket flags. If the number of elements in this array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * is less than the number of flags used by the Kerberos protocol,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * then the missing flags will be filled in with false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param authTime the time of initial authentication for the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param startTime the time after which the ticket will be valid. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * may be null in which case the value of authTime is treated as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * startTime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param endTime the time after which the ticket will no longer be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param renewTill an absolute expiration time for the ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * including all renewal that might be possible. This field may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * for tickets that are not renewable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param clientAddresses the addresses from where the ticket may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * used by the client. This field may be null when the ticket is usable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * from any address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public KerberosTicket(byte[] asn1Encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                         KerberosPrincipal client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                         KerberosPrincipal server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                         byte[] sessionKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                         int keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                         boolean[] flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                         Date authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                         Date startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                         Date endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                         Date renewTill,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                         InetAddress[] clientAddresses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        init(asn1Encoding, client, server, sessionKey, keyType, flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            authTime, startTime, endTime, renewTill, clientAddresses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private void init(byte[] asn1Encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                         KerberosPrincipal client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                         KerberosPrincipal server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                         byte[] sessionKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                         int keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                         boolean[] flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                         Date authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                         Date startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                         Date endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                         Date renewTill,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                         InetAddress[] clientAddresses) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   253
        if (sessionKey == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   254
            throw new IllegalArgumentException("Session key for ticket"
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   255
                    + " cannot be null");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   256
        }
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   257
        init(asn1Encoding, client, server,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   258
             new KeyImpl(sessionKey, keyType), flags, authTime,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   259
             startTime, endTime, renewTill, clientAddresses);
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   260
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   262
    private void init(byte[] asn1Encoding,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   263
                         KerberosPrincipal client,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   264
                         KerberosPrincipal server,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   265
                         KeyImpl sessionKey,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   266
                         boolean[] flags,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   267
                         Date authTime,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   268
                         Date startTime,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   269
                         Date endTime,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   270
                         Date renewTill,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   271
                         InetAddress[] clientAddresses) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   272
        if (asn1Encoding == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   273
            throw new IllegalArgumentException("ASN.1 encoding of ticket"
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   274
                    + " cannot be null");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   275
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        this.asn1Encoding = asn1Encoding.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   278
        if (client == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   279
            throw new IllegalArgumentException("Client name in ticket"
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   280
                    + " cannot be null");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   281
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        this.client = client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   284
        if (server == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   285
            throw new IllegalArgumentException("Server name in ticket"
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   286
                    + " cannot be null");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   287
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        this.server = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   290
        // Caller needs to make sure `sessionKey` will not be null
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   291
        this.sessionKey = sessionKey;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (flags != null) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   294
           if (flags.length >= NUM_FLAGS) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   295
               this.flags = flags.clone();
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   296
           } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                this.flags = new boolean[NUM_FLAGS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                // Fill in whatever we have
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   299
                for (int i = 0; i < flags.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    this.flags[i] = flags[i];
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   301
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
           }
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   303
        } else {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   304
            this.flags = new boolean[NUM_FLAGS];
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   305
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (this.flags[RENEWABLE_TICKET_FLAG]) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   308
           if (renewTill == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   309
               throw new IllegalArgumentException("The renewable period "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                       + "end time cannot be null for renewable tickets.");
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   311
           }
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   312
           this.renewTill = new Date(renewTill.getTime());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   315
        if (authTime != null) {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   316
            this.authTime = new Date(authTime.getTime());
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   317
        }
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   318
        if (startTime != null) {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   319
            this.startTime = new Date(startTime.getTime());
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   320
        } else {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   321
            this.startTime = this.authTime;
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   322
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   324
        if (endTime == null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   325
            throw new IllegalArgumentException("End time for ticket validity"
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   326
                    + " cannot be null");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   327
        }
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   328
        this.endTime = new Date(endTime.getTime());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   330
        if (clientAddresses != null) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   331
            this.clientAddresses = clientAddresses.clone();
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   332
        }
2
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
     * Returns the client principal associated with this ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return the client principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public final KerberosPrincipal getClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Returns the service principal associated with this ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return the service principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public final KerberosPrincipal getServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   354
     * Returns the session key associated with this ticket. The return value
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   355
     * is always a {@link EncryptionKey} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @return the session key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public final SecretKey getSessionKey() {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   360
        if (destroyed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw new IllegalStateException("This ticket is no longer valid");
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   362
        }
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   363
        return new EncryptionKey(
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   364
                sessionKey.getEncoded(), sessionKey.getKeyType());
2
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
     * Returns the key type of the session key associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * ticket as defined by the Kerberos Protocol Specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return the key type of the session key associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see #getSessionKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public final int getSessionKeyType() {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   377
        if (destroyed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            throw new IllegalStateException("This ticket is no longer valid");
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   379
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return sessionKey.getKeyType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Determines if this ticket is forwardable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return true if this ticket is forwardable, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public final boolean isForwardable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return flags[FORWARDABLE_TICKET_FLAG];
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
     * Determines if this ticket had been forwarded or was issued based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * authentication involving a forwarded ticket-granting ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @return true if this ticket had been forwarded or was issued based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * authentication involving a forwarded ticket-granting ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public final boolean isForwarded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return flags[FORWARDED_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Determines if this ticket is proxiable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @return true if this ticket is proxiable, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public final boolean isProxiable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return flags[PROXIABLE_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Determines is this ticket is a proxy-ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return true if this ticket is a proxy-ticket, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public final boolean isProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return flags[PROXY_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Determines is this ticket is post-dated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @return true if this ticket is post-dated, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public final boolean isPostdated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return flags[POSTDATED_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Determines is this ticket is renewable. If so, the {@link #refresh()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * refresh} method can be called, assuming the validity period for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * renewing is not already over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return true if this ticket is renewable, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public final boolean isRenewable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return flags[RENEWABLE_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Determines if this ticket was issued using the Kerberos AS-Exchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * protocol, and not issued based on some ticket-granting ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return true if this ticket was issued using the Kerberos AS-Exchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * protocol, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public final boolean isInitial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return flags[INITIAL_TICKET_FLAG];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns the flags associated with this ticket. Each element in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * returned array indicates the value for the corresponding bit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * ASN.1 BitString that represents the ticket flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @return the flags associated with this ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public final boolean[]  getFlags() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   462
        return (flags == null? null: flags.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Returns the time that the client was authenticated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @return the time that the client was authenticated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *         or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public final java.util.Date getAuthTime() {
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   472
        return (authTime == null) ? null : (Date)authTime.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Returns the start time for this ticket's validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @return the start time for this ticket's validity period
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *         or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public final java.util.Date getStartTime() {
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   482
        return (startTime == null) ? null : (Date)startTime.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Returns the expiration time for this ticket's validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return the expiration time for this ticket's validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public final java.util.Date getEndTime() {
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   491
        return (Date) endTime.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Returns the latest expiration time for this ticket, including all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * renewals. This will return a null value for non-renewable tickets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return the latest expiration time for this ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public final java.util.Date getRenewTill() {
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   501
        return (renewTill == null) ? null: (Date)renewTill.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Returns a list of addresses from where the ticket can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @return ths list of addresses or null, if the field was not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public final java.net.InetAddress[] getClientAddresses() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   511
        return (clientAddresses == null) ? null: clientAddresses.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Returns an ASN.1 encoding of the entire ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @return an ASN.1 encoding of the entire ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public final byte[] getEncoded() {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   520
        if (destroyed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            throw new IllegalStateException("This ticket is no longer valid");
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   522
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   523
        return asn1Encoding.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /** Determines if this ticket is still current.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public boolean isCurrent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return (System.currentTimeMillis() <= getEndTime().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Extends the validity period of this ticket. The ticket will contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * a new session key if the refresh operation succeeds. The refresh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * operation will fail if the ticket is not renewable or the latest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * allowable renew time has passed. Any other error returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * KDC will also cause this method to fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27771
diff changeset
   538
     * Note: This method is not synchronized with the accessor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * methods of this object. Hence callers need to be aware of multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * threads that might access this and try to renew it at the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @throws RefreshFailedException if the ticket is not renewable, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * the latest allowable renew time has passed, or the KDC returns some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @see #isRenewable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @see #getRenewTill()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public void refresh() throws RefreshFailedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   552
        if (destroyed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            throw new RefreshFailedException("A destroyed ticket "
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   554
                    + "cannot be renewd.");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   555
        }
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   556
        if (!isRenewable()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            throw new RefreshFailedException("This ticket is not renewable");
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   558
        }
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   559
        if (System.currentTimeMillis() > getRenewTill().getTime()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            throw new RefreshFailedException("This ticket is past "
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   561
                                           + "its last renewal time.");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   562
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        Throwable e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        sun.security.krb5.Credentials krb5Creds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            krb5Creds = new sun.security.krb5.Credentials(asn1Encoding,
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   568
                                                    client.getName(),
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   569
                                                    server.getName(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                                    sessionKey.getEncoded(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                    sessionKey.getKeyType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                                    flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                                    authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                                    startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                                    endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                                    renewTill,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                                    clientAddresses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            krb5Creds = krb5Creds.renew();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        } catch (sun.security.krb5.KrbException krbException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            e = krbException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        } catch (java.io.IOException ioException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            e = ioException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (e != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            RefreshFailedException rfException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                = new RefreshFailedException("Failed to renew Kerberos Ticket "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                             + "for client " + client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                                             + " and server " + server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                             + " - " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            rfException.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            throw rfException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
         * In case multiple threads try to refresh it at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                this.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            } catch (DestroyFailedException dfException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                // Squelch it since we don't care about the old ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            init(krb5Creds.getEncoded(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                 new KerberosPrincipal(krb5Creds.getClient().getName()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                 new KerberosPrincipal(krb5Creds.getServer().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                        KerberosPrincipal.KRB_NT_SRV_INST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                 krb5Creds.getSessionKey().getBytes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                 krb5Creds.getSessionKey().getEType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                 krb5Creds.getFlags(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                 krb5Creds.getAuthTime(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                 krb5Creds.getStartTime(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                 krb5Creds.getEndTime(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                 krb5Creds.getRenewTill(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                 krb5Creds.getClientAddresses());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            destroyed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * Destroys the ticket and destroys any sensitive information stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public void destroy() throws DestroyFailedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (!destroyed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            Arrays.fill(asn1Encoding, (byte) 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            client = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            sessionKey.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            flags = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            authTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            startTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            endTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            renewTill = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            clientAddresses = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            destroyed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * Determines if this ticket has been destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public boolean isDestroyed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return destroyed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   647
    /**
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   648
     * Returns an informative textual representation of this {@code KerberosTicket}.
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   649
     *
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   650
     * @return an informative textual representation of this {@code KerberosTicket}.
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   651
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public String toString() {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   653
        if (destroyed) {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   654
            return "Destroyed KerberosTicket";
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   655
        }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 18830
diff changeset
   656
        StringBuilder caddrString = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (clientAddresses != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            for (int i = 0; i < clientAddresses.length; i++) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 18830
diff changeset
   659
                caddrString.append("clientAddresses[" + i + "] = " +
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 18830
diff changeset
   660
                        clientAddresses[i].toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return ("Ticket (hex) = " + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                 (new HexDumpEncoder()).encodeBuffer(asn1Encoding) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                "Client Principal = " + client.toString() + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                "Server Principal = " + server.toString() + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                "Session Key = " + sessionKey.toString() + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                "Forwardable Ticket " + flags[FORWARDABLE_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                "Forwarded Ticket " + flags[FORWARDED_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                "Proxiable Ticket " + flags[PROXIABLE_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                "Proxy Ticket " + flags[PROXY_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                "Postdated Ticket " + flags[POSTDATED_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                "Renewable Ticket " + flags[RENEWABLE_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                "Initial Ticket " + flags[RENEWABLE_TICKET_FLAG] + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                "Auth Time = " + String.valueOf(authTime) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                "Start Time = " + String.valueOf(startTime) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                "End Time = " + endTime.toString() + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                "Renew Till = " + String.valueOf(renewTill) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                "Client Addresses " +
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 18830
diff changeset
   680
                (clientAddresses == null ? " Null " : caddrString.toString() +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                "\n"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /**
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   685
     * Returns a hash code for this {@code KerberosTicket}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   687
     * @return a hash code for this {@code KerberosTicket}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (isDestroyed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        result = result * 37 + Arrays.hashCode(getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        result = result * 37 + endTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        result = result * 37 + client.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        result = result * 37 + server.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        result = result * 37 + sessionKey.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // authTime may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (authTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            result = result * 37 + authTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        // startTime may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (startTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            result = result * 37 + startTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // renewTill may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (renewTill != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            result = result * 37 + renewTill.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        // clientAddress may be null, the array's hashCode is 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        result = result * 37 + Arrays.hashCode(clientAddresses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        return result * 37 + Arrays.hashCode(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   722
     * Compares the specified object with this {@code KerberosTicket} for equality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Returns true if the given object is also a
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   724
     * {@code KerberosTicket} and the two
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   725
     * {@code KerberosTicket} instances are equivalent.
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   726
     * A destroyed {@code KerberosTicket} object is only equal to itself.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     *
27771
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   728
     * @param other the object to compare to
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   729
     * @return true if the specified object is equal to this {@code KerberosTicket},
360714d431ab 8061253: Spec cleanup for some security-related classes
weijun
parents: 25859
diff changeset
   730
     * false otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   735
        if (other == this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            return true;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   737
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (! (other instanceof KerberosTicket)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        KerberosTicket otherTicket = ((KerberosTicket) other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (isDestroyed() || otherTicket.isDestroyed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        if (!Arrays.equals(getEncoded(), otherTicket.getEncoded()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                !endTime.equals(otherTicket.getEndTime()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                !server.equals(otherTicket.getServer()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                !client.equals(otherTicket.getClient()) ||
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   752
                !sessionKey.equals(otherTicket.sessionKey) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                !Arrays.equals(clientAddresses, otherTicket.getClientAddresses()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                !Arrays.equals(flags, otherTicket.getFlags())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        // authTime may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if (authTime == null) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   760
            if (otherTicket.getAuthTime() != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   762
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        } else {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   764
            if (!authTime.equals(otherTicket.getAuthTime())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   766
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        // startTime may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (startTime == null) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   771
            if (otherTicket.getStartTime() != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   773
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        } else {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   775
            if (!startTime.equals(otherTicket.getStartTime())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   777
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (renewTill == null) {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   781
            if (otherTicket.getRenewTill() != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   783
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        } else {
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   785
            if (!renewTill.equals(otherTicket.getRenewTill())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                return false;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   787
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   792
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   793
    private void readObject(ObjectInputStream s)
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents: 24969
diff changeset
   794
            throws IOException, ClassNotFoundException {
488
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   795
        s.defaultReadObject();
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   796
        if (sessionKey == null) {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   797
           throw new InvalidObjectException("Session key cannot be null");
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   798
        }
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   799
        try {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   800
            init(asn1Encoding, client, server, sessionKey,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   801
                 flags, authTime, startTime, endTime,
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   802
                 renewTill, clientAddresses);
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   803
        } catch (IllegalArgumentException iae) {
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   804
            throw (InvalidObjectException)
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   805
                new InvalidObjectException(iae.getMessage()).initCause(iae);
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   806
        }
5e84e13e8892 6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents: 51
diff changeset
   807
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
}