jdk/test/javax/security/auth/SubjectDomainCombiner/Regression.java
author rupashka
Wed, 03 Aug 2011 16:59:23 +0400
changeset 10106 e2f028934e97
parent 5506 202f599c92aa
child 44357 e0fbf5f9da3c
permissions -rw-r--r--
7072328: Sun URL in the MetalLookAndFeel.getLayoutStyle() specification should be replaced with Oracle one Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4390546
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary     performance regression and other bugs in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *              SubjectDomainCombiner.combine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main/othervm/policy=Regression.policy -Djava.security.auth.debug=combiner Regression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.security.auth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.ProtectionDomain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class Regression {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        Set principals = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        principals.add(new com.sun.security.auth.NTUserPrincipal("test1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        principals.add(new com.sun.security.auth.NTUserPrincipal("test2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        Subject subject = new Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                (false, principals, new HashSet(), new HashSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        SubjectDomainCombiner sdc = new SubjectDomainCombiner(subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        URL url1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        URL url2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        URL url3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        URL url4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            url1 = new URL("http://one");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            url2 = new URL("http://two");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            url3 = new URL("http://three");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            url4 = new URL("http://four");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        } catch (java.net.MalformedURLException mue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            mue.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            throw new SecurityException("Test failed: " + mue.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        ProtectionDomain d1 = new ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                (new CodeSource(url1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                null,                   // permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                null,                   // class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                null);                  // principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        ProtectionDomain d2 = new ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                (new CodeSource(url2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                null,                   // permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                null,                   // class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                null);                  // principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ProtectionDomain d3 = new ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                (new CodeSource(url3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                null,                   // permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                null,                   // class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                null);                  // principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        ProtectionDomain d4 = new ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                (new CodeSource(url4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                null,                   // permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                null,                   // class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                null);                  // principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // test 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // -- regular combine, make sure we get a proper combination back
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        ProtectionDomain currentDomains[] = { d1, d2, d3 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        ProtectionDomain assignedDomains[] = { d4 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        ProtectionDomain domains1[] = sdc.combine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        (currentDomains, assignedDomains);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (domains1.length != 4 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            domains1[0] == d1 || domains1[1] == d2 || domains1[2] == d3 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            domains1[3] != d4 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            !domains1[0].implies(new RuntimePermission("queuePrintJob"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new SecurityException("Test failed: combine test 1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("-------- TEST ONE PASSED --------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // test 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // -- repeat combine, make sure combiner cachine returned the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        //    same PD's back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        ProtectionDomain domains2[] = sdc.combine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                        (currentDomains, assignedDomains);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (domains2.length != 4 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            domains2[0] != domains1[0] || domains2[1] != domains1[1] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            domains2[2] != domains1[2] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            domains2[3] != domains1[3] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            !domains2[0].implies(new RuntimePermission("queuePrintJob"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new SecurityException("Test failed: combine test 2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        System.out.println("-------- TEST TWO PASSED --------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // test 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // -- mutate the Subject and make sure the combiner cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //    got cleared out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        subject.getPrincipals().remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                (new com.sun.security.auth.NTUserPrincipal("test2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ProtectionDomain domains3[] = sdc.combine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        (currentDomains, assignedDomains);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (domains3.length != 4 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            domains3[0] == domains1[0] || domains3[1] == domains1[1] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            domains3[2] == domains1[2] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            domains3[3] != domains1[3] ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            !domains3[0].implies(new RuntimePermission("createClassLoader")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            domains3[0].implies(new RuntimePermission("queuePrintJob"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new SecurityException("Test failed: combine test 3 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        System.out.println("-------- TEST THREE PASSED --------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        System.out.println("Test Passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}