< prev index next >

test/sun/security/krb5/ConfPlusProp.java

Print this page
rev 10772 : imported patch 8077102-dns_lookup_realm-should-be-false-by-default


  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         new ConfPlusProp().run();
  39     }
  40 
  41     void refresh() throws Exception {
  42         Config.refresh();
  43         config = Config.getInstance();
  44     }
  45 
  46     void checkDefaultRealm(String r) throws Exception {
  47         try {
  48             if (!config.getDefaultRealm().equals(r)) {
  49                 throw new AssertionError("Default realm error");
  50             }
  51         } catch (Exception e) {
  52             if (r != null) throw e;
  53         }
  54     }
  55 
  56     void check(String r, String k) throws Exception {
  57         try {


  73         refresh();
  74 
  75         checkDefaultRealm("R1");
  76         check("R1", "k1");
  77         check("R2", "old");
  78         check("R3", null);
  79         if (!config.get("libdefaults", "forwardable").equals("well")) {
  80             throw new Exception("Extra config error");
  81         }
  82 
  83         // Point to a file with no libdefaults
  84         System.setProperty("java.security.krb5.conf",
  85                 System.getProperty("test.src", ".") +"/confplusprop2.conf");
  86         refresh();
  87 
  88         checkDefaultRealm(null);
  89         check("R1", "k12");
  90         check("R2", "old");
  91         check("R3", null);
  92 
  93         int version = System.getProperty("java.version").charAt(2) - '0';
  94         System.out.println("JDK version is " + version);
  95 
  96         // Zero-config is supported since 1.7
  97         if (version >= 7) {
  98             // Point to a non-existing file
  99             System.setProperty("java.security.krb5.conf", "i-am-not-a file");
 100             refresh();
 101 
 102             // Default realm might come from DNS
 103             //checkDefaultRealm(null);
 104             check("R1", null);
 105             check("R2", null);
 106             check("R3", null);
 107             if (config.get("libdefaults", "forwardable") != null) {
 108                 throw new Exception("Extra config error");
 109             }
 110         }
 111 
 112         // Add prop
 113         System.setProperty("java.security.krb5.realm", "R2");
 114         System.setProperty("java.security.krb5.kdc", "k2");
 115 
 116         // Point to a file with existing default_realm
 117         System.setProperty("java.security.krb5.conf",
 118                 System.getProperty("test.src", ".") +"/confplusprop.conf");
 119         refresh();
 120 
 121         checkDefaultRealm("R2");
 122         check("R1", "k1");
 123         check("R2", "k2");
 124         check("R3", "k2");
 125         if (!config.get("libdefaults", "forwardable").equals("well")) {
 126             throw new Exception("Extra config error");
 127         }
 128 
 129         // Point to a file with no libdefaults
 130         System.setProperty("java.security.krb5.conf",
 131                 System.getProperty("test.src", ".") +"/confplusprop2.conf");
 132         refresh();
 133 
 134         checkDefaultRealm("R2");
 135         check("R1", "k12");
 136         check("R2", "k2");
 137         check("R3", "k2");
 138 
 139         // Point to a non-existing file
 140         System.setProperty("java.security.krb5.conf", "i-am-not-a file");
 141         refresh();
 142 
 143         checkDefaultRealm("R2");
 144         check("R1", "k2");
 145         check("R2", "k2");
 146         check("R3", "k2");
 147         if (config.get("libdefaults", "forwardable") != null) {
 148             throw new Exception("Extra config error");
 149         }
 150     }
 151 }


  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 {


  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 }
< prev index next >