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

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

Introduction

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

Prototype

public URLConnection openConnection(URL url, boolean isSpnego) throws IOException, AuthenticationException 

Source Link

Document

Opens a url with read and connect timeouts

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();/*from  w  w w. j a v a 2s  .  c o  m*/
    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 a v  a2s  .  c o  m
    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");
        }

    }

}