@AfterClass
  public void tearDown() throws Exception {
    if (secureEmbeddedServer != null) {
      secureEmbeddedServer.getServer().stop();
    }

    if (kdc != null) {
      kdc.stop();
    }

    if (originalConf != null) {
      System.setProperty("atlas.conf", originalConf);
    }
  }
  @BeforeClass
  public void setUp() throws Exception {
    jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
    providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();

    String persistDir = TestUtils.getTempDirectory();

    setupKDCAndPrincipals();
    setupCredentials();

    // client will actually only leverage subset of these properties
    final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl);

    persistSSLClientConfiguration(configuration);

    TestUtils.writeConfiguration(
        configuration, persistDir + File.separator + ApplicationProperties.APPLICATION_PROPERTIES);

    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
      url =
          NegativeSSLAndKerberosTest.class.getResource(
              "/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
      url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    configuration.load(url);

    configuration.setProperty(TLS_ENABLED, true);
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.keytab", userKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.principal", "dgi/localhost@" + kdc.getRealm());

    configuration.setProperty("atlas.authentication.method.file", "false");
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty(
        "atlas.authentication.method.kerberos.principal", "HTTP/localhost@" + kdc.getRealm());
    configuration.setProperty(
        "atlas.authentication.method.kerberos.keytab", httpKeytabFile.getAbsolutePath());
    configuration.setProperty(
        "atlas.authentication.method.kerberos.name.rules",
        "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT");

    configuration.setProperty("atlas.authentication.method.file", "true");
    configuration.setProperty(
        "atlas.authentication.method.file.filename", persistDir + "/users-credentials");
    configuration.setProperty("atlas.auth.policy.file", persistDir + "/policy-store.txt");

    TestUtils.writeConfiguration(
        configuration, persistDir + File.separator + ApplicationProperties.APPLICATION_PROPERTIES);

    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);

    // save original setting
    originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);

    dgiClient = new AtlasClient(configuration, DGI_URL);

    secureEmbeddedServer =
        new TestSecureEmbeddedServer(21443, getWarPath()) {
          @Override
          public Configuration getConfiguration() {
            return configuration;
          }
        };
    secureEmbeddedServer.getServer().start();
  }