src/java.security.jgss/share/classes/sun/security/krb5/KdcComm.java
author weijun
Tue, 14 Aug 2018 22:39:34 +0800
changeset 51398 3c389a284345
parent 47216 71c04702a3d5
permissions -rw-r--r--
8209416: Refactoring GetPropertyAction calls in security libs Reviewed-by: xuelei, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, 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: 5458
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: 5458
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: 5458
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5458
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
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    34
import java.security.PrivilegedAction;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    35
import java.security.Security;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    36
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.krb5.internal.Krb5;
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
    38
import sun.security.krb5.internal.NetClient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.net.SocketTimeoutException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.PrivilegedActionException;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    45
import java.util.ArrayList;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    46
import java.util.List;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    47
import java.util.Set;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    48
import java.util.HashSet;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
    49
import java.util.Iterator;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    50
import sun.security.krb5.internal.KRBError;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    52
/**
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    53
 * KDC-REQ/KDC-REP communication. No more base class for KrbAsReq and
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    54
 * KrbTgsReq. This class is now communication only.
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    55
 */
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
    56
public final class KdcComm {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    58
    // The following settings can be configured in [libdefaults]
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    59
    // section of krb5.conf, which are global for all realms. Each of
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    60
    // them can also be defined in a realm, which overrides value here.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    63
     * max retry time for a single KDC, default Krb5.KDC_RETRY_LIMIT (3)
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    64
     */
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    65
    private static int defaultKdcRetryLimit;
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    66
    /**
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    67
     * timeout requesting a ticket from KDC, in millisec, default 30 sec
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    69
    private static int defaultKdcTimeout;
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    70
    /**
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    71
     * max UDP packet size, default unlimited (-1)
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    72
     */
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    73
    private static int defaultUdpPrefLimit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    77
    /**
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    78
     * What to do when a KDC is unavailable, specified in the
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    79
     * java.security file with key krb5.kdc.bad.policy.
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    80
     * Possible values can be TRY_LAST or TRY_LESS. Reloaded when refreshed.
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    81
     */
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    82
    private enum BpType {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    83
        NONE, TRY_LAST, TRY_LESS
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    84
    }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    85
    private static int tryLessMaxRetries = 1;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    86
    private static int tryLessTimeout = 5000;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    87
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    88
    private static BpType badPolicy;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    static {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    91
        initStatic();
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    92
    }
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    93
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    94
    /**
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    95
     * Read global settings
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    96
     */
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
    97
    public static void initStatic() {
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    98
        String value = AccessController.doPrivileged(
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
    99
        new PrivilegedAction<String>() {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   100
            public String run() {
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
   101
                return Security.getProperty("krb5.kdc.bad.policy");
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   102
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   103
        });
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   104
        if (value != null) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   105
            value = value.toLowerCase(Locale.ENGLISH);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   106
            String[] ss = value.split(":");
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   107
            if ("tryless".equals(ss[0])) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   108
                if (ss.length > 1) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   109
                    String[] params = ss[1].split(",");
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   110
                    try {
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   111
                        int tmp0 = Integer.parseInt(params[0]);
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   112
                        if (params.length > 1) {
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   113
                            tryLessTimeout = Integer.parseInt(params[1]);
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   114
                        }
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   115
                        // Assign here in case of exception at params[1]
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   116
                        tryLessMaxRetries = tmp0;
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   117
                    } catch (NumberFormatException nfe) {
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   118
                        // Ignored. Please note that tryLess is recognized and
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   119
                        // used, parameters using default values
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   120
                        if (DEBUG) {
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
   121
                            System.out.println("Invalid krb5.kdc.bad.policy" +
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   122
                                    " parameter for tryLess: " +
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   123
                                    value + ", use default");
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   124
                        }
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   125
                    }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   126
                }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   127
                badPolicy = BpType.TRY_LESS;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   128
            } else if ("trylast".equals(ss[0])) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   129
                badPolicy = BpType.TRY_LAST;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   130
            } else {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   131
                badPolicy = BpType.NONE;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   132
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   133
        } else {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   134
            badPolicy = BpType.NONE;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   135
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        int timeout = -1;
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   139
        int max_retries = -1;
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   140
        int udp_pref_limit = -1;
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   141
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Config cfg = Config.getInstance();
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 12842
diff changeset
   144
            String temp = cfg.get("libdefaults", "kdc_timeout");
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   145
            timeout = parseTimeString(temp);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   146
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 12842
diff changeset
   147
            temp = cfg.get("libdefaults", "max_retries");
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   148
            max_retries = parsePositiveIntString(temp);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 12842
diff changeset
   149
            temp = cfg.get("libdefaults", "udp_preference_limit");
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   150
            udp_pref_limit = parsePositiveIntString(temp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } catch (Exception exc) {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   152
           // ignore any exceptions; use default values
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
           if (DEBUG) {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   154
                System.out.println ("Exception in getting KDC communication " +
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   155
                                    "settings, using default value " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                    exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   159
        defaultKdcTimeout = timeout > 0 ? timeout : 30*1000; // 30 seconds
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   160
        defaultKdcRetryLimit =
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   161
                max_retries > 0 ? max_retries : Krb5.KDC_RETRY_LIMIT;
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   162
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   163
        if (udp_pref_limit < 0) {
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   164
            defaultUdpPrefLimit = Krb5.KDC_DEFAULT_UDP_PREF_LIMIT;
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   165
        } else if (udp_pref_limit > Krb5.KDC_HARD_UDP_LIMIT) {
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   166
            defaultUdpPrefLimit = Krb5.KDC_HARD_UDP_LIMIT;
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   167
        } else {
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   168
            defaultUdpPrefLimit = udp_pref_limit;
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 14342
diff changeset
   169
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   171
        KdcAccessibility.reset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   174
    /**
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   175
     * The instance fields
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   176
     */
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   177
    private String realm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   179
    public KdcComm(String realm) throws KrbException {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   180
        if (realm == null) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   181
           realm = Config.getInstance().getDefaultRealm();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   182
            if (realm == null) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   183
                throw new KrbException(Krb5.KRB_ERR_GENERIC,
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   184
                                       "Cannot find default realm");
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   185
            }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   186
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   187
        this.realm = realm;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   188
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   190
    public byte[] send(byte[] obuf)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        throws IOException, KrbException {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   192
        int udpPrefLimit = getRealmSpecificValue(
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   193
                realm, "udp_preference_limit", defaultUdpPrefLimit);
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   194
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        boolean useTCP = (udpPrefLimit > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             (obuf != null && obuf.length > udpPrefLimit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   198
        return send(obuf, useTCP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   201
    private byte[] send(byte[] obuf, boolean useTCP)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        throws IOException, KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (obuf == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Config cfg = Config.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (realm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            realm = cfg.getDefaultRealm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (realm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                throw new KrbException(Krb5.KRB_ERR_GENERIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                       "Cannot find default realm");
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
        String kdcList = cfg.getKDCList(realm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (kdcList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            throw new KrbException("Cannot get kdc for realm " + realm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   220
        // tempKdc may include the port number also
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   221
        Iterator<String> tempKdc = KdcAccessibility.list(kdcList).iterator();
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   222
        if (!tempKdc.hasNext()) {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   223
            throw new KrbException("Cannot get kdc for realm " + realm);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   224
        }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   225
        byte[] ibuf = null;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   226
        try {
20818
chegar
parents: 20804 18549
diff changeset
   227
            ibuf = sendIfPossible(obuf, tempKdc.next(), useTCP);
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   228
        } catch(Exception first) {
20827
29e3da385ed2 8020696: Merge problem for KdcComm.java
weijun
parents: 20818
diff changeset
   229
            boolean ok = false;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   230
            while(tempKdc.hasNext()) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   231
                try {
20818
chegar
parents: 20804 18549
diff changeset
   232
                    ibuf = sendIfPossible(obuf, tempKdc.next(), useTCP);
20827
29e3da385ed2 8020696: Merge problem for KdcComm.java
weijun
parents: 20818
diff changeset
   233
                    ok = true;
29e3da385ed2 8020696: Merge problem for KdcComm.java
weijun
parents: 20818
diff changeset
   234
                    break;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   235
                } catch(Exception ignore) {}
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   236
            }
20827
29e3da385ed2 8020696: Merge problem for KdcComm.java
weijun
parents: 20818
diff changeset
   237
            if (!ok) throw first;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   238
        }
20804
18285d130365 8014341: Better service from Kerberos servers
weijun
parents: 16504
diff changeset
   239
        if (ibuf == null) {
20818
chegar
parents: 20804 18549
diff changeset
   240
            throw new IOException("Cannot get a KDC reply");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   242
        return ibuf;
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   243
    }
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   244
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   245
    // send the AS Request to the specified KDC
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   246
    // failover to using TCP if useTCP is not set and response is too big
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   247
    private byte[] sendIfPossible(byte[] obuf, String tempKdc, boolean useTCP)
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   248
        throws IOException, KrbException {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   249
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   250
        try {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   251
            byte[] ibuf = send(obuf, tempKdc, useTCP);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   252
            KRBError ke = null;
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   253
            try {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   254
                ke = new KRBError(ibuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } catch (Exception e) {
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   256
                // OK
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   257
            }
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   258
            if (ke != null && ke.getErrorCode() ==
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   259
                    Krb5.KRB_ERR_RESPONSE_TOO_BIG) {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   260
                ibuf = send(obuf, tempKdc, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   262
            KdcAccessibility.removeBad(tempKdc);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   263
            return ibuf;
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   264
        } catch(Exception e) {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   265
            if (DEBUG) {
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   266
                System.out.println(">>> KrbKdcReq send: error trying " +
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   267
                        tempKdc);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   268
                e.printStackTrace(System.out);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   269
            }
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   270
            KdcAccessibility.addBad(tempKdc);
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   271
            throw e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    // send the AS Request to the specified KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   277
    private byte[] send(byte[] obuf, String tempKdc, boolean useTCP)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        throws IOException, KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (obuf == null)
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   281
            return null;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   282
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        int port = Krb5.KDC_INET_DEFAULT_PORT;
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   284
        int retries = getRealmSpecificValue(
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   285
                realm, "max_retries", defaultKdcRetryLimit);
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   286
        int timeout = getRealmSpecificValue(
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   287
                realm, "kdc_timeout", defaultKdcTimeout);
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   288
        if (badPolicy == BpType.TRY_LESS &&
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   289
                KdcAccessibility.isBad(tempKdc)) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   290
            if (retries > tryLessMaxRetries) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   291
                retries = tryLessMaxRetries; // less retries
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   292
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   293
            if (timeout > tryLessTimeout) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   294
                timeout = tryLessTimeout; // less time
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   295
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   296
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   297
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   298
        String kdc = null;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   299
        String portStr = null;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   300
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   301
        if (tempKdc.charAt(0) == '[') {     // Explicit IPv6 in []
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   302
            int pos = tempKdc.indexOf(']', 1);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   303
            if (pos == -1) {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   304
                throw new IOException("Illegal KDC: " + tempKdc);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   305
            }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   306
            kdc = tempKdc.substring(1, pos);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   307
            if (pos != tempKdc.length() - 1) {  // with port number
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   308
                if (tempKdc.charAt(pos+1) != ':') {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   309
                    throw new IOException("Illegal KDC: " + tempKdc);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   310
                }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   311
                portStr = tempKdc.substring(pos+2);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   312
            }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   313
        } else {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   314
            int colon = tempKdc.indexOf(':');
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   315
            if (colon == -1) {      // Hostname or IPv4 host only
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   316
                kdc = tempKdc;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   317
            } else {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   318
                int nextColon = tempKdc.indexOf(':', colon+1);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   319
                if (nextColon > 0) {    // >=2 ":", IPv6 with no port
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   320
                    kdc = tempKdc;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   321
                } else {                // 1 ":", hostname or IPv4 with port
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   322
                    kdc = tempKdc.substring(0, colon);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   323
                    portStr = tempKdc.substring(colon+1);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   324
                }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   325
            }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   326
        }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents: 2597
diff changeset
   327
        if (portStr != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int tempPort = parsePositiveIntString(portStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (tempPort > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                port = tempPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            System.out.println(">>> KrbKdcReq send: kdc=" + kdc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                               + (useTCP ? " TCP:":" UDP:")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                               +  port +  ", timeout="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                               + timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                               + ", number of retries ="
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   339
                               + retries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                               + ", #bytes=" + obuf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        KdcCommunication kdcCommunication =
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   344
            new KdcCommunication(kdc, port, useTCP, timeout, retries, obuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        try {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   346
            byte[] ibuf = AccessController.doPrivileged(kdcCommunication);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                System.out.println(">>> KrbKdcReq send: #bytes read="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        + (ibuf != null ? ibuf.length : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7175
diff changeset
   351
            return ibuf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        } catch (PrivilegedActionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            Exception wrappedException = e.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            if (wrappedException instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                throw (IOException) wrappedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                throw (KrbException) wrappedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private static class KdcCommunication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        implements PrivilegedExceptionAction<byte[]> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        private String kdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        private int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        private boolean useTCP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        private int timeout;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   369
        private int retries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        private byte[] obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public KdcCommunication(String kdc, int port, boolean useTCP,
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   373
                                int timeout, int retries, byte[] obuf) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            this.kdc = kdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            this.useTCP = useTCP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            this.timeout = timeout;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   378
            this.retries = retries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            this.obuf = obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // The caller only casts IOException and KrbException so don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // add any new ones!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        public byte[] run() throws IOException, KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            byte[] ibuf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   389
            for (int i=1; i <= retries; i++) {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   390
                String proto = useTCP?"TCP":"UDP";
40540
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   391
                if (DEBUG) {
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   392
                    System.out.println(">>> KDCCommunication: kdc=" + kdc
12842
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9035
diff changeset
   393
                            + " " + proto + ":"
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9035
diff changeset
   394
                            +  port +  ", timeout="
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9035
diff changeset
   395
                            + timeout
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9035
diff changeset
   396
                            + ",Attempt =" + i
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 9035
diff changeset
   397
                            + ", #bytes=" + obuf.length);
40540
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   398
                }
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   399
                try (NetClient kdcClient = NetClient.getInstance(
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   400
                        proto, kdc, port, timeout)) {
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   401
                    kdcClient.send(obuf);
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   402
                    ibuf = kdcClient.receive();
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   403
                    break;
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   404
                } catch (SocketTimeoutException se) {
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   405
                    if (DEBUG) {
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   406
                        System.out.println ("SocketTimeOutException with " +
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   407
                                "attempt: " + i);
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   408
                    }
40540
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   409
                    if (i == retries) {
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   410
                        ibuf = null;
49fd4217ac48 8164656: krb5 does not retry if TCP connection timeouts
weijun
parents: 25859
diff changeset
   411
                        throw se;
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents: 5506
diff changeset
   412
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return ibuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   420
     * Parses a time value string. If it ends with "s", parses as seconds.
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   421
     * Otherwise, parses as milliseconds.
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   422
     * @param s the time string
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   423
     * @return the integer value in milliseconds, or -1 if input is null or
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   424
     * has an invalid format
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   425
     */
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   426
    private static int parseTimeString(String s) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   427
        if (s == null) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   428
            return -1;
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   429
        }
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   430
        if (s.endsWith("s")) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   431
            int seconds = parsePositiveIntString(s.substring(0, s.length()-1));
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   432
            return (seconds < 0) ? -1 : (seconds*1000);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   433
        } else {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   434
            return parsePositiveIntString(s);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   435
        }
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   436
    }
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   437
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   438
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20827
diff changeset
   439
     * Returns krb5.conf setting of {@code key} for a specific realm,
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   440
     * which can be:
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   441
     * 1. defined in the sub-stanza for the given realm inside [realms], or
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   442
     * 2. defined in [libdefaults], or
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   443
     * 3. defValue
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   444
     * @param realm the given realm in which the setting is requested. Returns
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   445
     * the global setting if null
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   446
     * @param key the key for the setting
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   447
     * @param defValue default value
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   448
     * @return a value for the key
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   450
    private int getRealmSpecificValue(String realm, String key, int defValue) {
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   451
        int v = defValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   453
        if (realm == null) return v;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   455
        int temp = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        try {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   457
            String value =
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 12842
diff changeset
   458
               Config.getInstance().get("realms", realm, key);
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   459
            if (key.equals("kdc_timeout")) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   460
                temp = parseTimeString(value);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   461
            } else {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   462
                temp = parsePositiveIntString(value);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   463
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        } catch (Exception exc) {
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   465
            // Ignored, defValue will be picked up
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   468
        if (temp > 0) v = temp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   470
        return v;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   473
    private static int parsePositiveIntString(String intString) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (intString == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        int ret = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            ret = Integer.parseInt(intString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        if (ret >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   490
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   491
    /**
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   492
     * Maintains a KDC accessible list. Unavailable KDCs are put into a
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   493
     * blacklist, when a KDC in the blacklist is available, it's removed
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   494
     * from there. No insertion order in the blacklist.
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   495
     *
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   496
     * There are two methods to deal with KDCs in the blacklist. 1. Only try
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   497
     * them when there's no KDC not on the blacklist. 2. Still try them, but
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   498
     * with lesser number of retries and smaller timeout value.
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   499
     */
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   500
    static class KdcAccessibility {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   501
        // Known bad KDCs
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   502
        private static Set<String> bads = new HashSet<>();
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   503
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   504
        private static synchronized void addBad(String kdc) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   505
            if (DEBUG) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   506
                System.out.println(">>> KdcAccessibility: add " + kdc);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   507
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   508
            bads.add(kdc);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   509
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   510
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   511
        private static synchronized void removeBad(String kdc) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   512
            if (DEBUG) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   513
                System.out.println(">>> KdcAccessibility: remove " + kdc);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   514
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   515
            bads.remove(kdc);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   516
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   517
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   518
        private static synchronized boolean isBad(String kdc) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   519
            return bads.contains(kdc);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   520
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   521
5458
62f857d96000 6844193: support max_retries in krb5.conf
weijun
parents: 4531
diff changeset
   522
        private static synchronized void reset() {
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   523
            if (DEBUG) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   524
                System.out.println(">>> KdcAccessibility: reset");
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   525
            }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   526
            bads.clear();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   527
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   528
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   529
        // Returns a preferred KDC list by putting the bad ones at the end
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   530
        private static synchronized List<String> list(String kdcList) {
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   531
            StringTokenizer st = new StringTokenizer(kdcList);
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   532
            List<String> list = new ArrayList<>();
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   533
            if (badPolicy == BpType.TRY_LAST) {
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   534
                List<String> badkdcs = new ArrayList<>();
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   535
                while (st.hasMoreTokens()) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   536
                    String t = st.nextToken();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   537
                    if (bads.contains(t)) badkdcs.add(t);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   538
                    else list.add(t);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   539
                }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   540
                // Bad KDCs are put at last
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   541
                list.addAll(badkdcs);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   542
            } else {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   543
                // All KDCs are returned in their original order,
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   544
                // This include TRY_LESS and NONE
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   545
                while (st.hasMoreTokens()) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   546
                    list.add(st.nextToken());
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   547
                }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   548
            }
18549
66e6e111be22 8016051: Possible ClassCastException in KdcComm
weijun
parents: 16504
diff changeset
   549
            return list;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   550
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   551
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
}
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 3864
diff changeset
   553