J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2007 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.net.URL; |
| 26 | import java.net.MalformedURLException; |
| 27 | import sun.security.provider.*; |
| 28 | |
| 29 | public class GetInstancePolicySpi extends PolicySpi { |
| 30 | |
| 31 | private Policy p; |
| 32 | |
| 33 | public GetInstancePolicySpi(final Policy.Parameters params) { |
| 34 | p = AccessController.doPrivileged |
| 35 | (new PrivilegedAction<Policy>() { |
| 36 | public Policy run() { |
| 37 | if (params instanceof URIParameter) { |
| 38 | URIParameter uriParam = (URIParameter)params; |
| 39 | try { |
| 40 | URL url = uriParam.getURI().toURL(); |
| 41 | return new PolicyFile(url); |
| 42 | } catch (MalformedURLException mue) { |
| 43 | throw new IllegalArgumentException(mue); |
| 44 | } |
| 45 | } |
| 46 | return new PolicyFile(); |
| 47 | } |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | public boolean engineImplies(ProtectionDomain domain, Permission perm) { |
| 52 | |
| 53 | /** |
| 54 | * Note there is no need to capture own protection domain and |
| 55 | * return immediately if we are performing a check against ourself |
| 56 | * (a task normally needed for custom policy implementations). |
| 57 | * |
| 58 | * We simply call PolicyFile.implies - any doPrivileged |
| 59 | * that PolicyFile performs will truncate us from the current ACC. |
| 60 | */ |
| 61 | |
| 62 | return p.implies(domain, perm); |
| 63 | } |
| 64 | } |