286 {
287 String pkg = (String) iter.next();
288
289 // Prevent matching "sun" and "sunir" even if they
290 // starts with similar beginning characters
291 //
292 if (pkgname.equals(pkg) || pkgname.startsWith(pkg + "."))
293 {
294 checkPermission(new java.lang.RuntimePermission
295 ("accessClassInPackage." + pkgname));
296 }
297 }
298 }
299
300 /**
301 * Tests if a client can get access to the AWT event queue.
302 * <p>
303 * This method calls <code>checkPermission</code> with the
304 * <code>AWTPermission("accessEventQueue")</code> permission.
305 *
306 * @since JDK1.1
307 * @exception SecurityException if the caller does not have
308 * permission to access the AWT event queue.
309 */
310 public void checkAwtEventQueueAccess() {
311 AppContext appContext = AppContext.getAppContext();
312 AppletClassLoader appletClassLoader = currentAppletClassLoader();
313
314 if (AppContext.isMainContext(appContext) && (appletClassLoader != null)) {
315 // If we're about to allow access to the main EventQueue,
316 // and anything untrusted is on the class context stack,
317 // disallow access.
318 super.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION);
319 }
320 } // checkAwtEventQueueAccess()
321
322 /**
323 * Returns the thread group of the applet. We consult the classloader
324 * if there is one.
325 */
326 public ThreadGroup getThreadGroup() {
330 AppletClassLoader appletLoader = currentAppletClassLoader();
331 ThreadGroup loaderGroup = (appletLoader == null) ? null
332 : appletLoader.getThreadGroup();
333 if (loaderGroup != null) {
334 return loaderGroup;
335 } else {
336 return super.getThreadGroup();
337 }
338 } // getThreadGroup()
339
340 /**
341 * Get the AppContext corresponding to the current context.
342 * The default implementation returns null, but this method
343 * may be overridden by various SecurityManagers
344 * (e.g. AppletSecurity) to index AppContext objects by the
345 * calling context.
346 *
347 * @return the AppContext corresponding to the current context.
348 * @see sun.awt.AppContext
349 * @see java.lang.SecurityManager
350 * @since JDK1.2.1
351 */
352 public AppContext getAppContext() {
353 AppletClassLoader appletLoader = currentAppletClassLoader();
354
355 if (appletLoader == null) {
356 return null;
357 } else {
358 AppContext context = appletLoader.getAppContext();
359
360 // context == null when some thread in applet thread group
361 // has not been destroyed in AppContext.dispose()
362 if (context == null) {
363 throw new SecurityException("Applet classloader has invalid AppContext");
364 }
365
366 return context;
367 }
368 }
369
370 } // class AppletSecurity
|
286 {
287 String pkg = (String) iter.next();
288
289 // Prevent matching "sun" and "sunir" even if they
290 // starts with similar beginning characters
291 //
292 if (pkgname.equals(pkg) || pkgname.startsWith(pkg + "."))
293 {
294 checkPermission(new java.lang.RuntimePermission
295 ("accessClassInPackage." + pkgname));
296 }
297 }
298 }
299
300 /**
301 * Tests if a client can get access to the AWT event queue.
302 * <p>
303 * This method calls <code>checkPermission</code> with the
304 * <code>AWTPermission("accessEventQueue")</code> permission.
305 *
306 * @since 1.1
307 * @exception SecurityException if the caller does not have
308 * permission to access the AWT event queue.
309 */
310 public void checkAwtEventQueueAccess() {
311 AppContext appContext = AppContext.getAppContext();
312 AppletClassLoader appletClassLoader = currentAppletClassLoader();
313
314 if (AppContext.isMainContext(appContext) && (appletClassLoader != null)) {
315 // If we're about to allow access to the main EventQueue,
316 // and anything untrusted is on the class context stack,
317 // disallow access.
318 super.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION);
319 }
320 } // checkAwtEventQueueAccess()
321
322 /**
323 * Returns the thread group of the applet. We consult the classloader
324 * if there is one.
325 */
326 public ThreadGroup getThreadGroup() {
330 AppletClassLoader appletLoader = currentAppletClassLoader();
331 ThreadGroup loaderGroup = (appletLoader == null) ? null
332 : appletLoader.getThreadGroup();
333 if (loaderGroup != null) {
334 return loaderGroup;
335 } else {
336 return super.getThreadGroup();
337 }
338 } // getThreadGroup()
339
340 /**
341 * Get the AppContext corresponding to the current context.
342 * The default implementation returns null, but this method
343 * may be overridden by various SecurityManagers
344 * (e.g. AppletSecurity) to index AppContext objects by the
345 * calling context.
346 *
347 * @return the AppContext corresponding to the current context.
348 * @see sun.awt.AppContext
349 * @see java.lang.SecurityManager
350 * @since 1.2.1
351 */
352 public AppContext getAppContext() {
353 AppletClassLoader appletLoader = currentAppletClassLoader();
354
355 if (appletLoader == null) {
356 return null;
357 } else {
358 AppContext context = appletLoader.getAppContext();
359
360 // context == null when some thread in applet thread group
361 // has not been destroyed in AppContext.dispose()
362 if (context == null) {
363 throw new SecurityException("Applet classloader has invalid AppContext");
364 }
365
366 return context;
367 }
368 }
369
370 } // class AppletSecurity
|