jdk/test/sun/security/krb5/ConfPlusProp.java
author weijun
Mon, 29 Oct 2012 14:14:06 +0800
changeset 14327 c0d86f6f8be8
parent 9008 1c23e333dd76
child 14342 8435a30053c1
permissions -rw-r--r--
7184246: Simplify Config.get() of krb5 Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     1
/*
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 6123
diff changeset
     2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     4
 *
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     8
 *
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    13
 * accompanied this code).
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    14
 *
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3422
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3422
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3422
diff changeset
    21
 * questions.
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    22
 */
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    23
/*
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    24
 * @test
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    25
 * @bug 6857795
3422
72bf5182bb8b 6867231: Regression: jdk/test/sun/security/krb5/ConfPlusProp.java error against jdk7/pit/b68
weijun
parents: 3315
diff changeset
    26
 * @bug 6858589
6123
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
    27
 * @bug 6972005
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 9008
diff changeset
    28
 * @compile -XDignore.symbol.file ConfPlusProp.java
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 6123
diff changeset
    29
 * @run main/othervm ConfPlusProp
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    30
 * @summary krb5.conf ignored if system properties on realm and kdc are provided
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    31
 */
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    32
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    33
import sun.security.krb5.Config;
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    34
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    35
public class ConfPlusProp {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    36
    Config config;
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    38
        new ConfPlusProp().run();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    39
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    40
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    41
    void refresh() throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    42
        Config.refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    43
        config = Config.getInstance();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    44
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    45
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    46
    void checkDefaultRealm(String r) throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    47
        try {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    48
            if (!config.getDefaultRealm().equals(r)) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    49
                throw new AssertionError("Default realm error");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    50
            }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    51
        } catch (Exception e) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    52
            if (r != null) throw e;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    53
        }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    54
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    55
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    56
    void check(String r, String k) throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    57
        try {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    58
            if (!config.getKDCList(r).equals(k)) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    59
                throw new AssertionError(r + " kdc not " + k);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    60
            }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    61
        } catch (Exception e) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    62
            if (k != null) throw e;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    63
        }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    64
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    65
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    66
    void run() throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    67
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    68
        // No prop, only conf
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    69
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    70
        // Point to a file with existing default_realm
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    71
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    72
                System.getProperty("test.src", ".") +"/confplusprop.conf");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    73
        refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    74
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    75
        checkDefaultRealm("R1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    76
        check("R1", "k1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    77
        check("R2", "old");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    78
        check("R3", null);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 9008
diff changeset
    79
        if (!config.get("libdefaults", "forwardable").equals("well")) {
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    80
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    81
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    82
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    83
        // Point to a file with no libdefaults
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    84
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    85
                System.getProperty("test.src", ".") +"/confplusprop2.conf");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    86
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    87
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    88
        checkDefaultRealm(null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    89
        check("R1", "k12");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    90
        check("R2", "old");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    91
        check("R3", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    92
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    93
        int version = System.getProperty("java.version").charAt(2) - '0';
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    94
        System.out.println("JDK version is " + version);
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    95
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    96
        // Zero-config is supported since 1.7
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    97
        if (version >= 7) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    98
            // Point to a non-existing file
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    99
            System.setProperty("java.security.krb5.conf", "i-am-not-a file");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   100
            refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   101
6123
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
   102
            // Default realm might come from DNS
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
   103
            //checkDefaultRealm(null);
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   104
            check("R1", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   105
            check("R2", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   106
            check("R3", null);
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 9008
diff changeset
   107
            if (config.get("libdefaults", "forwardable") != null) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   108
                throw new Exception("Extra config error");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   109
            }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   110
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   111
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   112
        // Add prop
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   113
        System.setProperty("java.security.krb5.realm", "R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   114
        System.setProperty("java.security.krb5.kdc", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   115
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   116
        // Point to a file with existing default_realm
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   117
        System.setProperty("java.security.krb5.conf",
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   118
                System.getProperty("test.src", ".") +"/confplusprop.conf");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   119
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   120
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   121
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   122
        check("R1", "k1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   123
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   124
        check("R3", "k2");
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 9008
diff changeset
   125
        if (!config.get("libdefaults", "forwardable").equals("well")) {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   126
            throw new Exception("Extra config error");
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   127
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   128
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   129
        // Point to a file with no libdefaults
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   130
        System.setProperty("java.security.krb5.conf",
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   131
                System.getProperty("test.src", ".") +"/confplusprop2.conf");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   132
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   133
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   134
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   135
        check("R1", "k12");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   136
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   137
        check("R3", "k2");
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   138
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   139
        // Point to a non-existing file
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   140
        System.setProperty("java.security.krb5.conf", "i-am-not-a file");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   141
        refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   142
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   143
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   144
        check("R1", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   145
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   146
        check("R3", "k2");
14327
c0d86f6f8be8 7184246: Simplify Config.get() of krb5
weijun
parents: 9008
diff changeset
   147
        if (config.get("libdefaults", "forwardable") != null) {
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   148
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   149
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   150
    }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   151
}