java.security 源码学习06 PrivilegedAction

本文详细解析了Java安全模型中的PrivilegedAction接口,该接口用于定义在特权模式下运行的计算任务,不抛出已检查异常。文章阐述了如何使用AccessController.doPrivileged方法执行此类任务,并对比了PrivilegedExceptionAction的区别。

1. 源码


/**
   A computation to be performed with privileges enabled.  The computation is
   performed by invoking {@code AccessController.doPrivileged} on the
   {@code PrivilegedAction} object.  This interface is used only for
   computations that do not throw checked exceptions; computations that
   throw checked exceptions must use {@code PrivilegedExceptionAction}
   instead.
 启用权限时执行的计算。通过在{@code PrivilegedAction}对象上调用
 {@code AccessController.doPrivileged}来执行计算。
 此接口仅用于不抛出已检查异常的计算;
 抛出已检查异常的计算必须使用{@code PrivilegedExceptionAction}。
 *
 * @see AccessController
 * @see AccessController#doPrivileged(PrivilegedAction)
 * @see PrivilegedExceptionAction
 */

public interface PrivilegedAction<T> {
    /**
       Performs the computation.  This method will be called by
       {@code AccessController.doPrivileged} after enabling privileges.

     执行计算。启用权限后,{@code AccessController.doPrivileged}将调用此方法。

       @return a class-dependent value that may represent the results of the
               computation. Each class that implements
               {@code PrivilegedAction}
               should document what (if anything) this value represents.
       @see AccessController#doPrivileged(PrivilegedAction)
       @see AccessController#doPrivileged(PrivilegedAction,
                                           AccessControlContext)
     */
    T run();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值