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


Java PrivilegedAction.run方法代码示例

本文整理汇总了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();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:SecurityUtil.java

示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:RMIConnectionImpl.java

示例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);
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:18,代码来源:SecurityManager.java

示例4: execute

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

示例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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:RMIConnectionImpl.java

示例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(); }};
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:Executors.java


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