Repository: incubator-slider Updated Branches: refs/heads/develop 901f38cd3 -> 1282802fd
SLIDER-719 we MAY now have Jersey and SPNEGO hooked up, but tests need to verify this properly Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/c97f7603 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/c97f7603 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/c97f7603 Branch: refs/heads/develop Commit: c97f760310b1eccd8f92268f9fa33ad1925f4aec Parents: 61f4743 Author: Steve Loughran <[email protected]> Authored: Mon Jan 19 14:32:48 2015 +0000 Committer: Steve Loughran <[email protected]> Committed: Tue Jan 20 14:50:23 2015 +0000 ---------------------------------------------------------------------- .../core/restclient/UgiJerseyBinding.java | 21 +++++++++++++++++++- .../restclient/UrlConnectionOperations.java | 14 +++++++++++-- .../slider/agent/rest/RestTestDelegates.groovy | 18 ++++++++--------- .../slider/agent/rest/TestStandaloneREST.groovy | 2 +- .../apache/slider/test/SliderTestUtils.groovy | 1 - .../funtest/lifecycle/AgentWebPagesIT.groovy | 5 ++++- 6 files changed, 46 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java index 6af8e23..6f002ab 100644 --- a/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java +++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java @@ -21,6 +21,7 @@ package org.apache.slider.core.restclient; import com.google.common.base.Preconditions; import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory; import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.authentication.client.AuthenticationException; import java.io.IOException; @@ -33,7 +34,7 @@ import java.net.URL; * Usage: create an instance, then when creating a Jersey <code>Client</code> * pass in to the constructor the handler provided by {@link #getHandler()} * - * @see https://jersey.java.net/apidocs/1.17/jersey/com/sun/jersey/client/urlconnection/HttpURLConnectionFactory.html + * see <a href="https://jersey.java.net/apidocs/1.17/jersey/com/sun/jersey/client/urlconnection/HttpURLConnectionFactory.html">Jersey docs</a> */ public class UgiJerseyBinding implements HttpURLConnectionFactory { @@ -52,6 +53,15 @@ public class UgiJerseyBinding implements } /** + * Create an instance off the configuration. The SPNEGO policy + * is derived from the current UGI settings. + * @param conf config + */ + public UgiJerseyBinding(Configuration conf) { + this(new UrlConnectionOperations(conf)); + } + + /** * Get a URL connection. * @param url * @return the connection @@ -74,6 +84,15 @@ public class UgiJerseyBinding implements public URLConnectionClientHandler getHandler() { return handler; } + + /** + * Get the SPNEGO flag (as found in the operations instance + * @return the spnego policy + */ + public boolean isUseSpnego() { + return operations.isUseSpnego(); + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java index c51914a..65a4117 100644 --- a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java +++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java @@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.hdfs.web.URLConnectionFactory; import org.apache.hadoop.net.NetUtils; +import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.client.AuthenticationException; import org.apache.hadoop.yarn.webapp.ForbiddenException; import org.apache.hadoop.yarn.webapp.NotFoundException; @@ -48,10 +49,19 @@ public class UrlConnectionOperations extends Configured { private boolean useSpnego = false; + /** + * Create an instance off the configuration. The SPNEGO policy + * is derived from the current UGI settings. + * @param conf config + */ public UrlConnectionOperations(Configuration conf) { super(conf); connectionFactory = URLConnectionFactory .newDefaultURLConnectionFactory(conf); + if (UserGroupInformation.isSecurityEnabled()) { + log.debug("SPNEGO is enabled"); + setUseSpnego(true); + } } @@ -66,10 +76,10 @@ public class UrlConnectionOperations extends Configured { /** * Opens a url with read and connect timeouts * - * @param url - * to open + * @param url to open * @return URLConnection * @throws IOException + * @throws AuthenticationException authentication failure */ public HttpURLConnection openConnection(URL url) throws IOException, http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy index 0826204..bf009c2 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy @@ -97,15 +97,6 @@ class RestTestDelegates extends SliderTestUtils { assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING) } - - public void testRestletOperations() throws Throwable { - Client client = createJerseyClient() - String path = appendToURL(application, LIVE_RESOURCES) - WebResource webResource = client.resource(path) - webResource.type(MediaType.APPLICATION_JSON) - .get(ConfTree.class); - } - public void testLiveContainers() throws Throwable { describe "Application REST ${LIVE_CONTAINERS}" @@ -202,6 +193,15 @@ class RestTestDelegates extends SliderTestUtils { TEST_GLOBAL_OPTION_PRESENT } + + public void testRestletGetOperations() throws Throwable { + Client client = createJerseyClient() + String path = appendToURL(application, LIVE_RESOURCES) + WebResource webResource = client.resource(path) + webResource.type(MediaType.APPLICATION_JSON) + .get(ConfTree.class); + } + public void testPing() { // GET String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING) http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy index 22bc4ae..fd676df 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy @@ -90,7 +90,7 @@ class TestStandaloneREST extends AgentMiniClusterTestBase { RestTestDelegates proxied = new RestTestDelegates(appmaster) RestTestDelegates direct = new RestTestDelegates(realappmaster) - direct.testRestletOperations(); + direct.testRestletGetOperations(); proxied.testCodahaleOperations() direct.testCodahaleOperations() http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy index 9dd2828..df62057 100644 --- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy @@ -605,7 +605,6 @@ class SliderTestUtils extends Assert { public static synchronized void initHttpTestSupport(Configuration conf) { connectionOperations = new UrlConnectionOperations(conf); jerseyBinding = new UgiJerseyBinding(connectionOperations) - } /** http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy ---------------------------------------------------------------------- diff --git a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy index de8dcdf..95352d0 100644 --- a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy +++ b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy @@ -108,6 +108,9 @@ public class AgentWebPagesIT extends AgentCommandTestBase proxied.testRESTModel() + direct.testRestletGetOperations() + proxied.testRestletGetOperations() + // PUT & POST &c direct direct.testPing() if (!wsBackDoorRequired) { @@ -116,7 +119,7 @@ public class AgentWebPagesIT extends AgentCommandTestBase } direct.logCodahaleMetrics(); - + // finally, stop the AM direct.testStop(); }
