Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 1 | /* |
Mark Sheppard | 8906a13 | 2016-04-11 03:00:50 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2009, 2016 Oracle and/or its affiliates. All rights reserved. |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 3 | * 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'Hair | fe008ae | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 19 | * 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 Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 22 | */ |
| 23 | /* |
| 24 | * @test |
| 25 | * @bug 6682516 |
| 26 | * @summary SPNEGO_HTTP_AUTH/WWW_KRB and SPNEGO_HTTP_AUTH/WWW_SPNEGO failed on all non-windows platforms |
Mark Sheppard | 8906a13 | 2016-04-11 03:00:50 +0100 | [diff] [blame^] | 27 | * @modules java.security.jgss/sun.security.krb5 |
| 28 | * @run main/othervm -Djava.security.krb5.conf=krb5.conf Test |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | import java.net.InetAddress; |
| 32 | import java.net.UnknownHostException; |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 33 | import sun.security.krb5.PrincipalName; |
| 34 | |
Mark Sheppard | 8906a13 | 2016-04-11 03:00:50 +0100 | [diff] [blame^] | 35 | public class Test { |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 36 | public static void main(String[] args) throws Exception { |
| 37 | // This config file is generated using Kerberos.app on a Mac |
Mark Sheppard | 8906a13 | 2016-04-11 03:00:50 +0100 | [diff] [blame^] | 38 | String hostsFileName = System.getProperty("test.src", ".") + "/TestHosts"; |
| 39 | System.setProperty("jdk.net.hosts.file", hostsFileName); |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 40 | 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"); |
| 47 | |
| 48 | // canonicalized name goes IP, reject |
| 49 | check("c2", "c2"); |
| 50 | |
| 51 | // canonicalized name goes strange, reject |
| 52 | check("c3", "c3"); |
| 53 | |
| 54 | // unsupported |
| 55 | check("c4", "c4"); |
| 56 | } |
| 57 | |
| 58 | static void check(String input, String output) throws Exception { |
| 59 | System.out.println(input + " -> " + output); |
| 60 | PrincipalName pn = new PrincipalName("host/"+input, |
| 61 | PrincipalName.KRB_NT_SRV_HST); |
| 62 | if (!pn.getNameStrings()[1].equals(output)) { |
| 63 | throw new Exception("Output is " + pn); |
| 64 | } |
| 65 | } |
Weijun Wang | 04e56f7 | 2009-05-20 10:12:00 +0800 | [diff] [blame] | 66 | } |