src/share/classes/java/lang/SecurityManager.java

Print this page




1324      * If you override this method, then you should make a call to
1325      * <code>super.checkTopLevelWindow</code>
1326      * at the point the overridden method would normally return
1327      * <code>false</code>, and the value of
1328      * <code>super.checkTopLevelWindow</code> should
1329      * be returned.
1330      *
1331      * @param      window   the new window that is being created.
1332      * @return     <code>true</code> if the calling thread is trusted to put up
1333      *             top-level windows; <code>false</code> otherwise.
1334      * @exception  NullPointerException if the <code>window</code> argument is
1335      *             <code>null</code>.
1336      * @see        java.awt.Window
1337      * @see        #checkPermission(java.security.Permission) checkPermission
1338      */
1339     public boolean checkTopLevelWindow(Object window) {
1340         if (window == null) {
1341             throw new NullPointerException("window can't be null");
1342         }
1343         try {
1344             checkPermission(SecurityConstants.TOPLEVEL_WINDOW_PERMISSION);
1345             return true;
1346         } catch (SecurityException se) {
1347             // just return false
1348         }
1349         return false;
1350     }
1351 
1352     /**
1353      * Throws a <code>SecurityException</code> if the
1354      * calling thread is not allowed to initiate a print job request.
1355      * <p>
1356      * This method calls
1357      * <code>checkPermission</code> with the
1358      * <code>RuntimePermission("queuePrintJob")</code> permission.
1359      * <p>
1360      * If you override this method, then you should make a call to
1361      * <code>super.checkPrintJobAccess</code>
1362      * at the point the overridden method would normally throw an
1363      * exception.
1364      * <p>


1374 
1375     /**
1376      * Throws a <code>SecurityException</code> if the
1377      * calling thread is not allowed to access the system clipboard.
1378      * <p>
1379      * This method calls <code>checkPermission</code> with the
1380      * <code>AWTPermission("accessClipboard")</code>
1381      * permission.
1382      * <p>
1383      * If you override this method, then you should make a call to
1384      * <code>super.checkSystemClipboardAccess</code>
1385      * at the point the overridden method would normally throw an
1386      * exception.
1387      *
1388      * @since   JDK1.1
1389      * @exception  SecurityException  if the calling thread does not have
1390      *             permission to access the system clipboard.
1391      * @see        #checkPermission(java.security.Permission) checkPermission
1392      */
1393     public void checkSystemClipboardAccess() {
1394         checkPermission(SecurityConstants.ACCESS_CLIPBOARD_PERMISSION);
1395     }
1396 
1397     /**
1398      * Throws a <code>SecurityException</code> if the
1399      * calling thread is not allowed to access the AWT event queue.
1400      * <p>
1401      * This method calls <code>checkPermission</code> with the
1402      * <code>AWTPermission("accessEventQueue")</code> permission.
1403      * <p>
1404      * If you override this method, then you should make a call to
1405      * <code>super.checkAwtEventQueueAccess</code>
1406      * at the point the overridden method would normally throw an
1407      * exception.
1408      *
1409      * @since   JDK1.1
1410      * @exception  SecurityException  if the calling thread does not have
1411      *             permission to access the AWT event queue.
1412      * @see        #checkPermission(java.security.Permission) checkPermission
1413      */
1414     public void checkAwtEventQueueAccess() {
1415         checkPermission(SecurityConstants.CHECK_AWT_EVENTQUEUE_PERMISSION);
1416     }
1417 
1418     /*
1419      * We have an initial invalid bit (initially false) for the class
1420      * variables which tell if the cache is valid.  If the underlying
1421      * java.security.Security property changes via setProperty(), the
1422      * Security class uses reflection to change the variable and thus
1423      * invalidate the cache.
1424      *
1425      * Locking is handled by synchronization to the
1426      * packageAccessLock/packageDefinitionLock objects.  They are only
1427      * used in this class.
1428      *
1429      * Note that cache invalidation as a result of the property change
1430      * happens without using these locks, so there may be a delay between
1431      * when a thread updates the property and when other threads updates
1432      * the cache.
1433      */
1434     private static boolean packageAccessValid = false;
1435     private static String[] packageAccess;




