@Override
  public Object invoke(Object arg0, final Method method, final Object[] args)
      throws Throwable {
    try {
      if (method.getDeclaringClass() == HiveSessionBase.class) {
        return invoke(method, args);
      }
      return ugi.doAs(
        new PrivilegedExceptionAction<Object> () {
          @Override
          public Object run() throws HiveSQLException {
            return invoke(method, args);
          }
        });
    } catch (UndeclaredThrowableException e) {
      Throwable innerException = e.getCause();
      if (innerException instanceof PrivilegedActionException) {
        throw innerException.getCause();
      } else {
        throw e.getCause();
      }
    }
  }
Proxy wrapper on HiveSession to execute operations
by impersonating given user
service/src/java/org/apache/hive/service/cli/session/HiveSessionProxy.java