test/jdk/java/security/Security/ClassLoader/DeprivilegedModuleLoaderTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 41226 jdk/test/java/security/Security/ClassLoader/DeprivilegedModuleLoaderTest.java@da753c438a07
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40392
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     1
/*
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     4
 *
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     8
 *
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    13
 * accompanied this code).
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    14
 *
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    18
 *
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    21
 * questions.
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    22
 */
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    23
41226
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    24
/*
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    25
 * @test
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    26
 * @bug 8159964
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    27
 * @summary Classes from deprivileged modules should get loaded through
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    28
 *          Platform Classloader.
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    29
 * @modules java.xml.crypto
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    30
 *          jdk.security.auth
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    31
 *          jdk.security.jgss
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    32
 * @run main DeprivilegedModuleLoaderTest
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    33
 */
da753c438a07 8166378: Missing dependencies in several java/security tests
skovalev
parents: 40392
diff changeset
    34
40392
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    35
import java.io.File;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    36
import java.util.ArrayList;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    37
import java.util.List;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    38
import javax.security.auth.kerberos.KeyTab;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    39
import javax.xml.crypto.KeySelectorException;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    40
import javax.xml.crypto.dsig.XMLSignatureFactory;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    41
import com.sun.security.auth.callback.TextCallbackHandler;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    42
import com.sun.security.jgss.AuthorizationDataEntry;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    43
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    44
public class DeprivilegedModuleLoaderTest {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    45
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    46
    public static void main(String[] args) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    47
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    48
        boolean pass = true;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    49
        List<Class<?>> classes = getDeprivilegedClasses();
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    50
        for (Class<?> cls : classes) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    51
            try {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    52
                pass &= testPlatformClassLoader(cls);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    53
            } catch (Exception exc) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    54
                exc.printStackTrace(System.out);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    55
                pass = false;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    56
            }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    57
        }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    58
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    59
        if (!pass) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    60
            throw new RuntimeException("Atleast one test failed.");
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    61
        }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    62
    }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    63
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    64
    private static List<Class<?>> getDeprivilegedClasses() {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    65
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    66
        List<Class<?>> classes = new ArrayList<Class<?>>();
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    67
        // Test from java.xml.crypto/javax/xml/crypto/dsig package
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    68
        classes.add(XMLSignatureFactory.class);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    69
        // Test from java.xml.crypto/javax/xml/crypto package
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    70
        classes.add(KeySelectorException.class);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    71
        // Test From java.security.jgss/javax/security/auth/kerberos package
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    72
        classes.add(KeyTab.class);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    73
        // Test from jdk.security.jgss/com/sun/security/jgss package
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    74
        classes.add(AuthorizationDataEntry.class);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    75
        // Test from jdk.security.auth/com/sun/security/auth/callback package
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    76
        classes.add(TextCallbackHandler.class);
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    77
        return classes;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    78
    }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    79
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    80
    private static boolean testPlatformClassLoader(Class<?> cls) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    81
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    82
        ClassLoader loader = cls.getClassLoader();
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    83
        if (loader == null) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    84
            throw new RuntimeException(String.format(
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    85
                    "Loaded through Bootstrap Classloader: '%s'", cls));
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    86
        } else if (!loader.toString().contains("PlatformClassLoader")) {
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    87
            throw new RuntimeException(String.format(
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    88
                    "Not loaded through Platform ClassLoader: '%s'", cls));
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    89
        }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    90
        System.out.println(String.format(
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    91
                "Pass: '%s' get loaded through PlatformClassLoader", cls));
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    92
        return true;
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    93
    }
5265aeda7716 8159964: Update Tests to verify JDK build for "JDK-8159488 Deprivilege java.xml.crypto"
ssahoo
parents:
diff changeset
    94
}