Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/ConfPlusProp.java
38838 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* @compile -XDignore.symbol.file ConfPlusProp.java28* @run main/othervm ConfPlusProp29* @summary krb5.conf ignored if system properties on realm and kdc are provided30*/3132import sun.security.krb5.Config;3334public class ConfPlusProp {35Config config;36public static void main(String[] args) throws Exception {37if (System.getenv("USERDNSDOMAIN") != null ||38System.getenv("LOGONSERVER") != null) {39System.out.println(40"Looks like a Windows machine in a domain. Skip test.");41return;42}43new ConfPlusProp().run();44}4546void refresh() throws Exception {47Config.refresh();48config = Config.getInstance();49}5051void checkDefaultRealm(String r) throws Exception {52try {53if (!config.getDefaultRealm().equals(r)) {54throw new AssertionError("Default realm error");55}56} catch (Exception e) {57if (r != null) throw e;58}59}6061void check(String r, String k) throws Exception {62try {63if (!config.getKDCList(r).equals(k)) {64throw new AssertionError(r + " kdc not " + k);65}66} catch (Exception e) {67if (k != null) throw e;68}69}7071void run() throws Exception {7273// No prop, only conf7475// Point to a file with existing default_realm76System.setProperty("java.security.krb5.conf",77System.getProperty("test.src", ".") +"/confplusprop.conf");78refresh();7980checkDefaultRealm("R1");81check("R1", "k1");82check("R2", "old");83check("R3", null);84if (!config.get("libdefaults", "forwardable").equals("well")) {85throw new Exception("Extra config error");86}8788// Point to a file with no libdefaults89System.setProperty("java.security.krb5.conf",90System.getProperty("test.src", ".") +"/confplusprop2.conf");91refresh();9293checkDefaultRealm(null);94check("R1", "k12");95check("R2", "old");96check("R3", null);9798if (config.get("libdefaults", "forwardable") != null) {99throw new Exception("Extra config error");100}101102// Add prop103System.setProperty("java.security.krb5.realm", "R2");104System.setProperty("java.security.krb5.kdc", "k2");105106// Point to a file with existing default_realm107System.setProperty("java.security.krb5.conf",108System.getProperty("test.src", ".") +"/confplusprop.conf");109refresh();110111checkDefaultRealm("R2");112check("R1", "k1");113check("R2", "k2");114check("R3", "k2");115if (!config.get("libdefaults", "forwardable").equals("well")) {116throw new Exception("Extra config error");117}118119// Point to a file with no libdefaults120System.setProperty("java.security.krb5.conf",121System.getProperty("test.src", ".") +"/confplusprop2.conf");122refresh();123124checkDefaultRealm("R2");125check("R1", "k12");126check("R2", "k2");127check("R3", "k2");128129if (config.get("libdefaults", "forwardable") != null) {130throw new Exception("Extra config error");131}132}133}134135136