jdk/test/sun/security/krb5/ConfPlusProp.java
author weijun
Wed, 08 Jul 2009 12:07:43 +0800
changeset 3221 98ac5a3e79e9
child 3315 2c61231c7973
permissions -rw-r--r--
6857795: krb5.conf ignored if system properties on realm and kdc are provided 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
/*
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    21
 * have any questions.
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
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    26
 * @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
    27
 */
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
import sun.security.krb5.Config;
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    30
import sun.security.krb5.KrbException;
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 {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    33
    public static void main(String[] args) throws Exception {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    34
        System.setProperty("java.security.krb5.realm", "R2");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    35
        System.setProperty("java.security.krb5.kdc", "k2");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    36
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    37
        // 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
    38
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    39
                System.getProperty("test.src", ".") +"/confplusprop.conf");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    40
        Config config = Config.getInstance();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    41
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    42
        if (!config.getDefaultRealm().equals("R2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    43
            throw new Exception("Default realm error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    44
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    45
        if (!config.getKDCList("R1").equals("k1")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    46
            throw new Exception("R1 kdc error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    47
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    48
        if (!config.getKDCList("R2").equals("k2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    49
            throw new Exception("R2 kdc error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    50
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    51
        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
    52
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    53
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    54
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    55
        // 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
    56
        System.setProperty("java.security.krb5.conf",
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    57
                System.getProperty("test.src", ".") +"/confplusprop2.conf");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    58
        Config.refresh();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    59
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    60
        config = Config.getInstance();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    61
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    62
        if (!config.getDefaultRealm().equals("R2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    63
            throw new Exception("Default realm error again");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    64
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    65
        if (!config.getKDCList("R1").equals("k12")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    66
            throw new Exception("R1 kdc error");
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
        if (!config.getKDCList("R2").equals("k2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    69
            throw new Exception("R2 kdc error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    70
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    71
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    72
        // Point to a non-existing file
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    73
        System.setProperty("java.security.krb5.conf", "i-am-not-a file");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    74
        Config.refresh();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    75
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    76
        config = Config.getInstance();
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    77
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    78
        if (!config.getDefaultRealm().equals("R2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    79
            throw new Exception("Default realm error");
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
        try {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    82
            config.getKDCList("R1");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    83
            throw new Exception("R1 is nowhere");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    84
        } catch (KrbException ke) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    85
            // OK
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    86
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    87
        if (!config.getKDCList("R2").equals("k2")) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    88
            throw new Exception("R2 kdc error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    89
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    90
        if (config.getDefault("forwardable", "libdefaults") != null) {
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    91
            throw new Exception("Extra config error");
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    92
        }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    93
    }
98ac5a3e79e9 6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff changeset
    94
}