/** * Calls {@code action.run()}. */ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException { try { return action.run(); } catch (RuntimeException e) { throw e; // so we don't wrap RuntimeExceptions with PrivilegedActionException } catch (Exception e) { throw new PrivilegedActionException(e); } }
/** * Run an action under this identity. * * @param action the task to run (must not be {@code null}) * @param <R> the return value type * @return the action return value * @throws PrivilegedActionException if the action fails with an exception */ default <R> R runAsExceptionAction(PrivilegedExceptionAction<R> action) throws PrivilegedActionException { if (action == null) return null; try { return runAsFunctionEx(PrivilegedExceptionAction::run, action); } catch (Exception e) { throw new PrivilegedActionException(e); } }
/** * Run a privileged action with this authentication context associated for the duration of the task. * * @param parameter the parameter to pass to the action * @param action the action to run under association * @param <T> the action return type * @param <P> the action parameter type * @return the action return value * @throws PrivilegedActionException if the action throws an exception */ public <T, P> T run(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionException { try { return runExFunction(action, parameter); } catch (Exception e) { throw new PrivilegedActionException(e); } }
@Override public final PrivilegedActionException privilegedActionFailed(final Exception e) { final PrivilegedActionException result = new PrivilegedActionException(e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String readOnlyPermissionCollection = "COM00300: Permission collection is read-only";
/** * Perform an action with permission checking enabled. If permission checking is already enabled, the action is * simply run. * * @param action the action to perform * @param context the access control context to use * @param <T> the action return type * @return the return value of the action * @throws PrivilegedActionException if the action threw an exception */ public static <T> T doChecked(PrivilegedExceptionAction<T> action, AccessControlContext context) throws PrivilegedActionException { final Context ctx = CTX.get(); if (ctx.checking) { try { return action.run(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } } ctx.checking = true; try { return AccessController.doPrivileged(action, context); } finally { ctx.checking = false; } }
throw e; } catch (Exception e) { throw new PrivilegedActionException(e); throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { ctx.checking = false;
throw e; } catch (Exception e) { throw new PrivilegedActionException(e); throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { ctx.checking = false;
return action.run(); } catch (Exception e) { throw new PrivilegedActionException(e); throw new PrivilegedActionException(e); } finally { ctx.checking = true;
/** * Perform an action with permission checking enabled. If permission checking is already enabled, the action is * simply run. * * @param parameter the parameter to pass to the action * @param action the action to perform * @param context the access control context to use * @param <T> the action return type * @param <P> the action parameter type * @return the return value of the action * @throws PrivilegedActionException if the action threw an exception */ public static <T, P> T doChecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext context) throws PrivilegedActionException { final Context ctx = CTX.get(); if (ctx.checking) { try { return action.run(parameter); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } } ctx.checking = true; try { return doPrivilegedWithParameter(parameter, action, context); } finally { ctx.checking = false; } }
return action.run(parameter); } catch (Exception e) { throw new PrivilegedActionException(e); throw new PrivilegedActionException(e); } finally { ctx.checking = true;
throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { for (int i = 0; i < length; i++) {
/** * Run an action under this identity. * * @param parameter the parameter to pass to the action * @param action the action to run * @param <T> the action return type * @param <P> the action parameter type * @return the action result (may be {@code null}) * @throws PrivilegedActionException if the action fails * @deprecated Use {@link #runAsFunctionEx(ExceptionFunction, Object)} instead. */ @Deprecated public <T, P> T runAs(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionException { if (action == null) return null; final Supplier<SecurityIdentity>[] oldWithIdentities = establishIdentities(); final Supplier<SecurityIdentity> oldIdentity = securityDomain.getAndSetCurrentSecurityIdentity(this); try { return action.run(parameter); } catch (RuntimeException | PrivilegedActionException e) { throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { securityDomain.setCurrentSecurityIdentity(oldIdentity); restoreIdentities(oldWithIdentities); } }
throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { for (int i = length - 1; i >= 0; i--) {
throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { for (int i = length - 1; i >= 0; i--) {
/** * Run an action under this identity. * * @param action the action to run * @param <T> the action return type * @return the action result (may be {@code null}) * @throws PrivilegedActionException if the action fails */ public <T> T runAs(PrivilegedExceptionAction<T> action) throws PrivilegedActionException { PeerIdentity old = context.getAndSetPeerIdentity(this); try { preAssociate(); try { return action.run(); } finally { safePostAssociate(); } } catch (RuntimeException | PrivilegedActionException e) { throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { context.setPeerIdentity(old); } }
/** * Run an action under this identity. * * @param parameter the parameter to pass to the action * @param action the action to run * @param <T> the action return type * @param <P> the action parameter type * @return the action result (may be {@code null}) * @throws PrivilegedActionException if the action fails */ public <T, P> T runAs(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionException { PeerIdentity old = context.getAndSetPeerIdentity(this); try { preAssociate(); try { return action.run(parameter); } finally { safePostAssociate(); } } catch (RuntimeException | PrivilegedActionException e) { throw e; } catch (Exception e) { throw new PrivilegedActionException(e); } finally { context.setPeerIdentity(old); } }
public Class<?> run() throws PrivilegedActionException { try { return cl.loadClass(name); } catch (Exception e) { throw new PrivilegedActionException(e); } } });
/** * Calls {@code action.run()}. */ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException { try { return action.run(); } catch (RuntimeException e) { throw e; // so we don't wrap RuntimeExceptions with PrivilegedActionException } catch (Exception e) { throw new PrivilegedActionException(e); } }
public Class<?> run() throws PrivilegedActionException { try { return getContextClassLoader().loadClass(name); } catch ( Exception e) { throw new PrivilegedActionException(e); } } });
/** * Calls {@code action.run()}. */ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException { try { return action.run(); } catch (RuntimeException e) { throw e; // so we don't wrap RuntimeExceptions with PrivilegedActionException } catch (Exception e) { throw new PrivilegedActionException(e); } }