Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/config/SCDynamicConfigTest.java
38853 views
/*1* Copyright (c) 2012, 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 718424626* @summary Simplify Config.get() of krb527*/28import java.lang.reflect.Field;29import java.lang.reflect.Method;30import java.util.Hashtable;31import java.util.Vector;32import sun.security.krb5.Config;33import sun.security.krb5.SCDynamicStoreConfig;3435public class SCDynamicConfigTest {3637static Vector<Hashtable<String,String>>hosts() {38Vector <Hashtable<String,String>> result = new Vector<>();39Hashtable<String,String> pair = new Hashtable<>();40pair.put("host", "127.0.0.1");41result.add(pair);42pair = new Hashtable<>();43pair.put("host", "127.0.0.2");44result.add(pair);45return result;46}4748public static void main(String[] args) throws Exception {49// Reconstruct a typical SCDynamicConfig.getKerberosConfig() output50Hashtable<String, Object> conf = new Hashtable<>();5152Hashtable<String, Object> libdefaults = new Hashtable<>();53libdefaults.put("default_realm", "REALM.COM");54conf.put("libdefaults", libdefaults);5556Hashtable<String, Object> realms = new Hashtable<>();57Hashtable<String, Object> thisRealm = new Hashtable<>();58realms.put("REALM.COM", thisRealm);59thisRealm.put("kpasswd", hosts());60thisRealm.put("kadmin", hosts());61thisRealm.put("kdc", hosts());62conf.put("realms", realms);6364Hashtable<String, Object> domain_realm = new Hashtable<>();65domain_realm.put(".realm.com", "REALM.COM");66domain_realm.put("realm.com", "REALM.COM");67conf.put("domain_realm", domain_realm);6869System.out.println("SCDynamicConfig:\n");70System.out.println(conf);7172// Simulate SCDynamicConfig.getConfig() output73Method m = SCDynamicStoreConfig.class.getDeclaredMethod(74"convertNativeConfig", Hashtable.class);75m.setAccessible(true);76conf = (Hashtable)m.invoke(null, conf);7778System.out.println("\nkrb5.conf:\n");79System.out.println(conf);8081// Feed it into a Config object82System.setProperty("java.security.krb5.conf", "not-a-file");83Config cf = Config.getInstance();84Field f = Config.class.getDeclaredField("stanzaTable");85f.setAccessible(true);86f.set(cf, conf);8788System.out.println("\nConfig:\n");89System.out.println(cf);9091if (!cf.getDefaultRealm().equals("REALM.COM")) {92throw new Exception();93}94if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) {95throw new Exception();96}97if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) {98throw new Exception();99}100}101}102103104