J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | import java.security.*; |
| 25 | import java.util.PropertyPermission; |
| 26 | import java.net.SocketPermission; |
| 27 | import java.lang.*; |
| 28 | |
| 29 | public class DynamicPolicy extends Policy{ |
| 30 | |
| 31 | static int refresher = 0; |
| 32 | |
| 33 | |
| 34 | public DynamicPolicy() { |
| 35 | } |
| 36 | |
| 37 | public PermissionCollection getPermissions(CodeSource cs) { |
| 38 | |
| 39 | Permissions perms = new Permissions(); |
| 40 | initStaticPolicy(perms); |
| 41 | // Defalut policy in the beginning... |
| 42 | // toggle from refresh to refresh |
| 43 | if (refresher == 1) |
| 44 | perms.add(new PropertyPermission("user.name","read")); |
| 45 | |
| 46 | System.err.println("perms=[" + perms + "]"); |
| 47 | return perms; |
| 48 | } |
| 49 | |
| 50 | public boolean implies(ProtectionDomain pd, Permission p) { |
| 51 | return getPermissions(pd).implies(p); |
| 52 | } |
| 53 | |
| 54 | public PermissionCollection getPermissions(ProtectionDomain pd) { |
| 55 | |
| 56 | Permissions perms = new Permissions(); |
| 57 | initStaticPolicy(perms); |
| 58 | // Defalut policy in the beginning... |
| 59 | // toggle from refresh to refresh |
| 60 | if (refresher == 1) |
| 61 | perms.add(new PropertyPermission("user.name","read")); |
| 62 | |
| 63 | return perms; |
| 64 | } |
| 65 | |
| 66 | public void refresh() { |
| 67 | refresher++; |
| 68 | } |
| 69 | |
| 70 | private void initStaticPolicy(PermissionCollection perms) { |
| 71 | |
| 72 | perms.add(new java.security.SecurityPermission("getPolicy")); |
| 73 | perms.add(new java.security.SecurityPermission("setPolicy")); |
| 74 | perms.add(new java.lang.RuntimePermission("stopThread")); |
| 75 | perms.add(new java.net.SocketPermission("localhost:1024-", "listen")); |
| 76 | perms.add(new PropertyPermission("java.version","read")); |
| 77 | perms.add(new PropertyPermission("java.vendor","read")); |
| 78 | perms.add(new PropertyPermission("java.vendor.url","read")); |
| 79 | perms.add(new PropertyPermission("java.class.version","read")); |
| 80 | perms.add(new PropertyPermission("os.name","read")); |
| 81 | perms.add(new PropertyPermission("os.version","read")); |
| 82 | perms.add(new PropertyPermission("os.arch","read")); |
| 83 | perms.add(new PropertyPermission("file.separator","read")); |
| 84 | perms.add(new PropertyPermission("path.separator","read")); |
| 85 | perms.add(new PropertyPermission("line.separator","read")); |
| 86 | perms.add(new PropertyPermission("java.specification.version", "read")); |
| 87 | perms.add(new PropertyPermission("java.specification.vendor", "read")); |
| 88 | perms.add(new PropertyPermission("java.specification.name", "read")); |
| 89 | perms.add(new PropertyPermission("java.vm.specification.version", "read")); |
| 90 | perms.add(new PropertyPermission("java.vm.specification.vendor", "read")); |
| 91 | perms.add(new PropertyPermission("java.vm.specification.name", "read")); |
| 92 | perms.add(new PropertyPermission("java.vm.version", "read")); |
| 93 | perms.add(new PropertyPermission("java.vm.vendor", "read")); |
| 94 | perms.add(new PropertyPermission("java.vm.name", "read")); |
| 95 | return; |
| 96 | } |
| 97 | } |