jdk/src/share/classes/sun/security/krb5/internal/KDCOptions.java
author weijun
Fri, 04 Apr 2014 21:19:43 +0800
changeset 23716 33cc4db6209b
parent 14413 e954df027393
permissions -rw-r--r--
8029995: accept yes/no for boolean krb5.conf settings Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
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
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.krb5.Config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.krb5.KrbException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.Asn1Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.internal.util.KerberosFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Implements the ASN.1 KDCOptions type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <xmp>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * KDCOptions   ::= KerberosFlags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      -- reserved(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      -- forwardable(1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      -- forwarded(2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      -- proxiable(3),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      -- proxy(4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      -- allow-postdate(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      -- postdated(6),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      -- unused7(7),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      -- renewable(8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      -- unused9(9),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      -- unused10(10),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      -- opt-hardware-auth(11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      -- unused12(12),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      -- unused13(13),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * -- 15 is reserved for canonicalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      -- unused15(15),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * -- 26 was unused in 1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      -- disable-transited-check(26),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      -- renewable-ok(27),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *      -- enc-tkt-in-skey(28),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *      -- renew(30),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *      -- validate(31)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * KerberosFlags   ::= BIT STRING (SIZE (32..MAX))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *                      -- minimum number of bits shall be sent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *                      -- but no fewer than 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * </xmp>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * This definition reflects the Network Working Group RFC 4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * specification available at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * http://www.ietf.org/rfc/rfc4120.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * This class appears as data field in the initial request(KRB_AS_REQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * or subsequent request(KRB_TGS_REQ) to the KDC and indicates the flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * that the client wants to set on the tickets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * The optional bits are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *  <LI>KDCOptions.RESERVED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *  <LI>KDCOptions.FORWARDABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *  <LI>KDCOptions.FORWARDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *  <LI>KDCOptions.PROXIABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *  <LI>KDCOptions.PROXY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *  <LI>KDCOptions.ALLOW_POSTDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *  <LI>KDCOptions.POSTDATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *  <LI>KDCOptions.RENEWABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *  <LI>KDCOptions.RENEWABLE_OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *  <LI>KDCOptions.ENC_TKT_IN_SKEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *  <LI>KDCOptions.RENEW
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *  <LI>KDCOptions.VALIDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *  </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p> Various checks must be made before honoring an option. The restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * on the use of some options are as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <li> FORWARDABLE, FORWARDED, PROXIABLE, RENEWABLE options may be set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * subsequent request only if the ticket_granting ticket on which it is based has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * the same options (FORWARDABLE, FORWARDED, PROXIABLE, RENEWABLE) set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <li> ALLOW_POSTDATE may be set in subsequent request only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * ticket-granting ticket on which it is based also has its MAY_POSTDATE flag set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <li> POSTDATED may be set in subsequent request only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * ticket-granting ticket on which it is based also has its MAY_POSTDATE flag set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <li> RENEWABLE or RENEW may be set in subsequent request only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * ticket-granting ticket on which it is based also has its RENEWABLE flag set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <li> POXY may be set in subsequent request only if the ticket-granting ticket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * on which it is based also has its PROXIABLE flag set, and the address(es) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * the host from which the resulting ticket is to be valid should be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * in the addresses field of the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <li>FORWARDED, PROXY, ENC_TKT_IN_SKEY, RENEW, VALIDATE are used only in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * subsequent requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * </ol><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
public class KDCOptions extends KerberosFlags {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
14328
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   123
    private static final int KDC_OPT_PROXIABLE = 0x10000000;
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   124
    private static final int KDC_OPT_RENEWABLE_OK = 0x00000010;
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   125
    private static final int KDC_OPT_FORWARDABLE = 0x40000000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // KDC Options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static final int RESERVED        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final int FORWARDABLE     = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static final int FORWARDED       = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final int PROXIABLE       = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static final int PROXY           = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final int ALLOW_POSTDATE  = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static final int POSTDATED       = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final int UNUSED7         = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public static final int RENEWABLE       = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final int UNUSED9         = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static final int UNUSED10        = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final int UNUSED11        = 11;
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   142
    public static final int CNAME_IN_ADDL_TKT = 14;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public static final int RENEWABLE_OK    = 27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static final int ENC_TKT_IN_SKEY = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int RENEW           = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static final int VALIDATE        = 31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   148
    private static final String[] names = {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   149
        "RESERVED",         //0
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   150
        "FORWARDABLE",      //1;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   151
        "FORWARDED",        //2;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   152
        "PROXIABLE",        //3;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   153
        "PROXY",            //4;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   154
        "ALLOW_POSTDATE",   //5;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   155
        "POSTDATED",        //6;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   156
        "UNUSED7",          //7;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   157
        "RENEWABLE",        //8;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   158
        "UNUSED9",          //9;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   159
        "UNUSED10",         //10;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   160
        "UNUSED11",         //11;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   161
        null,null,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   162
        "CNAME_IN_ADDL_TKT",//14;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   163
        null,null,null,null,null,null,null,null,null,null,null,null,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   164
        "RENEWABLE_OK",     //27;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   165
        "ENC_TKT_IN_SKEY",  //28;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   166
        null,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   167
        "RENEW",            //30;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   168
        "VALIDATE",         //31;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   169
    };
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   170
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   173
    public static KDCOptions with(int... flags) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   174
        KDCOptions options = new KDCOptions();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   175
        for (int flag: flags) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   176
            options.set(flag, true);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   177
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   178
        return options;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   179
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   180
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public KDCOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        super(Krb5.KDC_OPTS_MAX + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        setDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public KDCOptions(int size, byte[] data) throws Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        super(size, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if ((size > data.length * BITS_PER_UNIT) || (size > Krb5.KDC_OPTS_MAX + 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Constructs a KDCOptions from the specified bit settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param data the bits to be set for the KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception Asn1Exception if an error occurs while decoding an ASN1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public KDCOptions(boolean[] data) throws Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (data.length > Krb5.KDC_OPTS_MAX + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public KDCOptions(DerValue encoding) throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this(encoding.getUnalignedBitString(true).toBooleanArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Constructs a KDCOptions from the passed bit settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param options the bits to be set for the KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public KDCOptions(byte[] options) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super(options.length * BITS_PER_UNIT, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Parse (unmarshal) a KDCOptions from a DER input stream.  This form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * parsing might be used when expanding a value which is part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * a constructed sequence and uses explicitly tagged type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param data the Der input stream value, which contains one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * marshaled value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param explicitTag tag number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param optional indicate if this data field is optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return an instance of KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static KDCOptions parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        DerValue der = data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (explicitTag != (der.getTag() & (byte)0x1F))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            DerValue subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return new KDCOptions(subDer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Sets the value(true/false) for one of the <code>KDCOptions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param option an option bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param value true if the option is selected, false if the option is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see sun.security.krb5.internal.Krb5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void set(int option, boolean value) throws ArrayIndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        super.set(option, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Gets the value(true/false) for one of the <code>KDCOptions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param option an option bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return value true if the option is selected, false if the option is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see sun.security.krb5.internal.Krb5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public boolean get(int option) throws ArrayIndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return super.get(option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   273
    @Override public String toString() {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   274
        StringBuilder sb = new StringBuilder();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   275
        sb.append("KDCOptions: ");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   276
        for (int i=0; i<Krb5.KDC_OPTS_MAX+1; i++) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   277
            if (get(i)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   278
                if (names[i] != null) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   279
                    sb.append(names[i]).append(",");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   280
                } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   281
                    sb.append(i).append(",");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   282
                }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   283
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   284
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   285
        return sb.toString();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14328
diff changeset
   286
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private void setDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            Config config = Config.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   293
            // If key not present, returns Integer.MIN_VALUE, which is
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   294
            // almost all zero.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   296
            int options = config.getIntValue("libdefaults",
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   297
                    "kdc_default_options");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
14328
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   299
            if ((options & KDC_OPT_RENEWABLE_OK) == KDC_OPT_RENEWABLE_OK) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                set(RENEWABLE_OK, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            } else {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 14413
diff changeset
   302
                if (config.getBooleanObject("libdefaults", "renewable") == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    set(RENEWABLE_OK, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
14328
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   306
            if ((options & KDC_OPT_PROXIABLE) == KDC_OPT_PROXIABLE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                set(PROXIABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } else {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 14413
diff changeset
   309
                if (config.getBooleanObject("libdefaults", "proxiable") == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    set(PROXIABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
14328
45c5cda024f0 7195426: kdc_default_options not supported correctly
weijun
parents: 14327
diff changeset
   314
            if ((options & KDC_OPT_FORWARDABLE) == KDC_OPT_FORWARDABLE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                set(FORWARDABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            } else {
23716
33cc4db6209b 8029995: accept yes/no for boolean krb5.conf settings
weijun
parents: 14413
diff changeset
   317
                if (config.getBooleanObject("libdefaults", "forwardable") == Boolean.TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    set(FORWARDABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } catch (KrbException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                System.out.println("Exception in getting default values for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        "KDC Options from the configuration ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}