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/auto/LongLife.java
38854 views
1
/*
2
* Copyright (c) 2018, 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
/*
25
* @test
26
* @bug 8131051 8187218
27
* @summary KDC might issue a renewable ticket even if not requested
28
* @compile -XDignore.symbol.file LongLife.java
29
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock LongLife
30
*/
31
32
import org.ietf.jgss.GSSCredential;
33
import org.ietf.jgss.GSSManager;
34
import sun.security.krb5.Config;
35
import javax.security.auth.Subject;
36
import javax.security.auth.kerberos.KerberosTicket;
37
import java.security.PrivilegedExceptionAction;
38
39
public class LongLife {
40
41
public static void main(String[] args) throws Exception {
42
43
OneKDC kdc = new OneKDC(null).writeJAASConf();
44
45
test(kdc, "10h", false, 36000, false);
46
test(kdc, "2d", false, KDC.DEFAULT_LIFETIME, true);
47
test(kdc, "2d", true, 2 * 24 * 3600, false);
48
49
// 8187218: getRemainingLifetime() is negative if lifetime
50
// is longer than 30 days.
51
test(kdc, "30d", true, 30 * 24 * 3600, false);
52
}
53
54
static void test(
55
KDC kdc,
56
String ticketLifetime,
57
boolean forceTill, // if true, KDC will not try RENEWABLE
58
int expectedLifeTime,
59
boolean expectedRenewable) throws Exception {
60
61
KDC.saveConfig(OneKDC.KRB5_CONF, kdc);
62
Config.refresh();
63
64
System.setProperty("test.kdc.ttl.value", ticketLifetime);
65
66
if (forceTill) {
67
System.setProperty("test.kdc.force.till", "");
68
} else {
69
System.clearProperty("test.kdc.force.till");
70
}
71
72
Context c = Context.fromJAAS("client");
73
74
GSSCredential cred = Subject.doAs(c.s(),
75
(PrivilegedExceptionAction<GSSCredential>)
76
()-> {
77
GSSManager m = GSSManager.getInstance();
78
return m.createCredential(GSSCredential.INITIATE_ONLY);
79
});
80
81
KerberosTicket tgt = c.s().getPrivateCredentials(KerberosTicket.class)
82
.iterator().next();
83
System.out.println(tgt);
84
85
int actualLifeTime = cred.getRemainingLifetime();
86
if (actualLifeTime < (expectedLifeTime - 60 )
87
|| actualLifeTime > (expectedLifeTime + 60)) {
88
throw new Exception("actualLifeTime is " + actualLifeTime +
89
" ExpectedLifeTime is " + expectedLifeTime);
90
}
91
92
if (tgt.isRenewable() != expectedRenewable) {
93
throw new Exception("TGT's RENEWABLE flag is " + tgt.isRenewable());
94
}
95
}
96
}
97
98