1324      * If you override this method, then you should make a call to
1325      * <code>super.checkTopLevelWindow</code>
1326      * at the point the overridden method would normally return
1327      * <code>false</code>, and the value of
1328      * <code>super.checkTopLevelWindow</code> should
1329      * be returned.
1330      *
1331      * @param      window   the new window that is being created.
1332      * @return     <code>true</code> if the calling thread is trusted to put up
1333      *             top-level windows; <code>false</code> otherwise.
1334      * @exception  NullPointerException if the <code>window</code> argument is
1335      *             <code>null</code>.
1336      * @see        java.awt.Window
1337      * @see        #checkPermission(java.security.Permission) checkPermission
1338      */
1339     public boolean checkTopLevelWindow(Object window) {
1340         if (window == null) {
1341             throw new NullPointerException("window can't be null");
1342         }
1343         try {
1344             checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION);
1345             return true;
1346         } catch (SecurityException se) {
1347             // just return false
1348         }
1349         return false;
1350     }
1351 
1352     /**
1353      * Throws a <code>SecurityException</code> if the
1354      * calling thread is not allowed to initiate a print job request.
1355      * <p>
1356      * This method calls
1357      * <code>checkPermission</code> with the
1358      * <code>RuntimePermission("queuePrintJob")</code> permission.
1359      * <p>
1360      * If you override this method, then you should make a call to
1361      * <code>super.checkPrintJobAccess</code>
1362      * at the point the overridden method would normally throw an
1363      * exception.
1364      * <p>


1374 
1375     /**
1376      * Throws a <code>SecurityException</code> if the
1377      * calling thread is not allowed to access the system clipboard.
1378      * <p>
1379      * This method calls <code>checkPermission</code> with the
1380      * <code>AWTPermission("accessClipboard")</code>
1381      * permission.
1382      * <p>
1383      * If you override this method, then you should make a call to
1384      * <code>super.checkSystemClipboardAccess</code>
1385      * at the point the overridden method would normally throw an
1386      * exception.
1387      *
1388      * @since   JDK1.1
1389      * @exception  SecurityException  if the calling thread does not have
1390      *             permission to access the system clipboard.
1391      * @see        #checkPermission(java.security.Permission) checkPermission
1392      */
1393     public void checkSystemClipboardAccess() {
1394         checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
1395     }
1396 
1397     /**
1398      * Throws a <code>SecurityException</code> if the
1399      * calling thread is not allowed to access the AWT event queue.
1400      * <p>
1401      * This method calls <code>checkPermission</code> with the
1402      * <code>AWTPermission("accessEventQueue")</code> permission.
1403      * <p>
1404      * If you override this method, then you should make a call to
1405      * <code>super.checkAwtEventQueueAccess</code>
1406      * at the point the overridden method would normally throw an
1407      * exception.
1408      *
1409      * @since   JDK1.1
1410      * @exception  SecurityException  if the calling thread does not have
1411      *             permission to access the AWT event queue.
1412      * @see        #checkPermission(java.security.Permission) checkPermission
1413      */
1414     public void checkAwtEventQueueAccess() {
1415         checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
1416     }
1417 
1418     /*
1419      * We have an initial invalid bit (initially false) for the class
1420      * variables which tell if the cache is valid.  If the underlying
1421      * java.security.Security property changes via setProperty(), the
1422      * Security class uses reflection to change the variable and thus
1423      * invalidate the cache.
1424      *
1425      * Locking is handled by synchronization to the
1426      * packageAccessLock/packageDefinitionLock objects.  They are only
1427      * used in this class.
1428      *
1429      * Note that cache invalidation as a result of the property change
1430      * happens without using these locks, so there may be a delay between
1431      * when a thread updates the property and when other threads updates
1432      * the cache.
1433      */
1434     private static boolean packageAccessValid = false;
1435     private static String[] packageAccess;