jdk/src/share/classes/sun/security/krb5/Credentials.java
author jmelvin
Mon, 16 Apr 2012 18:09:53 -0400
changeset 12538 211d6e82fe51
parent 12423 a69d7fadb9f8
child 13247 74902cfeb9c6
permissions -rw-r--r--
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6 Summary: On Mac OS X, align system property "os.arch" with Apple legacy JDKs. Also, improve os.name string matching by using .contains() method instead of .startsWith(). This fix spans multiple repositories. Reviewed-by: dcubed, phh, ohair, katleman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12423
diff changeset
     2
 * Copyright (c) 2000, 2012, 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: 4336
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: 4336
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: 4336
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package sun.security.krb5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.internal.ccache.CredentialsCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.internal.crypto.EType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Date;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5974
diff changeset
    39
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class encapsulates the concept of a Kerberos service
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * credential. That includes a Kerberos ticket and an associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * session key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class Credentials {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    Ticket ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    PrincipalName client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    PrincipalName server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    EncryptionKey key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    TicketFlags flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    KerberosTime authTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    KerberosTime startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    KerberosTime endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    KerberosTime renewTill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    HostAddresses cAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    EncryptionKey serviceKey;
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    60
    AuthorizationData authzData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static CredentialsCache cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static boolean alreadyLoaded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static boolean alreadyTried = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static native Credentials acquireDefaultNativeCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public Credentials(Ticket new_ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                       PrincipalName new_client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                       PrincipalName new_server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                       EncryptionKey new_key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                       TicketFlags new_flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                       KerberosTime authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                       KerberosTime new_startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                       KerberosTime new_endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                       KerberosTime renewTill,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    76
                       HostAddresses cAddr,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    77
                       AuthorizationData authzData) {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    78
        this(new_ticket, new_client, new_server, new_key, new_flags,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    79
                authTime, new_startTime, new_endTime, renewTill, cAddr);
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    80
        this.authzData = authzData;
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    81
    }
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    82
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    83
    public Credentials(Ticket new_ticket,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    84
                       PrincipalName new_client,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    85
                       PrincipalName new_server,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    86
                       EncryptionKey new_key,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    87
                       TicketFlags new_flags,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    88
                       KerberosTime authTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    89
                       KerberosTime new_startTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    90
                       KerberosTime new_endTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    91
                       KerberosTime renewTill,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                       HostAddresses cAddr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        ticket = new_ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        client = new_client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        server = new_server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        key = new_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        flags = new_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.authTime = authTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        startTime = new_startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        endTime = new_endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.renewTill = renewTill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.cAddr = cAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public Credentials(byte[] encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                       String client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                       String server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                       byte[] keyBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                       int keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                       boolean[] flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                       Date authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                       Date startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                       Date endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                       Date renewTill,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                       InetAddress[] cAddrs) throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this(new Ticket(encoding),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             new PrincipalName(client, PrincipalName.KRB_NT_PRINCIPAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             new PrincipalName(server, PrincipalName.KRB_NT_SRV_INST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
             new EncryptionKey(keyType, keyBytes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             (flags == null? null: new TicketFlags(flags)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
             (authTime == null? null: new KerberosTime(authTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             (startTime == null? null: new KerberosTime(startTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             (endTime == null? null: new KerberosTime(endTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
             (renewTill == null? null: new KerberosTime(renewTill)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
             null); // caddrs are in the encoding at this point
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
     * Acquires a service ticket for the specified service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * principal. If the service ticket is not already available, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * obtains a new one from the KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Credentials(Credentials tgt, PrincipalName service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public final PrincipalName getClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public final PrincipalName getServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public final EncryptionKey getSessionKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public final Date getAuthTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (authTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return authTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public final Date getStartTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (startTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                return startTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public final Date getEndTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (endTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                return endTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public final Date getRenewTill() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (renewTill != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return renewTill.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public final boolean[] getFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (flags == null) // Can be in a KRB-CRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return flags.toBooleanArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public final InetAddress[] getClientAddresses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (cAddr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return cAddr.getInetAddresses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public final byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        byte[] retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            retVal = ticket.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } catch (Asn1Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            System.out.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            System.out.println(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public boolean isForwardable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return flags.get(Krb5.TKT_OPTS_FORWARDABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public boolean isRenewable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return flags.get(Krb5.TKT_OPTS_RENEWABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public Ticket getTicket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public TicketFlags getTicketFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   227
    public AuthorizationData getAuthzData() {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   228
        return authzData;
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   229
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Checks if the service ticket returned by the KDC has the OK-AS-DELEGATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * flag set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return true if OK-AS_DELEGATE flag is set, otherwise, return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public boolean checkDelegate() {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   236
        return flags.get(Krb5.TKT_OPTS_DELEGATE);
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   237
    }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   238
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   239
    /**
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   240
     * Reset TKT_OPTS_DELEGATE to false, called at credentials acquirement
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   241
     * when one of the cross-realm TGTs does not have the OK-AS-DELEGATE
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   242
     * flag set. This info must be preservable and restorable through
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   243
     * the Krb5Util.credsToTicket/ticketToCreds() methods so that even if
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   244
     * the service ticket is cached it still remembers the cross-realm
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   245
     * authentication result.
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   246
     */
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   247
    public void resetDelegate() {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   248
        flags.set(Krb5.TKT_OPTS_DELEGATE, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public Credentials renew() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        KDCOptions options = new KDCOptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        options.set(KDCOptions.RENEW, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         * Added here to pass KrbKdcRep.check:73
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        options.set(KDCOptions.RENEWABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return new KrbTgsReq(options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                             this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                             server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                             null, // from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                             null, // till
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                             null, // rtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                             null, // eTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                             cAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                             null).sendAndGetCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns a TGT for the given client principal from a ticket cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param princ the client principal. A value of null means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * default principal name in the credentials cache will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param ticketCache the path to the tickets file. A value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * of null will be accepted to indicate that the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * path should be searched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @returns the TGT credentials or null if none were found. If the tgt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * expired, it is the responsibility of the caller to determine this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public static Credentials acquireTGTFromCache(PrincipalName princ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                  String ticketCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (ticketCache == null) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   288
            // The default ticket cache on Windows and Mac is not a file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            String os = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        new sun.security.action.GetPropertyAction("os.name"));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   291
            if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12423
diff changeset
   292
                    os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                Credentials creds = acquireDefaultCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                if (creds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        System.out.println(">>> Found no TGT's in LSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                if (princ != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    if (creds.getClient().equals(princ)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                            System.out.println(">>> Obtained TGT from LSA: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                               + creds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                            System.out.println(">>> LSA contains TGT for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                               + creds.getClient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                               + " not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                               + princ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        System.out.println(">>> Obtained TGT from LSA: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                           + creds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * Returns the appropriate cache. If ticketCache is null, it is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * default cache otherwise it is the cache filename contained in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        CredentialsCache ccache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            CredentialsCache.getInstance(princ, ticketCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   333
        if (ccache == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return null;
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   335
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        sun.security.krb5.internal.ccache.Credentials tgtCred  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            ccache.getDefaultCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   340
        if (tgtCred == null) {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   341
            return null;
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   342
        }
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   343
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (EType.isSupported(tgtCred.getEType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return tgtCred.setKrbCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    ">>> unsupported key type found the default TGT: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    tgtCred.getEType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Acquires default credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <br>The possible locations for default credentials cache is searched in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <li> The directory and cache file name specified by "KRB5CCNAME" system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <li> The directory and cache file name specified by "KRB5CCNAME"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * environment variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <li> A cache file named krb5cc_{user.name} at {user.home} directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @return a <code>KrbCreds</code> object if the credential is found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    // this method is intentionally changed to not check if the caller's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    // principal name matches cache file's principal name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    // It assumes that the GSS call has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    // the privilege to access the default cache file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public static synchronized Credentials acquireDefaultCreds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        Credentials result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (cache == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            cache = CredentialsCache.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            sun.security.krb5.internal.ccache.Credentials temp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                cache.getDefaultCreds();
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   385
            if (temp != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if (DEBUG) {
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   387
                    System.out.println(">>> KrbCreds found the default ticket"
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   388
                            + " granting ticket in credential cache.");
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   389
                }
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   390
                if (EType.isSupported(temp.getEType())) {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   391
                    result = temp.setKrbCreds();
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   392
                } else {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   393
                    if (DEBUG) {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   394
                        System.out.println(
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   395
                            ">>> unsupported key type found the default TGT: " +
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   396
                            temp.getEType());
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   397
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            // Doesn't seem to be a default cache on this system or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            // TGT has unsupported encryption type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (!alreadyTried) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                // See if there's any native code to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    ensureLoaded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        System.out.println("Can not load credentials cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    alreadyTried = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (alreadyLoaded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                // There is some native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                   System.out.println(">> Acquire default native Credentials");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                result = acquireDefaultNativeCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                // only TGT with DES key will be returned by native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Acquires credentials for a specified service using initial credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * When the service has a different realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * from the initial credential, we do cross-realm authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * - first, we use the current credential to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * a cross-realm credential from the local KDC, then use that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * cross-realm credential to request service credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * from the foreigh KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param service the name of service principal using format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * components@realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param ccreds client's initial credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @exception IOException if an error occurs in reading the credentials
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @exception KrbException if an error occurs specific to Kerberos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @return a <code>Credentials</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public static Credentials acquireServiceCreds(String service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                                  Credentials ccreds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return CredentialsUtil.acquireServiceCreds(service, ccreds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public CredentialsCache getCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public EncryptionKey getServiceKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return serviceKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Prints out debug info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public static void printDebug(Credentials c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        System.out.println(">>> DEBUG: ----Credentials----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        System.out.println("\tclient: " + c.client.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        System.out.println("\tserver: " + c.server.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        System.out.println("\tticket: realm: " + c.ticket.realm.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        System.out.println("\t        sname: " + c.ticket.sname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (c.startTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            System.out.println("\tstartTime: " + c.startTime.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        System.out.println("\tendTime: " + c.endTime.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        System.out.println("        ----Credentials end----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    static void ensureLoaded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                new java.security.PrivilegedAction<Void> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        public Void run() {
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12423
diff changeset
   481
                                if (System.getProperty("os.name").contains("OS X")) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   482
                                    System.loadLibrary("osxkrb5");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   483
                                } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   484
                                    System.loadLibrary("w2k_lsa_auth");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   485
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        alreadyLoaded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        StringBuffer buffer = new StringBuffer("Credentials:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        buffer.append("\nclient=").append(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        buffer.append("\nserver=").append(server);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (authTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            buffer.append("\nauthTime=").append(authTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (startTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            buffer.append("\nstartTime=").append(startTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        buffer.append("\nendTime=").append(endTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        buffer.append("\nrenewTill=").append(renewTill);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        buffer.append("\nflags: ").append(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        buffer.append("\nEType (int): ").append(key.getEType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return buffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
}