Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/canonicalize/Test.java
38853 views
1
/*
2
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
/*
24
* @test
25
* @bug 6682516 8149521
26
* @summary SPNEGO_HTTP_AUTH/WWW_KRB and SPNEGO_HTTP_AUTH/WWW_SPNEGO failed on all non-windows platforms
27
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Djava.security.krb5.conf=krb5.conf Test
28
*/
29
30
import java.net.InetAddress;
31
import java.net.UnknownHostException;
32
import sun.net.spi.nameservice.NameService;
33
import sun.net.spi.nameservice.NameServiceDescriptor;
34
import sun.security.krb5.PrincipalName;
35
36
public class Test implements NameServiceDescriptor {
37
public static void main(String[] args) throws Exception {
38
// This config file is generated using Kerberos.app on a Mac
39
System.setProperty("java.security.krb5.realm", "THIS.REALM");
40
System.setProperty("java.security.krb5.kdc", "localhost");
41
42
// add using canonicalized name
43
check("c1", "c1.this.domain");
44
check("c1.this", "c1.this.domain");
45
check("c1.this.domain", "c1.this.domain");
46
check("c1.this.domain.", "c1.this.domain");
47
48
// canonicalized name goes IP, reject
49
check("c2", "c2");
50
check("c2.", "c2");
51
52
// canonicalized name goes strange, reject
53
check("c3", "c3");
54
55
// unsupported
56
check("c4", "c4");
57
}
58
59
static void check(String input, String output) throws Exception {
60
System.out.println(input + " -> " + output);
61
PrincipalName pn = new PrincipalName("host/"+input,
62
PrincipalName.KRB_NT_SRV_HST);
63
if (!pn.getNameStrings()[1].equals(output)) {
64
throw new Exception("Output is " + pn);
65
}
66
}
67
68
@Override
69
public NameService createNameService() throws Exception {
70
NameService ns = new NameService() {
71
@Override
72
public InetAddress[] lookupAllHostAddr(String host)
73
throws UnknownHostException {
74
// All c<n>.* goes to 127.0.0.n
75
int i = Integer.valueOf(host.split("\\.")[0].substring(1));
76
return new InetAddress[]{
77
InetAddress.getByAddress(host, new byte[]{127,0,0,(byte)i})
78
};
79
}
80
@Override
81
public String getHostByAddr(byte[] addr)
82
throws UnknownHostException {
83
int i = addr[3];
84
switch (i) {
85
case 1: return "c1.this.domain"; // Good
86
case 2: return "127.0.0.2"; // Only IP
87
case 3: return "d3.this.domain"; // name change
88
default:
89
throw new UnknownHostException();
90
}
91
}
92
};
93
return ns;
94
}
95
96
@Override
97
public String getProviderName() {
98
return "mock";
99
}
100
101
@Override
102
public String getType() {
103
return "ns";
104
}
105
}
106
107