Example usage for org.apache.hadoop.hdfs.web URLConnectionFactory DEFAULT_SYSTEM_CONNECTION_FACTORY

List of usage examples for org.apache.hadoop.hdfs.web URLConnectionFactory DEFAULT_SYSTEM_CONNECTION_FACTORY

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.web URLConnectionFactory DEFAULT_SYSTEM_CONNECTION_FACTORY.

Prototype

URLConnectionFactory DEFAULT_SYSTEM_CONNECTION_FACTORY

To view the source code for org.apache.hadoop.hdfs.web URLConnectionFactory DEFAULT_SYSTEM_CONNECTION_FACTORY.

Click Source Link

Document

The URLConnectionFactory that sets the default timeout and it only trusts Java's SSL certificates.

Usage

From source file:org.apache.atlas.web.filters.AtlasAuthenticationKerberosFilterTest.java

License:Apache License

@Test(enabled = false)
public void testKerberosBasedLogin() throws Exception {
    String originalConf = System.getProperty("atlas.conf");

    setupKDCAndPrincipals();// w w w . java  2  s . c om
    TestEmbeddedServer server = null;

    try {
        // setup the atlas-application.properties file
        String confDirectory = generateKerberosTestProperties();
        System.setProperty("atlas.conf", confDirectory);

        // need to create the web application programmatically in order to control the injection of the test
        // application properties
        server = new TestEmbeddedServer(23000, "webapp/target/apache-atlas");

        startEmbeddedServer(server.getServer());

        final URLConnectionFactory connectionFactory = URLConnectionFactory.DEFAULT_SYSTEM_CONNECTION_FACTORY;
        // attempt to hit server and get rejected
        URL url = new URL("http://localhost:23000/");
        HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, false);
        connection.setRequestMethod("GET");
        connection.connect();

        assertEquals(connection.getResponseCode(), 401);

        // need to populate the ticket cache with a local user, so logging in...
        Subject subject = loginTestUser();

        Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws Exception {
                // attempt to hit server and get rejected
                URL url = new URL("http://localhost:23000/");
                HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, true);
                connection.setRequestMethod("GET");
                connection.connect();

                assertEquals(connection.getResponseCode(), 200);
                assertEquals(RequestContext.get().getUser(), TESTUSER);
                return null;
            }
        });
    } finally {
        server.getServer().stop();
        kdc.stop();

        if (originalConf != null) {
            System.setProperty("atlas.conf", originalConf);
        } else {
            System.clearProperty("atlas.conf");
        }

    }
}

From source file:org.apache.atlas.web.filters.MetadataAuthenticationKerberosFilterIT.java

License:Apache License

@Test(enabled = false)
public void testKerberosBasedLogin() throws Exception {
    String originalConf = System.getProperty("metadata.conf");
    System.setProperty("metadata.conf", System.getProperty("user.dir"));

    setupKDCAndPrincipals();/*from   w  w w  .  j  ava  2  s  .  c  om*/
    TestEmbeddedServer server = null;

    try {
        // setup the application.properties file
        generateKerberosTestProperties();

        // need to create the web application programmatically in order to control the injection of the test
        // application properties
        server = new TestEmbeddedServer(23000, "webapp/target/apache-atlas");

        startEmbeddedServer(server.getServer());

        final URLConnectionFactory connectionFactory = URLConnectionFactory.DEFAULT_SYSTEM_CONNECTION_FACTORY;
        // attempt to hit server and get rejected
        URL url = new URL("http://localhost:23000/");
        HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, false);
        connection.setRequestMethod("GET");
        connection.connect();

        Assert.assertEquals(connection.getResponseCode(), 401);

        // need to populate the ticket cache with a local user, so logging in...
        Subject subject = loginTestUser();

        Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws Exception {
                // attempt to hit server and get rejected
                URL url = new URL("http://localhost:23000/");
                HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, true);
                connection.setRequestMethod("GET");
                connection.connect();

                Assert.assertEquals(connection.getResponseCode(), 200);

                return null;
            }
        });
    } finally {
        server.getServer().stop();
        kdc.stop();

        if (originalConf != null) {
            System.setProperty("metadata.conf", originalConf);
        } else {
            System.clearProperty("metadata.conf");
        }

    }

}