author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 23339 | d66b18f52418 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13016
diff
changeset
|
2 |
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
4 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
8 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
14 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
18 |
* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
21 |
* questions. |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
22 |
*/ |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
23 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
24 |
/* |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
25 |
* @test |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
26 |
* @bug 6952519 |
12842
f6f9cb8f6b97
7162687: enhance KDC server availability detection
weijun
parents:
11357
diff
changeset
|
27 |
* @compile -XDignore.symbol.file TcpTimeout.java |
11357 | 28 |
* @run main/othervm TcpTimeout |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
29 |
* @summary kdc_timeout is not being honoured when using TCP |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
30 |
*/ |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
31 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
32 |
import java.io.*; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
33 |
import java.net.ServerSocket; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
34 |
import sun.security.krb5.Config; |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
35 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
36 |
public class TcpTimeout { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
37 |
public static void main(String[] args) |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
38 |
throws Exception { |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
39 |
|
11357 | 40 |
// Set debug to grab debug output like ">>> KDCCommunication" |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
41 |
System.setProperty("sun.security.krb5.debug", "true"); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
42 |
|
11357 | 43 |
// Called before new ServerSocket on p1 and p2 to make sure |
44 |
// customized nameservice is used |
|
45 |
KDC k = new KDC(OneKDC.REALM, OneKDC.KDCHOST, 0, true); |
|
46 |
int p3 = k.getPort(); |
|
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
47 |
k.addPrincipal(OneKDC.USER, OneKDC.PASS); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
48 |
k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
49 |
|
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
50 |
// Start two listener that does not communicate, simulate timeout |
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
51 |
ServerSocket ss1 = null; |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
52 |
ServerSocket ss2 = null; |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
53 |
|
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
54 |
try { |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
55 |
ss1 = new ServerSocket(0); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
56 |
ss2 = new ServerSocket(0); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
57 |
int p1 = ss1.getLocalPort(); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
58 |
int p2 = ss2.getLocalPort(); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
59 |
|
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
60 |
FileWriter fw = new FileWriter("alternative-krb5.conf"); |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
61 |
|
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
62 |
fw.write("[libdefaults]\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
63 |
"udp_preference_limit = 1\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
64 |
"max_retries = 2\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
65 |
"default_realm = " + OneKDC.REALM + "\n" + |
23339
d66b18f52418
8035963: The failed Kerberos tests due to timeouts
weijun
parents:
14342
diff
changeset
|
66 |
"kdc_timeout = " + BadKdc.toReal(5000) + "\n"); |
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
67 |
fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
68 |
"kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
69 |
"kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
70 |
"kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
71 |
"}\n"); |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
72 |
|
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
73 |
fw.close(); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
74 |
System.setProperty("java.security.krb5.conf", |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
75 |
"alternative-krb5.conf"); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
76 |
Config.refresh(); |
11357 | 77 |
|
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
78 |
System.out.println("Ports opened on " + p1 + ", " + p2 + ", " + p3); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
79 |
|
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
80 |
// The correct behavior should be: |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
81 |
// 5 sec on p1, 5 sec on p1, fail |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
82 |
// 5 sec on p2, 5 sec on p2, fail |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
83 |
// p3 ok, p3 ok again for preauth. |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
84 |
int count = 6; |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
85 |
|
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
86 |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
87 |
PrintStream oldout = System.out; |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
88 |
System.setOut(new PrintStream(bo)); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
89 |
Context c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
90 |
System.setOut(oldout); |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
91 |
|
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
92 |
String[] lines = new String(bo.toByteArray()).split("\n"); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
93 |
for (String line: lines) { |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
94 |
if (line.startsWith(">>> KDCCommunication")) { |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
95 |
System.out.println(line); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
96 |
count--; |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
97 |
} |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
98 |
} |
13016
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
99 |
if (count != 0) { |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
100 |
throw new Exception("Retry count is " + count + " less"); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
101 |
} |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
102 |
} finally { |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
103 |
if (ss1 != null) ss1.close(); |
8e43ddef9617
7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents:
12842
diff
changeset
|
104 |
if (ss2 != null) ss2.close(); |
7175
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
105 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
106 |
} |
46ec4c2dbc16
6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff
changeset
|
107 |
} |