Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/ProcessBuilder/SecurityManagerClinit.java
47209 views
/*1* Copyright 2010 Google Inc. 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 698074726* @summary Check that Process-related classes have the proper27* doPrivileged blocks, and can be initialized with an adversarial28* security manager.29* @run main/othervm SecurityManagerClinit30* @author Martin Buchholz31*/3233import java.io.*;34import java.security.*;3536public class SecurityManagerClinit {37private static class Policy extends java.security.Policy {38private Permissions perms;3940public Policy(Permission... permissions) {41perms = new Permissions();42for (Permission permission : permissions)43perms.add(permission);44}4546public boolean implies(ProtectionDomain pd, Permission p) {47return perms.implies(p);48}49}5051public static void main(String[] args) throws Throwable {52String javaExe =53System.getProperty("java.home") +54File.separator + "bin" + File.separator + "java";5556final Policy policy =57new Policy58(new FilePermission("<<ALL FILES>>", "execute"),59new RuntimePermission("setSecurityManager"));60Policy.setPolicy(policy);6162System.setSecurityManager(new SecurityManager());6364try {65String[] cmd = { javaExe, "-version" };66Process p = Runtime.getRuntime().exec(cmd);67p.getOutputStream().close();68p.getInputStream().close();69p.getErrorStream().close();70p.waitFor();71} finally {72System.setSecurityManager(null);73}74}75}767778