Path: blob/master/test/jdk/java/security/Policy/GetInstance/GetInstancePolicySpi.java
41153 views
/*1* Copyright (c) 2005, 2007, 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.net.URL;25import java.net.MalformedURLException;26import sun.security.provider.*;2728public class GetInstancePolicySpi extends PolicySpi {2930private Policy p;3132public GetInstancePolicySpi(final Policy.Parameters params) {33p = AccessController.doPrivileged34(new PrivilegedAction<Policy>() {35public Policy run() {36if (params instanceof URIParameter) {37URIParameter uriParam = (URIParameter)params;38try {39URL url = uriParam.getURI().toURL();40return new PolicyFile(url);41} catch (MalformedURLException mue) {42throw new IllegalArgumentException(mue);43}44}45return new PolicyFile();46}47});48}4950public boolean engineImplies(ProtectionDomain domain, Permission perm) {5152/**53* Note there is no need to capture own protection domain and54* return immediately if we are performing a check against ourself55* (a task normally needed for custom policy implementations).56*57* We simply call PolicyFile.implies - any doPrivileged58* that PolicyFile performs will truncate us from the current ACC.59*/6061return p.implies(domain, perm);62}63}646566