private ProxyPrincipal issuedTokenPrincipal(String principal) throws TException {
   return new ProxyPrincipal(
       EzSecurityTokenUtils.serializeProxyUserTokenToJSON(
           new ProxyUserToken(
               new X509Info(dn), "EzSecurity", "", System.currentTimeMillis() + expiry)),
       "");
 }
  public static void main(String[] args) throws Exception {

    TestClient app = new TestClient();
    CmdLineParser cmd = new CmdLineParser(app);
    try {
      cmd.parseArgument(args);
      if (app.help == true) {
        cmd.printUsage(System.out);
        System.exit(1);
      }
      app.run();
    } catch (CmdLineException e) {
      System.err.println(e.getMessage());
      cmd.printUsage(System.err);
    } catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      System.exit(1);
    }
  }
  public void run()
      throws TException, EzSecurityTokenException, UserNotFoundException, IOException,
          AppNotRegisteredException {
    Properties config;
    try {
      config =
          new EzConfiguration(new DirectoryConfigurationLoader(new File(this.config).toPath()))
              .getProperties();
    } catch (EzConfigurationLoaderException e) {
      try {
        config = new EzConfiguration(new ClasspathConfigurationLoader()).getProperties();
      } catch (EzConfigurationLoaderException e1) {
        throw new RuntimeException("Unable to load EzConfiguration");
      }
    }

    if (config.get(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING) == null) {
      config.setProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING, this.zoo);
    }
    if (config.get(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY) == null) {
      config.setProperty(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY, this.sslDir);
    }
    if (config.get(EzBakePropertyConstants.EZBAKE_SECURITY_ID) == null) {
      config.setProperty(EzBakePropertyConstants.EZBAKE_SECURITY_ID, this.appId);
    }

    EzbakeSecurityClient client = new EzbakeSecurityClient(config);

    switch (this.request) {
      case User:
        EzSecurityToken usertoken =
            client.fetchTokenForProxiedUser(issuedTokenPrincipal(dn), this.target);
        if (this.outputFile != null) {
          writeTokenToFile(this.outputFile, usertoken);
        }
        break;
      case App:
        EzSecurityToken appToken = client.fetchAppToken(dn);
        if (this.outputFile != null) {
          writeTokenToFile(this.outputFile, appToken);
        }
        break;
      case DN:
        ProxyTokenRequest req = new ProxyTokenRequest();
        req.setX509(new X509Info(dn));
        req.setValidity(
            new ValidityCaveats("EFE", "EzSecurity", System.currentTimeMillis() + 1000, ""));

        EzSecurity.Client c = client.getClient();
        ProxyTokenResponse principal = c.requestProxyToken(req);
        client.returnClient(c);

        System.out.println(principal.getToken());
        System.out.println(principal.getSignature());
        break;
      case PROXY_DN:
        ProxyTokenRequest proxyReq = new ProxyTokenRequest();
        proxyReq.setX509(new X509Info(dn));
        proxyReq.setValidity(
            new ValidityCaveats("EFE", "EzSecurity", System.currentTimeMillis() + 1000, ""));
        proxyReq.getValidity().setIssuedTime(System.currentTimeMillis());

        EzSecurity.Client pc = client.getClient();
        ProxyTokenResponse presp = pc.requestProxyToken(proxyReq);
        client.returnClient(pc);

        System.out.println(presp.getToken());
        System.out.println(presp.getSignature());
        break;
    }
    Closeables.close(client, true);
  }