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 * @compile -XDignore.symbol.file ConfPlusProp.java 29 * @run main/othervm ConfPlusProp 30 * @summary krb5.conf ignored if system properties on realm and kdc are provided 31 */ 32 33 import sun.security.krb5.Config; 34 35 public class ConfPlusProp { 36 Config config; 37 public static void main(String[] args) throws Exception { 38 if (System.getenv("USERDNSDOMAIN") != null || 39 System.getenv("LOGONSERVER") != null) { 40 System.out.println( 41 "Looks like a Windows machine in a domain. Skip test."); 42 return; 43 } 44 new ConfPlusProp().run(); 45 } 46 47 void refresh() throws Exception { 48 Config.refresh(); 49 config = Config.getInstance(); 50 } 51 52 void checkDefaultRealm(String r) throws Exception { 53 try { 54 if (!config.getDefaultRealm().equals(r)) { 55 throw new AssertionError("Default realm error"); 56 } 57 } catch (Exception e) { 58 if (r != null) throw e; 59 } 60 } 61 62 void check(String r, String k) throws Exception { 63 try { 64 if (!config.getKDCList(r).equals(k)) { 65 throw new AssertionError(r + " kdc not " + k); 66 } 67 } catch (Exception e) { 68 if (k != null) throw e; 69 } 70 } 71 72 void run() throws Exception { 73 74 // No prop, only conf 75 76 // Point to a file with existing default_realm 77 System.setProperty("java.security.krb5.conf", 78 System.getProperty("test.src", ".") +"/confplusprop.conf"); 79 refresh(); 80 81 checkDefaultRealm("R1"); 82 check("R1", "k1"); 83 check("R2", "old"); 84 check("R3", null); 85 if (!config.get("libdefaults", "forwardable").equals("well")) { 86 throw new Exception("Extra config error"); 87 } 88 89 // Point to a file with no libdefaults 90 System.setProperty("java.security.krb5.conf", 91 System.getProperty("test.src", ".") +"/confplusprop2.conf"); 92 refresh(); 93 94 checkDefaultRealm(null); 95 check("R1", "k12"); 96 check("R2", "old"); 97 check("R3", null); 98 99 if (config.get("libdefaults", "forwardable") != null) { 100 throw new Exception("Extra config error"); 101 } 102 103 // Add prop 104 System.setProperty("java.security.krb5.realm", "R2"); 105 System.setProperty("java.security.krb5.kdc", "k2"); 106 107 // Point to a file with existing default_realm 108 System.setProperty("java.security.krb5.conf", 109 System.getProperty("test.src", ".") +"/confplusprop.conf"); 110 refresh(); 111 112 checkDefaultRealm("R2"); 113 check("R1", "k1"); 114 check("R2", "k2"); 115 check("R3", "k2"); 116 if (!config.get("libdefaults", "forwardable").equals("well")) { 117 throw new Exception("Extra config error"); 118 } 119 120 // Point to a file with no libdefaults 121 System.setProperty("java.security.krb5.conf", 122 System.getProperty("test.src", ".") +"/confplusprop2.conf"); 123 refresh(); 124 125 checkDefaultRealm("R2"); 126 check("R1", "k12"); 127 check("R2", "k2"); 128 check("R3", "k2"); 129 130 if (config.get("libdefaults", "forwardable") != null) { 131 throw new Exception("Extra config error"); 132 } 133 } 134 }