當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。