1 /*
   2  * Copyright (c) 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 7184246
  26  * @compile -XDignore.symbol.file Duplicates.java
  27  * @run main/othervm Duplicates
  28  * @summary Simplify Config.get() of krb5
  29  */
  30 
  31 import sun.security.krb5.Config;
  32 
  33 public class Duplicates {
  34     public static void main(String[] args) throws Exception {
  35         System.setProperty("java.security.krb5.conf",
  36                 System.getProperty("test.src", ".") +"/k1.conf");
  37         Config config = Config.getInstance();
  38         config.listTable();
  39         String s;
  40 
  41         // root section merged
  42         s = config.get("libdefaults", "default_realm");
  43         if (!s.equals("R1")) {
  44             throw new Exception();
  45         }
  46         // Former is preferred to latter for strings and sections
  47         s = config.get("libdefaults", "default_tkt_enctypes");
  48         if (!s.equals("aes128-cts")) {
  49             throw new Exception();
  50         }
  51         s = config.get("realms", "R1", "kdc");
  52         if (!s.equals("k1")) {
  53             throw new Exception(s);
  54         }
  55         // Duplicate keys in [realms] are merged, and sections with the same
  56         // name in between ignored
  57         s = config.getAll("realms", "R2", "kdc");
  58         if (!s.equals("k1 k2 k3 k4")) {
  59             throw new Exception(s);
  60         }
  61         // Duplicate keys in [capaths] are merged
  62         s = config.getAll("capaths", "R1", "R2");
  63         if (!s.equals("R3 R4 R5 R6")) {
  64             throw new Exception(s);
  65         }
  66         // We can be very deep now
  67         s = config.get("new", "x", "y", "z", "a", "b", "c");
  68         if (!s.equals("d")) {
  69             throw new Exception(s);
  70         }
  71     }
  72 }