You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2015/11/25 17:22:41 UTC
knox git commit: KNOX-632 added back configuration for
'replayBufferSize'
Repository: knox
Updated Branches:
refs/heads/master e7736bd80 -> d3582aeb7
KNOX-632 added back configuration for 'replayBufferSize'
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/d3582aeb
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/d3582aeb
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/d3582aeb
Branch: refs/heads/master
Commit: d3582aeb7e34288fa0a54c6cfbf5286cbb7b6b95
Parents: e7736bd
Author: Sumit Gupta <su...@apache.org>
Authored: Wed Nov 25 11:21:46 2015 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Wed Nov 25 11:21:46 2015 -0500
----------------------------------------------------------------------
.../gateway/dispatch/DefaultDispatch.java | 27 +++++++-
.../gateway/dispatch/DefaultDispatchTest.java | 71 ++++++++++++++++++--
2 files changed, 90 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/d3582aeb/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
index e17bd36..9555ffa 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/dispatch/DefaultDispatch.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
import org.apache.hadoop.gateway.audit.api.Auditor;
import org.apache.hadoop.gateway.audit.api.ResourceType;
import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
+import org.apache.hadoop.gateway.config.Configure;
import org.apache.hadoop.gateway.config.GatewayConfig;
import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
@@ -64,6 +65,8 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
private Set<String> outboundResponseExcludeHeaders;
+ private int replayBufferSize = -1;
+
@Override
public void init() {
outboundResponseExcludeHeaders = new HashSet<>();
@@ -76,6 +79,15 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
}
+ protected int getReplayBufferSize() {
+ return replayBufferSize;
+ }
+
+ @Configure
+ protected void setReplayBufferSize(int size) {
+ replayBufferSize = size;
+ }
+
protected void executeRequest(
HttpUriRequest outboundRequest,
HttpServletRequest inboundRequest,
@@ -194,7 +206,18 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
GatewayConfig config =
(GatewayConfig)request.getServletContext().getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE );
if( config != null && config.isHadoopKerberosSecured() ) {
- entity = new PartiallyRepeatableHttpEntity( entity, config.getHttpServerRequestBuffer() );
+ //Check if delegation token is supplied in the request
+ boolean delegationTokenPresent = false;
+ String queryString = request.getQueryString();
+ if (queryString != null) {
+ delegationTokenPresent = queryString.startsWith("delegation=") || queryString.contains("&delegation=");
+ }
+ if (replayBufferSize < 0) {
+ replayBufferSize = config.getHttpServerRequestBuffer();
+ }
+ if (!delegationTokenPresent) {
+ entity = new PartiallyRepeatableHttpEntity(entity, replayBufferSize);
+ }
}
return entity;
@@ -203,7 +226,7 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
@Override
public void doGet(URI url, HttpServletRequest request, HttpServletResponse response)
throws IOException, URISyntaxException {
- HttpGet method = new HttpGet(url);
+ HttpGet method = new HttpGet(url);
// https://issues.apache.org/jira/browse/KNOX-107 - Service URLs not rewritten for WebHDFS GET redirects
method.getParams().setBooleanParameter("http.protocol.handle-redirects", false);
copyRequestHeaderFields(method, request);
http://git-wip-us.apache.org/repos/asf/knox/blob/d3582aeb/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
index 1e66cc1..1b06a8c 100644
--- a/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/hadoop/gateway/dispatch/DefaultDispatchTest.java
@@ -22,6 +22,8 @@ import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@@ -90,20 +92,77 @@ public class DefaultDispatchTest {
@Test
public void testCallToSecureClusterWithDelegationToken() throws URISyntaxException, IOException {
- System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "true");
DefaultDispatch defaultDispatch = new DefaultDispatch();
ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
- EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( null ).anyTimes();
+ GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
+ EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(true).anyTimes();
+ EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
EasyMock.expect(inboundRequest.getQueryString()).andReturn( "delegation=123").anyTimes();
EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
- EasyMock.replay( servletContext, inboundRequest );
+ EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
- System.setProperty(GatewayConfig.HADOOP_KERBEROS_SECURED, "false");
- assertFalse("buffering in the presence of delegation token",
- (httpEntity instanceof CappedBufferHttpEntity));
+ assertFalse("buffering in the presence of delegation token",
+ (httpEntity instanceof PartiallyRepeatableHttpEntity));
+ }
+
+ @Test
+ public void testCallToNonSecureClusterWithoutDelegationToken() throws URISyntaxException, IOException {
+ DefaultDispatch defaultDispatch = new DefaultDispatch();
+ ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+ GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
+ EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(false).anyTimes();
+ EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
+ ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
+ HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
+ EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
+ EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
+ EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
+ HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
+ assertFalse("buffering in non secure cluster",
+ (httpEntity instanceof PartiallyRepeatableHttpEntity));
+ }
+
+ @Test
+ public void testCallToSecureClusterWithoutDelegationToken() throws URISyntaxException, IOException {
+ DefaultDispatch defaultDispatch = new DefaultDispatch();
+ defaultDispatch.setReplayBufferSize(10);
+ ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+ GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
+ EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn( Boolean.TRUE ).anyTimes();
+ EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
+ ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
+ HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
+ EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
+ EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
+ EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
+ HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
+ assertTrue("not buffering in the absence of delegation token",
+ (httpEntity instanceof PartiallyRepeatableHttpEntity));
+ }
+
+ @Test
+ public void testUsingDefaultBufferSize() throws URISyntaxException, IOException {
+ DefaultDispatch defaultDispatch = new DefaultDispatch();
+ ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+ GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
+ EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn( Boolean.TRUE ).anyTimes();
+ EasyMock.expect(gatewayConfig.getHttpServerRequestBuffer()).andReturn( 16 ).anyTimes();
+ EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
+ ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
+ HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
+ EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
+ EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
+ EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
+ EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
+ HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
+ assertTrue("not buffering in the absence of delegation token",
+ (httpEntity instanceof PartiallyRepeatableHttpEntity));
+ assertEquals(defaultDispatch.getReplayBufferSize(), 16);
}
}