Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/Policy/Dynamic/DynamicPolicy.java
38828 views
/*1* Copyright (c) 2000, 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 java.security.*;24import java.util.PropertyPermission;25import java.net.SocketPermission;26import java.lang.*;2728public class DynamicPolicy extends Policy{2930static int refresher = 0;313233public DynamicPolicy() {34}3536public PermissionCollection getPermissions(CodeSource cs) {3738Permissions perms = new Permissions();39initStaticPolicy(perms);40// Defalut policy in the beginning...41// toggle from refresh to refresh42if (refresher == 1)43perms.add(new PropertyPermission("user.name","read"));4445System.err.println("perms=[" + perms + "]");46return perms;47}4849public boolean implies(ProtectionDomain pd, Permission p) {50return getPermissions(pd).implies(p);51}5253public PermissionCollection getPermissions(ProtectionDomain pd) {5455Permissions perms = new Permissions();56initStaticPolicy(perms);57// Defalut policy in the beginning...58// toggle from refresh to refresh59if (refresher == 1)60perms.add(new PropertyPermission("user.name","read"));6162return perms;63}6465public void refresh() {66refresher++;67}6869private void initStaticPolicy(PermissionCollection perms) {7071perms.add(new java.security.SecurityPermission("getPolicy"));72perms.add(new java.security.SecurityPermission("setPolicy"));73perms.add(new java.lang.RuntimePermission("stopThread"));74perms.add(new java.net.SocketPermission("localhost:1024-", "listen"));75perms.add(new PropertyPermission("java.version","read"));76perms.add(new PropertyPermission("java.vendor","read"));77perms.add(new PropertyPermission("java.vendor.url","read"));78perms.add(new PropertyPermission("java.class.version","read"));79perms.add(new PropertyPermission("os.name","read"));80perms.add(new PropertyPermission("os.version","read"));81perms.add(new PropertyPermission("os.arch","read"));82perms.add(new PropertyPermission("file.separator","read"));83perms.add(new PropertyPermission("path.separator","read"));84perms.add(new PropertyPermission("line.separator","read"));85perms.add(new PropertyPermission("java.specification.version", "read"));86perms.add(new PropertyPermission("java.specification.vendor", "read"));87perms.add(new PropertyPermission("java.specification.name", "read"));88perms.add(new PropertyPermission("java.vm.specification.version", "read"));89perms.add(new PropertyPermission("java.vm.specification.vendor", "read"));90perms.add(new PropertyPermission("java.vm.specification.name", "read"));91perms.add(new PropertyPermission("java.vm.version", "read"));92perms.add(new PropertyPermission("java.vm.vendor", "read"));93perms.add(new PropertyPermission("java.vm.name", "read"));94return;95}96}979899