本文整理汇总了Java中java.security.PrivilegedAction.run方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedAction.run方法的具体用法?Java PrivilegedAction.run怎么用?Java PrivilegedAction.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.PrivilegedAction
的用法示例。
在下文中一共展示了PrivilegedAction.run方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAsLoginUserOrFatal
import java.security.PrivilegedAction; //导入方法依赖的package包/类
/**
* Perform the given action as the daemon's login user. If the login
* user cannot be determined, this will log a FATAL error and exit
* the whole JVM.
*/
public static <T> T doAsLoginUserOrFatal(PrivilegedAction<T> action) {
if (UserGroupInformation.isSecurityEnabled()) {
UserGroupInformation ugi = null;
try {
ugi = UserGroupInformation.getLoginUser();
} catch (IOException e) {
LOG.fatal("Exception while getting login user", e);
e.printStackTrace();
Runtime.getRuntime().exit(-1);
}
return ugi.doAs(action);
} else {
return action.run();
}
}
示例2: fetchNotifications
import java.security.PrivilegedAction; //导入方法依赖的package包/类
public NotificationResult fetchNotifications(long clientSequenceNumber,
int maxNotifications,
long timeout)
throws IOException {
if (logger.debugOn()) logger.debug("fetchNotifications",
"connectionId=" + connectionId
+", timeout=" + timeout);
if (maxNotifications < 0 || timeout < 0)
throw new IllegalArgumentException("Illegal negative argument");
final boolean serverTerminated =
serverCommunicatorAdmin.reqIncoming();
try {
if (serverTerminated) {
// we must not call fetchNotifs() if the server is
// terminated (timeout elapsed).
//
return new NotificationResult(0L, 0L,
new TargetedNotification[0]);
}
final long csn = clientSequenceNumber;
final int mn = maxNotifications;
final long t = timeout;
PrivilegedAction<NotificationResult> action =
new PrivilegedAction<NotificationResult>() {
public NotificationResult run() {
return getServerNotifFwd().fetchNotifs(csn, t, mn);
}
};
if (acc == null)
return action.run();
else
return AccessController.doPrivileged(action, acc);
} finally {
serverCommunicatorAdmin.rspOutgoing();
}
}
示例3: runFunction
import java.security.PrivilegedAction; //导入方法依赖的package包/类
/** Run the guarded business function, only if the current thread has access
* @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 AccessControlException This is thrown if the user doesn't have authorization for this function
* @return Returns back the object that the guarded code returned
*/
public static Object runFunction(String functionName, PrivilegedAction action)
throws AccessControlException {
if(hasAccess(functionName))
return action.run();
else {
// Access Defined
log.info("Access Denied To Business Function: " + functionName);
throw new AccessControlException("Business Function:" + functionName);
}
}
示例4: execute
import java.security.PrivilegedAction; //导入方法依赖的package包/类
@Override
public <T> T execute(PrivilegedAction<T> action) {
return action.run();
}
示例5: fetchNotifications
import java.security.PrivilegedAction; //导入方法依赖的package包/类
public NotificationResult fetchNotifications(long clientSequenceNumber,
int maxNotifications,
long timeout)
throws IOException {
if (logger.debugOn()) logger.debug("fetchNotifications",
"connectionId=" + connectionId
+", timeout=" + timeout);
if (maxNotifications < 0 || timeout < 0)
throw new IllegalArgumentException("Illegal negative argument");
final boolean serverTerminated =
serverCommunicatorAdmin.reqIncoming();
try {
if (serverTerminated) {
// we must not call fetchNotifs() if the server is
// terminated (timeout elapsed).
// returns null to force the client to stop fetching
if (logger.debugOn()) logger.debug("fetchNotifications",
"The notification server has been closed, "
+ "returns null to force the client to stop fetching");
return null;
}
final long csn = clientSequenceNumber;
final int mn = maxNotifications;
final long t = timeout;
PrivilegedAction<NotificationResult> action =
new PrivilegedAction<NotificationResult>() {
public NotificationResult run() {
return getServerNotifFwd().fetchNotifs(csn, t, mn);
}
};
if (acc == null)
return action.run();
else
return AccessController.doPrivileged(action, acc);
} finally {
serverCommunicatorAdmin.rspOutgoing();
}
}
示例6: callable
import java.security.PrivilegedAction; //导入方法依赖的package包/类
/**
* Returns a {@link Callable} object that, when
* called, runs the given privileged action and returns its result.
* @param action the privileged action to run
* @return a callable object
* @throws NullPointerException if action null
*/
public static Callable<Object> callable(final PrivilegedAction<?> action) {
if (action == null)
throw new NullPointerException();
return new Callable<Object>() {
public Object call() { return action.run(); }};
}