本文整理汇总了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);
}
}
示例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());
}
}
示例3: execute
import java.security.PrivilegedExceptionAction; //导入方法依赖的package包/类
@Override
public <T> T execute(PrivilegedExceptionAction<T> action)
throws Exception {
return action.run();
}
示例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(); }};
}