blob: fe1146211c8b10d48ae38dd5c04be4c9af231b64 [file] [log] [blame]
Weijun Wang04e56f72009-05-20 10:12:00 +08001/*
Magnus Ihse Bursie97df6302017-05-09 12:57:30 +02002 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
Weijun Wang04e56f72009-05-20 10:12:00 +08003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
Kelly O'Hairfe008ae2010-05-25 15:58:33 -070019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
Weijun Wang04e56f72009-05-20 10:12:00 +080022 */
23/*
24 * @test
Weijun Wangefd36db2016-05-20 11:15:05 +080025 * @bug 6682516 8149521
Weijun Wang04e56f72009-05-20 10:12:00 +080026 * @summary SPNEGO_HTTP_AUTH/WWW_KRB and SPNEGO_HTTP_AUTH/WWW_SPNEGO failed on all non-windows platforms
Mark Sheppard8906a132016-04-11 03:00:50 +010027 * @modules java.security.jgss/sun.security.krb5
28 * @run main/othervm -Djava.security.krb5.conf=krb5.conf Test
Weijun Wang04e56f72009-05-20 10:12:00 +080029 */
30
31import java.net.InetAddress;
32import java.net.UnknownHostException;
Weijun Wang04e56f72009-05-20 10:12:00 +080033import sun.security.krb5.PrincipalName;
34
Mark Sheppard8906a132016-04-11 03:00:50 +010035public class Test {
Weijun Wang04e56f72009-05-20 10:12:00 +080036 public static void main(String[] args) throws Exception {
37 // This config file is generated using Kerberos.app on a Mac
Mark Sheppard8906a132016-04-11 03:00:50 +010038 String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts";
39 System.setProperty("jdk.net.hosts.file", hostsFileName);
Weijun Wang04e56f72009-05-20 10:12:00 +080040 System.setProperty("java.security.krb5.realm", "THIS.REALM");
41 System.setProperty("java.security.krb5.kdc", "localhost");
42
43 // add using canonicalized name
44 check("c1", "c1.this.domain");
45 check("c1.this", "c1.this.domain");
46 check("c1.this.domain", "c1.this.domain");
Weijun Wangefd36db2016-05-20 11:15:05 +080047 check("c1.this.domain.", "c1.this.domain");
Weijun Wang04e56f72009-05-20 10:12:00 +080048
49 // canonicalized name goes IP, reject
50 check("c2", "c2");
Weijun Wangefd36db2016-05-20 11:15:05 +080051 check("c2.", "c2");
Weijun Wang04e56f72009-05-20 10:12:00 +080052
53 // canonicalized name goes strange, reject
54 check("c3", "c3");
55
56 // unsupported
57 check("c4", "c4");
58 }
59
60 static void check(String input, String output) throws Exception {
61 System.out.println(input + " -> " + output);
62 PrincipalName pn = new PrincipalName("host/"+input,
63 PrincipalName.KRB_NT_SRV_HST);
64 if (!pn.getNameStrings()[1].equals(output)) {
65 throw new Exception("Output is " + pn);
66 }
67 }
Weijun Wangefd36db2016-05-20 11:15:05 +080068}