Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java
66646 views
1
/*
2
* Copyright (c) 2021, 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 8257860
27
* @summary SCDynamicStoreConfig works
28
* @modules java.security.jgss/sun.security.krb5
29
* @library /test/lib
30
* @run main/manual/native TestDynamicStore
31
* @requires (os.family == "mac")
32
*/
33
34
import jdk.test.lib.Asserts;
35
import sun.security.krb5.Config;
36
37
// =================== Attention ===================
38
// This test calls a native method implemented in libTestDynamicStore.m
39
// to modify system-level Kerberos 5 settings stored in the dynamic store.
40
// It must be launched by a user with enough privilege or with "sudo".
41
// If launched with sudo, remember to remove the report and working
42
// directories with sudo as well after executing the test.
43
44
public class TestDynamicStore {
45
46
native static int actionInternal(char what, char whom);
47
48
// what: 'a' for add, 'r' for remove
49
// whom: 'a' for all, 'r' for realm, 'm' for mapping
50
static int action(char what, char whom) throws Exception {
51
int out = actionInternal(what, whom);
52
System.out.println("Run " + what + whom + " " + out);
53
Thread.sleep(1000); // wait for callback called
54
return out;
55
}
56
57
public static void main(String[] args) throws Exception {
58
59
System.loadLibrary("TestDynamicStore");
60
61
Config cfg = Config.getInstance();
62
if (cfg.exists("libdefaults") || cfg.exists("realms")) {
63
System.out.println("Already have krb5 config. Will not touch");
64
return;
65
}
66
67
try {
68
System.out.println("Fill in dynamic store");
69
if (action('a', 'a') == 0) {
70
throw new Exception("Cannot write native Kerberos settings. " +
71
"Please make sure the test runs with enough privilege.");
72
}
73
Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));
74
Asserts.assertTrue(Config.getInstance().exists("domain_realm"));
75
76
System.out.println("Remove mapping");
77
action('r', 'm');
78
Asserts.assertTrue(!Config.getInstance().exists("domain_realm"));
79
80
System.out.println("Re-add mapping");
81
action('a', 'm');
82
Asserts.assertTrue(Config.getInstance().exists("domain_realm"));
83
84
System.out.println("Remove realm info");
85
action('r', 'r');
86
// Realm info is not watched, so no change detected
87
Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));
88
89
System.out.println("Remove mapping");
90
action('r', 'm');
91
// But mapping is watched, so realm info is not re-read
92
Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("B.COM"));
93
} finally {
94
System.out.println("Remove everything");
95
action('r', 'a');
96
Asserts.assertTrue(!Config.getInstance().exists("libdefault"));
97
}
98
}
99
}
100
101