Esempio n. 1
0
 public Object execute(PrivilegedExceptionAction<Object> action) throws PrivilegedActionException {
   try {
     return action.run();
   } catch (Exception e) {
     throw new PrivilegedActionException(e);
   }
 }
Esempio n. 2
0
 @Override
 public <T> T runAs(PrivilegedExceptionAction<T> action)
     throws IOException, InterruptedException {
   T result = null;
   try {
     UserGroupInformation previous = (UserGroupInformation) callStatic("getCurrentUGI");
     try {
       if (ugi != null) {
         callStatic(
             "setCurrentUGI", new Class[] {UserGroupInformation.class}, new Object[] {ugi});
       }
       result = action.run();
     } finally {
       callStatic(
           "setCurrentUGI", new Class[] {UserGroupInformation.class}, new Object[] {previous});
     }
   } catch (Exception e) {
     if (e instanceof IOException) {
       throw (IOException) e;
     } else if (e instanceof InterruptedException) {
       throw (InterruptedException) e;
     } else if (e instanceof RuntimeException) {
       throw (RuntimeException) e;
     } else {
       throw new UndeclaredThrowableException(e, "Unknown exception in runAs()");
     }
   }
   return result;
 }
Esempio n. 3
0
 public static <T, E extends Exception> T run(
     PrivilegedExceptionAction<T> action, Class<E> exceptionClass) throws E {
   try {
     return (System.getSecurityManager() != null)
         ? AccessController.doPrivileged(action)
         : action.run();
   } catch (Exception e) {
     throw exceptionClass.cast(e);
   }
 }
Esempio n. 4
0
 public static <T> T run(PrivilegedExceptionAction<T> action) throws Exception {
   return (System.getSecurityManager() != null)
       ? AccessController.doPrivileged(action)
       : action.run();
 }