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