java.security.PrivilegedAction#run ( )源码实例Demo

下面列出了java.security.PrivilegedAction#run ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: SecurityUtil.java
/**
 * 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 项目: lams   文件: HibernateMethodLookupDispatcher.java
private static Method doPrivilegedAction(PrivilegedAction<Method> privilegedAction) {
	Class<?> callerClass = getCallerClass();

	if ( !authorizedClasses.contains( callerClass.getName() ) ) {
		throw new SecurityException( "Unauthorized call by class " + callerClass );
	}

	return System.getSecurityManager() != null ? AccessController.doPrivileged( privilegedAction ) :
		privilegedAction.run();
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码5 项目: TencentKona-8   文件: RMIConnectionImpl.java
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 项目: Bytecoder   文件: TAccessController.java
public static <T> T doPrivileged(final PrivilegedAction<T> action, final AccessControlContext context) {
    return action.run();
}
 
源代码7 项目: openjdk-jdk9   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码8 项目: jdk8u-jdk   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码9 项目: JDKSourceCode1.8   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码10 项目: quarkus   文件: DelegatingLdapContext.java
private static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return System.getSecurityManager() != null ? AccessController.doPrivileged(action) : action.run();
}
 
源代码11 项目: quarkus   文件: QuarkusDirContextFactory.java
private static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return System.getSecurityManager() != null ? AccessController.doPrivileged(action) : action.run();
}
 
源代码12 项目: openjdk-jdk8u   文件: RMIConnectionImpl.java
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();
    }
}
 
源代码13 项目: Bytecoder   文件: TAccessController.java
public static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return action.run();
}
 
源代码14 项目: jdk1.8-source-analysis   文件: Executors.java
/**
 * 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(); }};
}
 
源代码15 项目: dragonwell8_jdk   文件: Executors.java
/**
 * 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(); }};
}
 
源代码16 项目: TencentKona-8   文件: Executors.java
/**
 * 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(); }};
}
 
源代码17 项目: Bytecoder   文件: Executors.java
/**
 * 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(); }};
}
 
源代码18 项目: jdk8u-jdk   文件: Executors.java
/**
 * 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(); }};
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: Executors.java
/**
 * 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(); }};
}
 
/**
 * Runs the given privileged action, using a privileged block if required.
 * <p>
 * <b>NOTE:</b> This must never be changed into a publicly available method to avoid execution of arbitrary
 * privileged actions within HV's protection domain.
 */
private <T> T run(PrivilegedAction<T> action) {
    return System.getSecurityManager() != null ? AccessController.doPrivileged(action) : action.run();
}
 
 同类方法