Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/PolicyParser/ExtDirsChange.java
38853 views
/*1* Copyright (c) 2004, 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* @ignore run this by hand29*30* javac ExtDirChange31* rm ExtDirsA*.class ExtDirsB*.class32* java -Djava.security.manager \33* -Dtest.src=. \34* -Djava.security.policy=ExtDirsChange.policy \35* -Djava.security.debug=parser \36* -cp ExtDirsA/a.jar:ExtDirsB/b.jar:. \37* ExtDirsChange38*/3940import java.io.File;41import java.security.*;4243public class ExtDirsChange {44public static void main(String args[]) throws Exception {45System.out.println("java.ext.dirs: " +46System.getProperty("java.ext.dirs"));4748// Uses default security policy and java.ext.dirs49try {50ExtDirsA a = new ExtDirsA();51a.go();52throw new Exception("Test Failed (Setup problem)");53} catch (SecurityException se) {54System.out.println("Setup OK");55}5657// Change java.ext.dirs and refresh policy58AccessController.doPrivileged(new PrivilegedAction() {59public Object run() {60// Change java.ext.dirs61System.setProperty("java.ext.dirs",62"ExtDirsA" + File.pathSeparator + "ExtDirsB");63System.out.println("java.ext.dirs: " +64System.getProperty("java.ext.dirs"));65return null;66}67});6869// Continue to use default security policy70try {71ExtDirsA a = new ExtDirsA();72a.go();73throw new Exception("Test Failed (Setup before refresh problem)");74} catch (SecurityException se) {75System.out.println("Setup before refresh OK");76}7778// Refresh policy using updated java.ext.dirs79AccessController.doPrivileged(new PrivilegedAction() {80public Object run() {81Policy.getPolicy().refresh();82return null;83}84});8586// Test should now succeed87try {88ExtDirsA a = new ExtDirsA();89a.go();90System.out.println("Test Succeeded");91} catch (SecurityException se) {92se.printStackTrace();93System.out.println("Test Failed");94throw se;95}9697// Test with blank java.ext.dir98// Change java.ext.dirs and refresh policy99AccessController.doPrivileged(new PrivilegedAction() {100public Object run() {101// Change java.ext.dirs102System.setProperty("java.ext.dirs", " ");103System.out.println("java.ext.dirs: " +104System.getProperty("java.ext.dirs"));105Policy.getPolicy().refresh();106return null;107}108});109110// Test with blank java.ext.dir111try {112ExtDirsA a = new ExtDirsA();113a.go();114throw new Exception("Blank Test Failed");115} catch (SecurityException se) {116System.out.println("Blank Test OK");117}118}119}120121122