1/* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23/* 24 * @test 25 * @bug 6857795 26 * @bug 6858589 27 * @bug 6972005 28 * @modules java.security.jgss/sun.security.krb5 29 * @compile -XDignore.symbol.file ConfPlusProp.java 30 * @run main/othervm ConfPlusProp 31 * @summary krb5.conf ignored if system properties on realm and kdc are provided 32 */ 33 34import sun.security.krb5.Config; 35 36public class ConfPlusProp { 37 Config config; 38 public static void main(String[] args) throws Exception { 39 if (System.getenv("USERDNSDOMAIN") != null || 40 System.getenv("LOGONSERVER") != null) { 41 System.out.println( 42 "Looks like a Windows machine in a domain. Skip test."); 43 return; 44 } 45 new ConfPlusProp().run(); 46 } 47 48 void refresh() throws Exception { 49 Config.refresh(); 50 config = Config.getInstance(); 51 } 52 53 void checkDefaultRealm(String r) throws Exception { 54 try { 55 if (!config.getDefaultRealm().equals(r)) { 56 throw new AssertionError("Default realm error"); 57 } 58 } catch (Exception e) { 59 if (r != null) throw e; 60 } 61 } 62 63 void check(String r, String k) throws Exception { 64 try { 65 if (!config.getKDCList(r).equals(k)) { 66 throw new AssertionError(r + " kdc not " + k); 67 } 68 } catch (Exception e) { 69 if (k != null) throw e; 70 } 71 } 72 73 void run() throws Exception { 74 75 // No prop, only conf 76 77 // Point to a file with existing default_realm 78 System.setProperty("java.security.krb5.conf", 79 System.getProperty("test.src", ".") +"/confplusprop.conf"); 80 refresh(); 81 82 checkDefaultRealm("R1"); 83 check("R1", "k1"); 84 check("R2", "old"); 85 check("R3", null); 86 if (!config.get("libdefaults", "forwardable").equals("well")) { 87 throw new Exception("Extra config error"); 88 } 89 90 // Point to a file with no libdefaults 91 System.setProperty("java.security.krb5.conf", 92 System.getProperty("test.src", ".") +"/confplusprop2.conf"); 93 refresh(); 94 95 checkDefaultRealm(null); 96 check("R1", "k12"); 97 check("R2", "old"); 98 check("R3", null); 99 100 if (config.get("libdefaults", "forwardable") != null) { 101 throw new Exception("Extra config error"); 102 } 103 104 // Add prop 105 System.setProperty("java.security.krb5.realm", "R2"); 106 System.setProperty("java.security.krb5.kdc", "k2"); 107 108 // Point to a file with existing default_realm 109 System.setProperty("java.security.krb5.conf", 110 System.getProperty("test.src", ".") +"/confplusprop.conf"); 111 refresh(); 112 113 checkDefaultRealm("R2"); 114 check("R1", "k1"); 115 check("R2", "k2"); 116 check("R3", "k2"); 117 if (!config.get("libdefaults", "forwardable").equals("well")) { 118 throw new Exception("Extra config error"); 119 } 120 121 // Point to a file with no libdefaults 122 System.setProperty("java.security.krb5.conf", 123 System.getProperty("test.src", ".") +"/confplusprop2.conf"); 124 refresh(); 125 126 checkDefaultRealm("R2"); 127 check("R1", "k12"); 128 check("R2", "k2"); 129 check("R3", "k2"); 130 131 if (config.get("libdefaults", "forwardable") != null) { 132 throw new Exception("Extra config error"); 133 } 134 } 135} 136