Path: blob/master/test/jdk/sun/security/krb5/config/ConfPlusProp.java
41155 views
/*1* Copyright (c) 2009, 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*/22/*23* @test24* @bug 685779525* @bug 685858926* @bug 697200527* @modules java.security.jgss/sun.security.krb528* @compile -XDignore.symbol.file ConfPlusProp.java29* @run main/othervm ConfPlusProp30* @summary krb5.conf ignored if system properties on realm and kdc are provided31*/3233import sun.security.krb5.Config;3435public class ConfPlusProp {36Config config;37public static void main(String[] args) throws Exception {38if (System.getenv("USERDNSDOMAIN") != null ||39System.getenv("LOGONSERVER") != null) {40System.out.println(41"Looks like a Windows machine in a domain. Skip test.");42return;43}44new ConfPlusProp().run();45}4647void refresh() throws Exception {48Config.refresh();49config = Config.getInstance();50}5152void checkDefaultRealm(String r) throws Exception {53try {54if (!config.getDefaultRealm().equals(r)) {55throw new AssertionError("Default realm error");56}57} catch (Exception e) {58if (r != null) throw e;59}60}6162void check(String r, String k) throws Exception {63try {64if (!config.getKDCList(r).equals(k)) {65throw new AssertionError(r + " kdc not " + k);66}67} catch (Exception e) {68if (k != null) throw e;69}70}7172void run() throws Exception {7374// No prop, only conf7576// Point to a file with existing default_realm77System.setProperty("java.security.krb5.conf",78System.getProperty("test.src", ".") +"/confplusprop.conf");79refresh();8081checkDefaultRealm("R1");82check("R1", "k1");83check("R2", "old");84check("R3", null);85if (!config.get("libdefaults", "forwardable").equals("well")) {86throw new Exception("Extra config error");87}8889// Point to a file with no libdefaults90System.setProperty("java.security.krb5.conf",91System.getProperty("test.src", ".") +"/confplusprop2.conf");92refresh();9394checkDefaultRealm(null);95check("R1", "k12");96check("R2", "old");97check("R3", null);9899if (config.get("libdefaults", "forwardable") != null) {100throw new Exception("Extra config error");101}102103// Add prop104System.setProperty("java.security.krb5.realm", "R2");105System.setProperty("java.security.krb5.kdc", "k2");106107// Point to a file with existing default_realm108System.setProperty("java.security.krb5.conf",109System.getProperty("test.src", ".") +"/confplusprop.conf");110refresh();111112checkDefaultRealm("R2");113check("R1", "k1");114check("R2", "k2");115check("R3", "k2");116if (!config.get("libdefaults", "forwardable").equals("well")) {117throw new Exception("Extra config error");118}119120// Point to a file with no libdefaults121System.setProperty("java.security.krb5.conf",122System.getProperty("test.src", ".") +"/confplusprop2.conf");123refresh();124125checkDefaultRealm("R2");126check("R1", "k12");127check("R2", "k2");128check("R3", "k2");129130if (config.get("libdefaults", "forwardable") != null) {131throw new Exception("Extra config error");132}133}134}135136137