Path: blob/master/test/jdk/sun/security/provider/PolicyParser/ExtDirsChange.java
41152 views
/*1* Copyright (c) 2004, 2014, 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 499381926* @summary standard extensions path is hard-coded in default27* system policy file28* @run main/manual ExtDirsChange29*/3031/*32* Run this test manually with:33* javac ExtDirChange34* rm ExtDirsA*.class ExtDirsB*.class35* java -Djava.security.manager \36* -Dtest.src=. \37* -Djava.security.policy=ExtDirsChange.policy \38* -Djava.security.debug=parser \39* -cp ExtDirsA/a.jar:ExtDirsB/b.jar:. \40* ExtDirsChange41*/4243import java.io.File;44import java.security.*;4546public class ExtDirsChange {47public static void main(String args[]) throws Exception {48System.out.println("java.ext.dirs: " +49System.getProperty("java.ext.dirs"));5051// Uses default security policy and java.ext.dirs52try {53ExtDirsA a = new ExtDirsA();54a.go();55throw new Exception("Test Failed (Setup problem)");56} catch (SecurityException se) {57System.out.println("Setup OK");58}5960// Change java.ext.dirs and refresh policy61AccessController.doPrivileged(new PrivilegedAction() {62public Object run() {63// Change java.ext.dirs64System.setProperty("java.ext.dirs",65"ExtDirsA" + File.pathSeparator + "ExtDirsB");66System.out.println("java.ext.dirs: " +67System.getProperty("java.ext.dirs"));68return null;69}70});7172// Continue to use default security policy73try {74ExtDirsA a = new ExtDirsA();75a.go();76throw new Exception("Test Failed (Setup before refresh problem)");77} catch (SecurityException se) {78System.out.println("Setup before refresh OK");79}8081// Refresh policy using updated java.ext.dirs82AccessController.doPrivileged(new PrivilegedAction() {83public Object run() {84Policy.getPolicy().refresh();85return null;86}87});8889// Test should now succeed90try {91ExtDirsA a = new ExtDirsA();92a.go();93System.out.println("Test Succeeded");94} catch (SecurityException se) {95se.printStackTrace();96System.out.println("Test Failed");97throw se;98}99100// Test with blank java.ext.dir101// Change java.ext.dirs and refresh policy102AccessController.doPrivileged(new PrivilegedAction() {103public Object run() {104// Change java.ext.dirs105System.setProperty("java.ext.dirs", " ");106System.out.println("java.ext.dirs: " +107System.getProperty("java.ext.dirs"));108Policy.getPolicy().refresh();109return null;110}111});112113// Test with blank java.ext.dir114try {115ExtDirsA a = new ExtDirsA();116a.go();117throw new Exception("Blank Test Failed");118} catch (SecurityException se) {119System.out.println("Blank Test OK");120}121}122}123124125