code: private static UserGroupInformation createSecurityEnabledProxyUser(String userToProxy,
        String fileLocation, Logger log
    ) throws IOException {
  
      if (!new File(fileLocation).exists()) {
        throw new RuntimeException("hadoop token file doesn't exist.");
      }
  
      log.info("Found token file.  Setting " + HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY
          + " to " + fileLocation);
      System.setProperty(HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY, fileLocation);
  
      UserGroupInformation loginUser = null;
  
      loginUser = UserGroupInformation.getLoginUser();
      log.info("Current logged in user is " + loginUser.getUserName());
  
      UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(userToProxy, loginUser);
  
      for (Token<?> token : loginUser.getTokens()) {
        proxyUser.addToken(token);
      }
      proxyUser.addCredentials(loginUser.getCredentials());
      return proxyUser;
    }
docs: Perform all the magic required to get the proxyUser in a securitized grid
  
  @return a UserGroupInformation object for the specified userToProxy, which will also contain
  the logged in user's tokens