Path: blob/master/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java
66646 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 825786026* @summary SCDynamicStoreConfig works27* @modules java.security.jgss/sun.security.krb528* @library /test/lib29* @run main/manual/native TestDynamicStore30* @requires (os.family == "mac")31*/3233import jdk.test.lib.Asserts;34import sun.security.krb5.Config;3536// =================== Attention ===================37// This test calls a native method implemented in libTestDynamicStore.m38// to modify system-level Kerberos 5 settings stored in the dynamic store.39// It must be launched by a user with enough privilege or with "sudo".40// If launched with sudo, remember to remove the report and working41// directories with sudo as well after executing the test.4243public class TestDynamicStore {4445native static int actionInternal(char what, char whom);4647// what: 'a' for add, 'r' for remove48// whom: 'a' for all, 'r' for realm, 'm' for mapping49static int action(char what, char whom) throws Exception {50int out = actionInternal(what, whom);51System.out.println("Run " + what + whom + " " + out);52Thread.sleep(1000); // wait for callback called53return out;54}5556public static void main(String[] args) throws Exception {5758System.loadLibrary("TestDynamicStore");5960Config cfg = Config.getInstance();61if (cfg.exists("libdefaults") || cfg.exists("realms")) {62System.out.println("Already have krb5 config. Will not touch");63return;64}6566try {67System.out.println("Fill in dynamic store");68if (action('a', 'a') == 0) {69throw new Exception("Cannot write native Kerberos settings. " +70"Please make sure the test runs with enough privilege.");71}72Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));73Asserts.assertTrue(Config.getInstance().exists("domain_realm"));7475System.out.println("Remove mapping");76action('r', 'm');77Asserts.assertTrue(!Config.getInstance().exists("domain_realm"));7879System.out.println("Re-add mapping");80action('a', 'm');81Asserts.assertTrue(Config.getInstance().exists("domain_realm"));8283System.out.println("Remove realm info");84action('r', 'r');85// Realm info is not watched, so no change detected86Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));8788System.out.println("Remove mapping");89action('r', 'm');90// But mapping is watched, so realm info is not re-read91Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("B.COM"));92} finally {93System.out.println("Remove everything");94action('r', 'a');95Asserts.assertTrue(!Config.getInstance().exists("libdefault"));96}97}98}99100101