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