Java Code Examples for java.security.PrivilegedAction#run()

The following examples show how to use java.security.PrivilegedAction#run() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   File: SecurityUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example 2
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();
}
 
Example 3
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();
    }
}
 
Example 4
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();
    }
}
 
Example 5
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();
    }
}
 
Example 6
Source Project: Bytecoder   File: TAccessController.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T doPrivileged(final PrivilegedAction<T> action, final AccessControlContext context) {
    return action.run();
}
 
Example 7
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();
    }
}
 
Example 8
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();
    }
}
 
Example 9
Source Project: JDKSourceCode1.8   File: RMIConnectionImpl.java    License: MIT License 4 votes vote down vote up
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();
    }
}
 
Example 10
Source Project: quarkus   File: DelegatingLdapContext.java    License: Apache License 2.0 4 votes vote down vote up
private static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return System.getSecurityManager() != null ? AccessController.doPrivileged(action) : action.run();
}
 
Example 11
private static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return System.getSecurityManager() != null ? AccessController.doPrivileged(action) : action.run();
}
 
Example 12
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();
    }
}
 
Example 13
Source Project: Bytecoder   File: TAccessController.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T doPrivileged(final PrivilegedAction<T> action) {
    return action.run();
}
 
Example 14
/**
 * 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(); }};
}
 
Example 15
/**
 * 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(); }};
}
 
Example 16
/**
 * 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(); }};
}
 
Example 17
Source Project: Bytecoder   File: Executors.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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(); }};
}
 
Example 18
/**
 * 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(); }};
}
 
Example 19
/**
 * 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(); }};
}
 
Example 20
/**
 * 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();
}