当前位置: 首页>>代码示例>>Java>>正文


Java PrivilegedExceptionAction.run方法代码示例

本文整理汇总了Java中java.security.PrivilegedExceptionAction.run方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedExceptionAction.run方法的具体用法?Java PrivilegedExceptionAction.run怎么用?Java PrivilegedExceptionAction.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.PrivilegedExceptionAction的用法示例。


在下文中一共展示了PrivilegedExceptionAction.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runFunction

import java.security.PrivilegedExceptionAction; //导入方法依赖的package包/类
/** Run the guarded business function, only if the current thread has access.
 * This guarded function may throw a PrivilegedActionException which will contain
 * the real exception
 * @return Returns back the object that the guarded code returned
 * @param functionName Name of the business function being guarded
 * @param action An action object which will be executed, this should contain the guarded code
 * @throws PrivilegedActionException This is the wrapped exception the the guarded code threw
 * @throws AccessControlException This is thrown if the user doesn't have authorization for this function
 */
public static Object runFunction(String functionName, PrivilegedExceptionAction action)
throws PrivilegedActionException, AccessControlException {
    
    if(hasAccess(functionName)) {
        try {
            return action.run();
        } catch (Exception e) {
            throw new PrivilegedActionException(e);
        }
    } else {
        // Access Defined
        log.info("Access Denied To Business Function: " + functionName);
        throw new AccessControlException("Business Function:" + functionName);
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:25,代码来源:SecurityManager.java

示例2: shouldThrow

import java.security.PrivilegedExceptionAction; //导入方法依赖的package包/类
private void shouldThrow(PrivilegedExceptionAction<Object> action,
                         Class<? extends Throwable> except) {
  try {
    action.run();
    Assert.fail("action did not throw " + except);
  } catch (Throwable th) {
    LOG.info("Caught an exception: ", th);
    assertEquals("action threw wrong exception", except, th.getClass());
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:11,代码来源:TestDelegationToken.java

示例3: execute

import java.security.PrivilegedExceptionAction; //导入方法依赖的package包/类
@Override
public <T> T execute(PrivilegedExceptionAction<T> action)
        throws Exception {
  return action.run();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:6,代码来源:SimpleAuthenticator.java

示例4: callable

import java.security.PrivilegedExceptionAction; //导入方法依赖的package包/类
/**
 * Returns a {@link Callable} object that, when
 * called, runs the given privileged exception action and returns
 * its result.
 * @param action the privileged exception action to run
 * @return a callable object
 * @throws NullPointerException if action null
 */
public static Callable<Object> callable(final PrivilegedExceptionAction<?> action) {
    if (action == null)
        throw new NullPointerException();
    return new Callable<Object>() {
        public Object call() throws Exception { return action.run(); }};
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Executors.java


注:本文中的java.security.PrivilegedExceptionAction.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。