Path: blob/master/test/jdk/java/security/Security/ClassLoader/DeprivilegedModuleLoaderTest.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 815996426* @summary Classes from deprivileged modules should get loaded through27* Platform Classloader.28* @modules java.xml.crypto29* jdk.security.auth30* jdk.security.jgss31* @run main DeprivilegedModuleLoaderTest32*/3334import java.io.File;35import java.util.ArrayList;36import java.util.List;37import javax.security.auth.kerberos.KeyTab;38import javax.xml.crypto.KeySelectorException;39import javax.xml.crypto.dsig.XMLSignatureFactory;40import com.sun.security.auth.callback.TextCallbackHandler;41import com.sun.security.jgss.AuthorizationDataEntry;4243public class DeprivilegedModuleLoaderTest {4445public static void main(String[] args) {4647boolean pass = true;48List<Class<?>> classes = getDeprivilegedClasses();49for (Class<?> cls : classes) {50try {51pass &= testPlatformClassLoader(cls);52} catch (Exception exc) {53exc.printStackTrace(System.out);54pass = false;55}56}5758if (!pass) {59throw new RuntimeException("Atleast one test failed.");60}61}6263private static List<Class<?>> getDeprivilegedClasses() {6465List<Class<?>> classes = new ArrayList<Class<?>>();66// Test from java.xml.crypto/javax/xml/crypto/dsig package67classes.add(XMLSignatureFactory.class);68// Test from java.xml.crypto/javax/xml/crypto package69classes.add(KeySelectorException.class);70// Test From java.security.jgss/javax/security/auth/kerberos package71classes.add(KeyTab.class);72// Test from jdk.security.jgss/com/sun/security/jgss package73classes.add(AuthorizationDataEntry.class);74// Test from jdk.security.auth/com/sun/security/auth/callback package75classes.add(TextCallbackHandler.class);76return classes;77}7879private static boolean testPlatformClassLoader(Class<?> cls) {8081ClassLoader loader = cls.getClassLoader();82if (loader == null) {83throw new RuntimeException(String.format(84"Loaded through Bootstrap Classloader: '%s'", cls));85} else if (!loader.toString().contains("PlatformClassLoader")) {86throw new RuntimeException(String.format(87"Not loaded through Platform ClassLoader: '%s'", cls));88}89System.out.println(String.format(90"Pass: '%s' get loaded through PlatformClassLoader", cls));91return true;92}93}949596