Path: blob/master/test/jdk/java/security/Policy/ExtensiblePolicy/ExtensiblePolicyTest.java
41153 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.security.AccessController;2526/**27* @test @bug 805040228* @summary Check policy is extensible with user defined permissions29* @run main/othervm/policy=ExtensiblePolicyTest1.policy30* ExtensiblePolicyTest false31* @run main/othervm/policy=ExtensiblePolicyTest2.policy32* ExtensiblePolicyTest true33* @run main/othervm/policy=ExtensiblePolicyTest3.policy34* ExtensiblePolicyTest true35*/36public class ExtensiblePolicyTest {3738public static void main(String args[]) throws Throwable {39// ExtensiblePolicyTest1.policy: policy file grants permission to40// watch TVChannel 3-641// ExtensiblePolicyTest2.policy: policy file grants permission to42// watch TVChanel 443// ExtensiblePolicyTest3.policy: policy file grants permission signed44// by duke2 to watch TVChanel 54546TVPermission perm = new TVPermission("channel:5", "watch");47boolean getException = false;48String exceptionMessage = null;49boolean expectException = Boolean.parseBoolean(args[0]);50try {51AccessController.checkPermission(perm);52} catch (SecurityException se) {53getException = true;54exceptionMessage = se.getMessage();55}5657if (expectException ^ getException) {58throw new RuntimeException("Test Failed: expectException = "59+ expectException + " getException = " + getException60+ "\n" + exceptionMessage);61}62}6364}656667