153 sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION);
154 return getPolicyNoCheck();
155 }
156
157 /**
158 * Returns the installed Policy object, skipping the security check.
159 * Used by ProtectionDomain and getPolicy.
160 *
161 * @return the installed Policy.
162 */
163 static Policy getPolicyNoCheck()
164 {
165 PolicyInfo pi = policy.get();
166 // Use double-check idiom to avoid locking if system-wide policy is
167 // already initialized
168 if (pi.initialized == false || pi.policy == null) {
169 synchronized (Policy.class) {
170 PolicyInfo pinfo = policy.get();
171 if (pinfo.policy == null) {
172 String policy_class = AccessController.doPrivileged(
173 new PrivilegedAction<String>() {
174 public String run() {
175 return Security.getProperty("policy.provider");
176 }
177 });
178 if (policy_class == null) {
179 policy_class = "sun.security.provider.PolicyFile";
180 }
181
182 try {
183 pinfo = new PolicyInfo(
184 (Policy) Class.forName(policy_class).newInstance(),
185 true);
186 } catch (Exception e) {
187 /*
188 * The policy_class seems to be an extension
189 * so we have to bootstrap loading it via a policy
190 * provider that is on the bootclasspath.
191 * If it loads then shift gears to using the configured
192 * provider.
193 */
194
195 // install the bootstrap provider to avoid recursion
196 Policy polFile = new sun.security.provider.PolicyFile();
197 pinfo = new PolicyInfo(polFile, false);
198 policy.set(pinfo);
199
200 final String pc = policy_class;
201 Policy pol = AccessController.doPrivileged(
202 new PrivilegedAction<Policy>() {
203 public Policy run() {
204 try {
205 ClassLoader cl =
206 ClassLoader.getSystemClassLoader();
207 // we want the extension loader
208 ClassLoader extcl = null;
209 while (cl != null) {
210 extcl = cl;
211 cl = cl.getParent();
212 }
213 return (extcl != null ? (Policy)Class.forName(
214 pc, true, extcl).newInstance() : null);
215 } catch (Exception e) {
216 if (debug != null) {
217 debug.println("policy provider " +
218 pc +
219 " not available");
220 e.printStackTrace();
221 }
222 return null;
286 * security checks fulfilling a call to either Policy.implies
287 * or Policy.getPermissions. If this does occur the provider
288 * must be able to answer for it's own ProtectionDomain
289 * without triggering additional security checks, otherwise
290 * the policy implementation will end up in an infinite
291 * recursion.
292 *
293 * To mitigate this, the provider can collect it's own
294 * ProtectionDomain and associate a PermissionCollection while
295 * it is being installed. The currently installed policy
296 * provider (if there is one) will handle calls to
297 * Policy.implies or Policy.getPermissions during this
298 * process.
299 *
300 * This Policy superclass caches away the ProtectionDomain and
301 * statically binds permissions so that legacy Policy
302 * implementations will continue to function.
303 */
304
305 ProtectionDomain policyDomain =
306 AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
307 public ProtectionDomain run() {
308 return p.getClass().getProtectionDomain();
309 }
310 });
311
312 /*
313 * Collect the permissions granted to this protection domain
314 * so that the provider can be security checked while processing
315 * calls to Policy.implies or Policy.getPermissions.
316 */
317 PermissionCollection policyPerms = null;
318 synchronized (p) {
319 if (p.pdMapping == null) {
320 p.pdMapping = new WeakHashMap<>();
321 }
322 }
323
324 if (policyDomain.getCodeSource() != null) {
325 Policy pol = policy.get().policy;
326 if (pol != null) {
|
153 sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION);
154 return getPolicyNoCheck();
155 }
156
157 /**
158 * Returns the installed Policy object, skipping the security check.
159 * Used by ProtectionDomain and getPolicy.
160 *
161 * @return the installed Policy.
162 */
163 static Policy getPolicyNoCheck()
164 {
165 PolicyInfo pi = policy.get();
166 // Use double-check idiom to avoid locking if system-wide policy is
167 // already initialized
168 if (pi.initialized == false || pi.policy == null) {
169 synchronized (Policy.class) {
170 PolicyInfo pinfo = policy.get();
171 if (pinfo.policy == null) {
172 String policy_class = AccessController.doPrivileged(
173 new PrivilegedAction<>() {
174 public String run() {
175 return Security.getProperty("policy.provider");
176 }
177 });
178 if (policy_class == null) {
179 policy_class = "sun.security.provider.PolicyFile";
180 }
181
182 try {
183 pinfo = new PolicyInfo(
184 (Policy) Class.forName(policy_class).newInstance(),
185 true);
186 } catch (Exception e) {
187 /*
188 * The policy_class seems to be an extension
189 * so we have to bootstrap loading it via a policy
190 * provider that is on the bootclasspath.
191 * If it loads then shift gears to using the configured
192 * provider.
193 */
194
195 // install the bootstrap provider to avoid recursion
196 Policy polFile = new sun.security.provider.PolicyFile();
197 pinfo = new PolicyInfo(polFile, false);
198 policy.set(pinfo);
199
200 final String pc = policy_class;
201 Policy pol = AccessController.doPrivileged(
202 new PrivilegedAction<>() {
203 public Policy run() {
204 try {
205 ClassLoader cl =
206 ClassLoader.getSystemClassLoader();
207 // we want the extension loader
208 ClassLoader extcl = null;
209 while (cl != null) {
210 extcl = cl;
211 cl = cl.getParent();
212 }
213 return (extcl != null ? (Policy)Class.forName(
214 pc, true, extcl).newInstance() : null);
215 } catch (Exception e) {
216 if (debug != null) {
217 debug.println("policy provider " +
218 pc +
219 " not available");
220 e.printStackTrace();
221 }
222 return null;
286 * security checks fulfilling a call to either Policy.implies
287 * or Policy.getPermissions. If this does occur the provider
288 * must be able to answer for it's own ProtectionDomain
289 * without triggering additional security checks, otherwise
290 * the policy implementation will end up in an infinite
291 * recursion.
292 *
293 * To mitigate this, the provider can collect it's own
294 * ProtectionDomain and associate a PermissionCollection while
295 * it is being installed. The currently installed policy
296 * provider (if there is one) will handle calls to
297 * Policy.implies or Policy.getPermissions during this
298 * process.
299 *
300 * This Policy superclass caches away the ProtectionDomain and
301 * statically binds permissions so that legacy Policy
302 * implementations will continue to function.
303 */
304
305 ProtectionDomain policyDomain =
306 AccessController.doPrivileged(new PrivilegedAction<>() {
307 public ProtectionDomain run() {
308 return p.getClass().getProtectionDomain();
309 }
310 });
311
312 /*
313 * Collect the permissions granted to this protection domain
314 * so that the provider can be security checked while processing
315 * calls to Policy.implies or Policy.getPermissions.
316 */
317 PermissionCollection policyPerms = null;
318 synchronized (p) {
319 if (p.pdMapping == null) {
320 p.pdMapping = new WeakHashMap<>();
321 }
322 }
323
324 if (policyDomain.getCodeSource() != null) {
325 Policy pol = policy.get().policy;
326 if (pol != null) {
|