jdk/test/sun/security/krb5/ConfPlusProp.java
author weijun
Mon, 26 Jul 2010 17:21:51 +0800
changeset 6123 664a0a541d26
parent 5506 202f599c92aa
child 9008 1c23e333dd76
permissions -rw-r--r--
6972005: ConfPlusProp.java test failure when DNS has info for realm 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
/*
6123
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
     2
 * Copyright (c) 2009, 2010, 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
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    28
 * @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
    29
 */
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    30
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    31
import sun.security.krb5.Config;
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
public class ConfPlusProp {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    34
    Config config;
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    36
        new ConfPlusProp().run();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    37
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    38
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    39
    void refresh() throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    40
        Config.refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    41
        config = Config.getInstance();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    42
    }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    43
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    44
    void checkDefaultRealm(String r) throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    45
        try {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    46
            if (!config.getDefaultRealm().equals(r)) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    47
                throw new AssertionError("Default realm error");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    48
            }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    49
        } catch (Exception e) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    50
            if (r != null) throw e;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    51
        }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    52
    }
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
    void check(String r, String k) throws Exception {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    55
        try {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    56
            if (!config.getKDCList(r).equals(k)) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    57
                throw new AssertionError(r + " kdc not " + k);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    58
            }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    59
        } catch (Exception e) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    60
            if (k != null) throw e;
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    61
        }
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    62
    }
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
    void run() throws Exception {
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
        // No prop, only conf
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    67
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    68
        // 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
    69
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    70
                System.getProperty("test.src", ".") +"/confplusprop.conf");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    71
        refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    72
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    73
        checkDefaultRealm("R1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    74
        check("R1", "k1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    75
        check("R2", "old");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    76
        check("R3", null);
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    77
        if (!config.getDefault("forwardable", "libdefaults").equals("well")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    78
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    79
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    80
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    81
        // 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
    82
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    83
                System.getProperty("test.src", ".") +"/confplusprop2.conf");
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    84
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    85
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    86
        checkDefaultRealm(null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    87
        check("R1", "k12");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    88
        check("R2", "old");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    89
        check("R3", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    90
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    91
        int version = System.getProperty("java.version").charAt(2) - '0';
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    92
        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
    93
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    94
        // Zero-config is supported since 1.7
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    95
        if (version >= 7) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    96
            // Point to a non-existing file
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
    97
            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
    98
            refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    99
6123
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
   100
            // Default realm might come from DNS
664a0a541d26 6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents: 5506
diff changeset
   101
            //checkDefaultRealm(null);
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   102
            check("R1", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   103
            check("R2", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   104
            check("R3", null);
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   105
            if (config.getDefault("forwardable", "libdefaults") != null) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   106
                throw new Exception("Extra config error");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   107
            }
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   108
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   109
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   110
        // Add prop
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   111
        System.setProperty("java.security.krb5.realm", "R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   112
        System.setProperty("java.security.krb5.kdc", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   113
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   114
        // Point to a file with existing default_realm
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   115
        System.setProperty("java.security.krb5.conf",
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   116
                System.getProperty("test.src", ".") +"/confplusprop.conf");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   117
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   118
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   119
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   120
        check("R1", "k1");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   121
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   122
        check("R3", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   123
        if (!config.getDefault("forwardable", "libdefaults").equals("well")) {
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   124
            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
   125
        }
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   126
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   127
        // Point to a file with no libdefaults
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   128
        System.setProperty("java.security.krb5.conf",
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   129
                System.getProperty("test.src", ".") +"/confplusprop2.conf");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   130
        refresh();
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   131
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   132
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   133
        check("R1", "k12");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   134
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   135
        check("R3", "k2");
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   136
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   137
        // Point to a non-existing file
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   138
        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
   139
        refresh();
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   140
3315
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   141
        checkDefaultRealm("R2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   142
        check("R1", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   143
        check("R2", "k2");
2c61231c7973 6858589: more changes to Config on system properties
weijun
parents: 3221
diff changeset
   144
        check("R3", "k2");
3221
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   145
        if (config.getDefault("forwardable", "libdefaults") != null) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   146
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   147
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   148
    }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
   149
}