Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/Policy/ExtensiblePolicy/ExtensiblePolicyWithJarTest.java
38828 views
/*1* Copyright (c) 2015, 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*/2223import TVJar.TVPermission;24import java.io.File;25import java.nio.file.Files;26import java.nio.file.Paths;27import java.security.AccessController;28import jdk.testlibrary.ProcessTools;29import jdk.testlibrary.JarUtils;3031/**32* @test33* @bug 805040234* @summary Check policy is extensible with user defined permissions35* @library /lib/testlibrary36* @compile TVJar/TVPermission.java37* @run main ExtensiblePolicyWithJarTest38*/39public class ExtensiblePolicyWithJarTest {4041public static void main(String args[]) throws Throwable {42final String FS = File.separator;43final String PS = File.pathSeparator;44final String POL = "ExtensiblePolicyTest3.policy";45final String JAVA_HOME = System.getProperty("test.jdk");46final String KEYTOOL = JAVA_HOME + FS + "bin" + FS + "keytool";47final String JARSIGNER = JAVA_HOME + FS + "bin" + FS + "jarsigner";48final String KEYSTORE = "epkeystore";49final String PASSWORD = "password";50final String ALIAS = "duke2";51final String CLASSPATH = System.getProperty("test.class.path", "");52final String TESTCLASSES = System.getProperty("test.classes", "");53final String TVPERMJAR = "tvPerm.jar";54final String PATHTOJAR = System.getProperty("user.dir", "")55+ FS + TVPERMJAR;5657// create jar file for TVpermission58new File("TVJar").mkdir();59Files.copy(Paths.get(TESTCLASSES + FS + "TVJar", "TVPermission.class"),60Paths.get("TVJar", "TVPermission.class"));61Files.copy(Paths.get(TESTCLASSES + FS + "TVJar",62"TVPermissionCollection.class"),63Paths.get("TVJar", "TVPermissionCollection.class"));64JarUtils.createJar(TVPERMJAR, "TVJar/TVPermission.class",65"TVJar/TVPermissionCollection.class");6667// create key pair for jar signing68ProcessTools.executeCommand(KEYTOOL,69"-genkey",70"-alias", ALIAS,71"-keystore", KEYSTORE,72"-storetype", "JKS",73"-keypass", PASSWORD,74"-dname", "cn=Blah",75"-storepass", PASSWORD76).shouldHaveExitValue(0);77// sign jar78ProcessTools.executeCommand(JARSIGNER,79"-keystore", KEYSTORE,80"-storepass", PASSWORD,81"-keypass", PASSWORD,82TVPERMJAR,83ALIAS).shouldHaveExitValue(0);84// add jar file to classpath85String cp = PATHTOJAR + PS + CLASSPATH;8687// policy file grants permission signed by duke2 to watch TVChanel 588try {89String[] cmd = {90"-classpath", cp,91"-Djava.security.manager",92"-Djava.security.policy=" + POL,93"ExtensiblePolicyTest_orig$TestMain"};94ProcessTools.executeTestJvm(cmd).shouldHaveExitValue(0);95} catch (Exception ex) {96System.out.println("ExtensiblePolicyWithJarTest Failed");97}9899}100101public static class TestMain {102public static void main(String args[]) {103TVPermission perm = new TVPermission("channel:5", "watch");104try {105AccessController.checkPermission(perm);106} catch (SecurityException se) {107throw new RuntimeException(se);108}109}110}111112}113114115