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 2016/03/23 15:15:39 UTC
knox git commit: KNOX-668 Ranger UI proxy support with related REST
API support changes
Repository: knox
Updated Branches:
refs/heads/master ff8c1e250 -> 278ca7e8a
KNOX-668 Ranger UI proxy support with related REST API support changes
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/278ca7e8
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/278ca7e8
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/278ca7e8
Branch: refs/heads/master
Commit: 278ca7e8a83e906f466cae9a296d7a9ad0a4968f
Parents: ff8c1e2
Author: Sumit Gupta <su...@apache.org>
Authored: Tue Mar 22 16:45:03 2016 -0400
Committer: Sumit Gupta <su...@apache.org>
Committed: Tue Mar 22 16:45:03 2016 -0400
----------------------------------------------------------------------
.../rewrite/impl/FrontendFunctionProcessor.java | 2 +
.../impl/FrontendFunctionProcessorTest.java | 4 +-
.../FrontendFunctionProcessorTest/rewrite.xml | 5 ++
.../test-input-body.json | 3 +-
.../resources/services/ranger/0.5.0/rewrite.xml | 21 ++++++++
.../resources/services/ranger/0.5.0/service.xml | 23 +++++++++
.../services/rangerui/0.5.0/rewrite.xml | 51 ++++++++++++++++++++
.../services/rangerui/0.5.0/service.xml | 36 ++++++++++++++
8 files changed, 142 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
index c4d0c99..3ecb097 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteResolver;
import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.services.GatewayServices;
import java.net.URI;
import java.util.Arrays;
@@ -64,6 +65,7 @@ public class FrontendFunctionProcessor implements UrlRewriteFunctionProcessor<Fr
resolvers.put( "port", new FixedResolver( Integer.toString( frontend.getPort() ) ) );
resolvers.put( "path", new FixedResolver( frontend.getPath() ) );
}
+ resolvers.put( "topology", new FixedResolver( (String)environment.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE) ) );
resolvers.put( "address", resolvers.get( "addr" ) );
}
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
index 27f1c75..ac8e142 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
@@ -33,9 +33,9 @@ import org.apache.hadoop.test.mock.MockInteraction;
import org.apache.hadoop.test.mock.MockServlet;
import org.apache.http.auth.BasicUserPrincipal;
import org.easymock.EasyMock;
+import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.servlet.ServletTester;
import org.eclipse.jetty.util.ArrayQueue;
import org.eclipse.jetty.util.Attributes;
@@ -56,7 +56,6 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -207,6 +206,7 @@ public class FrontendFunctionProcessorTest {
JsonAssert.with( json ).assertThat( "$.addr", anyOf( is( "localhost:0" ), is( "0.0.0.0:0" ) ) );
JsonAssert.with( json ).assertThat( "$.address", anyOf( is( "localhost:0" ), is( "0.0.0.0:0" ) ) );
JsonAssert.with( json ).assertThat( "$.path", is( "" ) );
+ JsonAssert.with( json ).assertThat( "$.topology", is( "test-cluster" ) );
}
@Test
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml
index 7dbfd18..c55eb77 100644
--- a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml
+++ b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml
@@ -44,6 +44,10 @@
<rewrite template="{$frontend[path]}"/>
</rule>
+ <rule name="test-rule-frontend-topology">
+ <rewrite template="{$frontend[topology]}"/>
+ </rule>
+
<filter name="test-filter">
<content type="application/json">
<apply path="$.url" rule="test-rule-frontend-url"/>
@@ -53,6 +57,7 @@
<apply path="$.addr" rule="test-rule-frontend-addr"/>
<apply path="$.address" rule="test-rule-frontend-address"/>
<apply path="$.path" rule="test-rule-frontend-path"/>
+ <apply path="$.topology" rule="test-rule-frontend-topology"/>
</content>
</filter>
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/test-input-body.json
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/test-input-body.json b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/test-input-body.json
index 6790b98..ef625d3 100644
--- a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/test-input-body.json
+++ b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/test-input-body.json
@@ -5,5 +5,6 @@
"port":"test-input-port",
"addr":"test-input-addr",
"address":"test-input-address",
- "path":"test-input-path"
+ "path":"test-input-path",
+ "topology":"test-input-topology"
}
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/rewrite.xml
new file mode 100644
index 0000000..772c271
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/rewrite.xml
@@ -0,0 +1,21 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<rules>
+ <rule dir="IN" name="RANGER/ranger/inbound" pattern="*://*:*/**/ranger/service/public/{path=**}?{**}">
+ <rewrite template="{$serviceUrl[RANGER]}/service/public/{path=**}?{**}"/>
+ </rule>
+</rules>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/service.xml b/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/service.xml
new file mode 100644
index 0000000..308e0fc
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/ranger/0.5.0/service.xml
@@ -0,0 +1,23 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<service role="RANGER" name="ranger" version="0.5.0">
+ <routes>
+ <route path="/ranger/service/public/**"/>
+ </routes>
+ <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/>
+</service>
+
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/rewrite.xml
new file mode 100644
index 0000000..2ed3312
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/rewrite.xml
@@ -0,0 +1,51 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<rules>
+ <rule dir="IN" name="RANGERUI/rangerui/inbound/root" pattern="*://*:*/**/ranger/">
+ <rewrite template="{$serviceUrl[RANGERUI]}/"/>
+ </rule>
+ <rule dir="IN" name="RANGERUI/rangerui/inbound/path" pattern="*://*:*/**/ranger/{**}">
+ <rewrite template="{$serviceUrl[RANGERUI]}/{**}"/>
+ </rule>
+ <rule dir="IN" name="RANGERUI/rangerui/inbound/query" pattern="*://*:*/**/ranger/{**}?{**}">
+ <rewrite template="{$serviceUrl[RANGERUI]}/{**}?{**}"/>
+ </rule>
+
+ <rule dir="OUT" name="RANGERUI/rangerui/outbound/extrapath">
+ <rewrite template="{$frontend[topology]}/ranger/j_spring_security_check"/>
+ </rule>
+
+ <rule dir="OUT" name="RANGERUI/rangerui/outbound/login/headers/location">
+ <match pattern="{scheme}://{host}:{port}/{**}"/>
+ <rewrite template="{$frontend[url]}/ranger/{**}"/>
+ </rule>
+
+ <filter name="RANGERUI/rangerui/outbound/links">
+ <content type="application/javascript">
+ <apply path="j_spring_security_check" rule="RANGERUI/rangerui/outbound/extrapath"/>
+ </content>
+ <content type="*/html">
+ </content>
+ </filter>
+
+ <filter name="RANGERUI/rangerui/outbound/headers">
+ <content type="application/x-http-headers">
+ <apply path="Location" rule="RANGERUI/rangerui/outbound/login/headers/location"/>
+ </content>
+ </filter>
+
+</rules>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/278ca7e8/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/service.xml b/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/service.xml
new file mode 100644
index 0000000..854521e
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/rangerui/0.5.0/service.xml
@@ -0,0 +1,36 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<service role="RANGERUI" name="rangerui" version="0.5.0">
+ <routes>
+ <route path="/ranger">
+ <rewrite apply="RANGERUI/rangerui/inbound/root" to="request.url"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/links" to="response.body"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/headers" to="response.headers"/>
+ </route>
+ <route path="/ranger/**">
+ <rewrite apply="RANGERUI/rangerui/inbound/path" to="request.url"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/links" to="response.body"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/headers" to="response.headers"/>
+ </route>
+ <route path="/ranger/**?**">
+ <rewrite apply="RANGERUI/rangerui/inbound/query" to="request.url"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/links" to="response.body"/>
+ <rewrite apply="RANGERUI/rangerui/outbound/headers" to="response.headers"/>
+ </route>
+ </routes>
+ <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/>
+</service>