jdk/src/share/classes/sun/security/krb5/internal/KDCOptions.java
author weijun
Mon, 29 Oct 2012 14:14:06 +0800
changeset 14327 c0d86f6f8be8
parent 5506 202f599c92aa
child 14328 45c5cda024f0
permissions -rw-r--r--
7184246: Simplify Config.get() of krb5 Reviewed-by: xuelei
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public final int KDC_OPT_PROXIABLE = 0x10000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public final int KDC_OPT_RENEWABLE_OK = 0x00000010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public final int KDC_OPT_FORWARDABLE = 0x40000000;
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static final int RENEWABLE_OK    = 27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public static final int ENC_TKT_IN_SKEY = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static final int RENEW           = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int VALIDATE        = 31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public KDCOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        super(Krb5.KDC_OPTS_MAX + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        setDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public KDCOptions(int size, byte[] data) throws Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        super(size, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if ((size > data.length * BITS_PER_UNIT) || (size > Krb5.KDC_OPTS_MAX + 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Constructs a KDCOptions from the specified bit settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param data the bits to be set for the KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @exception Asn1Exception if an error occurs while decoding an ASN1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public KDCOptions(boolean[] data) throws Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        super(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (data.length > Krb5.KDC_OPTS_MAX + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);
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
    public KDCOptions(DerValue encoding) throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this(encoding.getUnalignedBitString(true).toBooleanArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Constructs a KDCOptions from the passed bit settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param options the bits to be set for the KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public KDCOptions(byte[] options) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        super(options.length * BITS_PER_UNIT, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Parse (unmarshal) a KDCOptions from a DER input stream.  This form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * parsing might be used when expanding a value which is part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * a constructed sequence and uses explicitly tagged type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param data the Der input stream value, which contains one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * marshaled value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param explicitTag tag number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param optional indicate if this data field is optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return an instance of KDCOptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public static KDCOptions parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        DerValue der = data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (explicitTag != (der.getTag() & (byte)0x1F))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            DerValue subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return new KDCOptions(subDer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Sets the value(true/false) for one of the <code>KDCOptions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param option an option bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param value true if the option is selected, false if the option is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see sun.security.krb5.internal.Krb5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void set(int option, boolean value) throws ArrayIndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        super.set(option, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Gets the value(true/false) for one of the <code>KDCOptions</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param option an option bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return value true if the option is selected, false if the option is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @exception ArrayIndexOutOfBoundsException if array index out of bound occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see sun.security.krb5.internal.Krb5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public boolean get(int option) throws ArrayIndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return super.get(option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
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 setDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            Config config = Config.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   247
            // If key not present, returns Integer.MIN_VALUE, which is
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   248
            // almost all zero.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   250
            int options = config.getIntValue("libdefaults",
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   251
                    "kdc_default_options");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if ((options & RENEWABLE_OK) == RENEWABLE_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                set(RENEWABLE_OK, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } else {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   256
                if (config.getBooleanValue("libdefaults", "renewable")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    set(RENEWABLE_OK, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            if ((options & PROXIABLE) == PROXIABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                set(PROXIABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            } else {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   263
                if (config.getBooleanValue("libdefaults", "proxiable")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    set(PROXIABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if ((options & FORWARDABLE) == FORWARDABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                set(FORWARDABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            } else {
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 5506
diff changeset
   271
                if (config.getBooleanValue("libdefaults", "forwardable")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    set(FORWARDABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } catch (KrbException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                System.out.println("Exception in getting default values for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        "KDC Options from the configuration ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}