When should AccessController.doPrivileged() be used?

前端 未结 4 1843
囚心锁ツ
囚心锁ツ 2020-12-13 09:35

If I understand AccessController.doPrivileged correctly, it is saying that untrusted code should be able to invoke methods requiring permissions (such as System.getPro

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 09:51

    Check out these links and scroll down to using the doPrivileged API.

    Java 6: http://docs.oracle.com/javase/6/docs/technotes/guides/security/doprivileged.html

    Java 7: http://docs.oracle.com/javase/7/docs/technotes/guides/security/doprivileged.html

    When the AccessController checkPermission method is invoked by the most recent caller, the basic algorithm for deciding whether to allow or deny the requested access is as follows:

    If the code for any caller in the call chain does not have the requested permission, AccessControlException is thrown, unless the following is true - a caller whose code is granted the said permission has been marked as "privileged" (see below) and all parties subsequently called by this caller (directly or indirectly) all have the said permission

提交回复
热议问题