code: public static synchronized UserGroupInformation getProxiedUser(
        final String toProxy, final Properties prop, final Logger log, final Configuration conf)
        throws IOException {
  
      if (conf == null) {
        throw new IllegalArgumentException("conf can't be null");
      }
      UserGroupInformation.setConfiguration(conf);
  
      if (toProxy == null) {
        throw new IllegalArgumentException("toProxy can't be null");
      }
  
      if (loginUser == null) {
        log.info("No login user. Creating login user");
        final String keytab = verifySecureProperty(prop, PROXY_KEYTAB_LOCATION, log);
        final String proxyUser = verifySecureProperty(prop, PROXY_USER, log);
        UserGroupInformation.loginUserFromKeytab(proxyUser, keytab);
        loginUser = UserGroupInformation.getLoginUser();
        log.info("Logged in with user " + loginUser);
      } else {
        log.info("loginUser (" + loginUser + ") already created, refreshing tgt.");
        loginUser.checkTGTAndReloginFromKeytab();
      }
  
      return UserGroupInformation.createProxyUser(toProxy, loginUser);
    }
docs: Create a proxied user based on the explicit user name, taking other parameters necessary from
  properties file.