1387N/A/*
3882N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. 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 *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1387N/A */
1387N/A/*
1387N/A * @test
1387N/A * @bug 6857795
1475N/A * @bug 6858589
2620N/A * @bug 6972005
3882N/A * @run main/othervm ConfPlusProp
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/A
1387N/Apublic class ConfPlusProp {
1422N/A Config config;
1387N/A public static void main(String[] args) throws Exception {
1422N/A new ConfPlusProp().run();
1422N/A }
1422N/A
1422N/A void refresh() throws Exception {
1422N/A Config.refresh();
1422N/A config = Config.getInstance();
1422N/A }
1422N/A
1422N/A void checkDefaultRealm(String r) throws Exception {
1422N/A try {
1422N/A if (!config.getDefaultRealm().equals(r)) {
1422N/A throw new AssertionError("Default realm error");
1422N/A }
1422N/A } catch (Exception e) {
1422N/A if (r != null) throw e;
1422N/A }
1422N/A }
1422N/A
1422N/A void check(String r, String k) throws Exception {
1422N/A try {
1422N/A if (!config.getKDCList(r).equals(k)) {
1422N/A throw new AssertionError(r + " kdc not " + k);
1422N/A }
1422N/A } catch (Exception e) {
1422N/A if (k != null) throw e;
1422N/A }
1422N/A }
1422N/A
1422N/A void run() throws Exception {
1422N/A
1422N/A // No prop, only conf
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");
1422N/A refresh();
1387N/A
1422N/A checkDefaultRealm("R1");
1422N/A check("R1", "k1");
1422N/A check("R2", "old");
1422N/A check("R3", null);
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");
1422N/A refresh();
1422N/A
1422N/A checkDefaultRealm(null);
1422N/A check("R1", "k12");
1422N/A check("R2", "old");
1422N/A check("R3", null);
1422N/A
1422N/A int version = System.getProperty("java.version").charAt(2) - '0';
1422N/A System.out.println("JDK version is " + version);
1387N/A
1422N/A // Zero-config is supported since 1.7
1422N/A if (version >= 7) {
1422N/A // Point to a non-existing file
1422N/A System.setProperty("java.security.krb5.conf", "i-am-not-a file");
1422N/A refresh();
1387N/A
2620N/A // Default realm might come from DNS
2620N/A //checkDefaultRealm(null);
1422N/A check("R1", null);
1422N/A check("R2", null);
1422N/A check("R3", null);
1422N/A if (config.getDefault("forwardable", "libdefaults") != null) {
1422N/A throw new Exception("Extra config error");
1422N/A }
1387N/A }
1422N/A
1422N/A // Add prop
1422N/A System.setProperty("java.security.krb5.realm", "R2");
1422N/A System.setProperty("java.security.krb5.kdc", "k2");
1422N/A
1422N/A // Point to a file with existing default_realm
1422N/A System.setProperty("java.security.krb5.conf",
1422N/A System.getProperty("test.src", ".") +"/confplusprop.conf");
1422N/A refresh();
1422N/A
1422N/A checkDefaultRealm("R2");
1422N/A check("R1", "k1");
1422N/A check("R2", "k2");
1422N/A check("R3", "k2");
1422N/A if (!config.getDefault("forwardable", "libdefaults").equals("well")) {
1422N/A throw new Exception("Extra config error");
1387N/A }
1422N/A
1422N/A // Point to a file with no libdefaults
1422N/A System.setProperty("java.security.krb5.conf",
1422N/A System.getProperty("test.src", ".") +"/confplusprop2.conf");
1422N/A refresh();
1422N/A
1422N/A checkDefaultRealm("R2");
1422N/A check("R1", "k12");
1422N/A check("R2", "k2");
1422N/A check("R3", "k2");
1387N/A
1387N/A // Point to a non-existing file
1387N/A System.setProperty("java.security.krb5.conf", "i-am-not-a file");
1422N/A refresh();
1387N/A
1422N/A checkDefaultRealm("R2");
1422N/A check("R1", "k2");
1422N/A check("R2", "k2");
1422N/A check("R3", "k2");
1387N/A if (config.getDefault("forwardable", "libdefaults") != null) {
1387N/A throw new Exception("Extra config error");
1387N/A }
1387N/A }
1387N/A}