ConfPlusProp.java revision 1387
1387N/A/*
1387N/A * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
1387N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1387N/A *
1387N/A * This code is free software; you can redistribute it and/or modify it
1387N/A * under the terms of the GNU General Public License version 2 only, as
1387N/A * published by the Free Software Foundation.
1387N/A *
1387N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1387N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1387N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1387N/A * version 2 for more details (a copy is included in the LICENSE file that
1387N/A * accompanied this code).
1387N/A *
1387N/A * You should have received a copy of the GNU General Public License version
1387N/A * 2 along with this work; if not, write to the Free Software Foundation,
1387N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1387N/A *
1387N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1387N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1387N/A * have any questions.
1387N/A */
1387N/A/*
1387N/A * @test
1387N/A * @bug 6857795
1387N/A * @summary krb5.conf ignored if system properties on realm and kdc are provided
1387N/A */
1387N/A
1387N/Aimport sun.security.krb5.Config;
1387N/Aimport sun.security.krb5.KrbException;
1387N/A
1387N/Apublic class ConfPlusProp {
1387N/A public static void main(String[] args) throws Exception {
1387N/A System.setProperty("java.security.krb5.realm", "R2");
1387N/A System.setProperty("java.security.krb5.kdc", "k2");
1387N/A
1387N/A // Point to a file with existing default_realm
1387N/A System.setProperty("java.security.krb5.conf",
1387N/A System.getProperty("test.src", ".") +"/confplusprop.conf");
1387N/A Config config = Config.getInstance();
1387N/A
1387N/A if (!config.getDefaultRealm().equals("R2")) {
1387N/A throw new Exception("Default realm error");
1387N/A }
1387N/A if (!config.getKDCList("R1").equals("k1")) {
1387N/A throw new Exception("R1 kdc error");
1387N/A }
1387N/A if (!config.getKDCList("R2").equals("k2")) {
1387N/A throw new Exception("R2 kdc error");
1387N/A }
1387N/A if (!config.getDefault("forwardable", "libdefaults").equals("well")) {
1387N/A throw new Exception("Extra config error");
1387N/A }
1387N/A
1387N/A // Point to a file with no libdefaults
1387N/A System.setProperty("java.security.krb5.conf",
1387N/A System.getProperty("test.src", ".") +"/confplusprop2.conf");
1387N/A Config.refresh();
1387N/A
1387N/A config = Config.getInstance();
1387N/A
1387N/A if (!config.getDefaultRealm().equals("R2")) {
1387N/A throw new Exception("Default realm error again");
1387N/A }
1387N/A if (!config.getKDCList("R1").equals("k12")) {
1387N/A throw new Exception("R1 kdc error");
1387N/A }
1387N/A if (!config.getKDCList("R2").equals("k2")) {
1387N/A throw new Exception("R2 kdc error");
1387N/A }
1387N/A
1387N/A // Point to a non-existing file
1387N/A System.setProperty("java.security.krb5.conf", "i-am-not-a file");
1387N/A Config.refresh();
1387N/A
1387N/A config = Config.getInstance();
1387N/A
1387N/A if (!config.getDefaultRealm().equals("R2")) {
1387N/A throw new Exception("Default realm error");
1387N/A }
1387N/A try {
1387N/A config.getKDCList("R1");
1387N/A throw new Exception("R1 is nowhere");
1387N/A } catch (KrbException ke) {
1387N/A // OK
1387N/A }
1387N/A if (!config.getKDCList("R2").equals("k2")) {
1387N/A throw new Exception("R2 kdc error");
1387N/A }
1387N/A if (config.getDefault("forwardable", "libdefaults") != null) {
1387N/A throw new Exception("Extra config error");
1387N/A }
1387N/A }
1387N/A}