[62/64] knox git commit: KNOX-998 - Some more refactoring, making sure all the Unit Tests run and build passes !

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java
 
b/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java
index 9a9dd15..267de1b 100644
--- 
a/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryFuncTest.java
@@ -88,7 +88,7 @@ public class DeploymentFactoryFuncTest {
 File deployDir = new File( config.getGatewayDeploymentDir() );
 deployDir.mkdirs();
 
-//((GatewayTestConfig) config).setDeploymentDir( "clusters" );
+//((GatewayTestConfig) config).setDeploymentDir( "clusters" );
 
 addStacksDir(config, targetDir);
 DefaultGatewayServices srvcs = new DefaultGatewayServices();
@@ -131,11 +131,11 @@ public class DeploymentFactoryFuncTest {
 //by default the first filter will be the X-Forwarded header filter
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/role", 
equalTo( "xforwardedheaders" ) ) );
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/name", 
equalTo( "XForwardedHeaderFilter" ) ) );
-assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/class", 
equalTo( "XForwardedHeaderFilter" ) ) );
+assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/class", 
equalTo( "org.apache.knox.gateway.filter.XForwardedHeaderFilter" ) ) );
 
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/role", 
equalTo( "federation" ) ) );
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/name", 
equalTo( "HeaderPreAuth" ) ) );
-assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/class", 
equalTo( "HeaderPreAuthFederationFilter" ) ) );
+assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/class", 
equalTo( "org.apache.knox.gateway.preauth.filter.HeaderPreAuthFederationFilter" 
) ) );
 assertThat( gateway, hasXPath( 
"/gateway/resource[1]/filter[2]/param[1]/name", equalTo( "filter" ) ) );
 assertThat( gateway, hasXPath( 
"/gateway/resource[1]/filter[2]/param[1]/value", equalTo( 
"org.opensource.ExistingFilter" ) ) );
 assertThat( gateway, hasXPath( 
"/gateway/resource[1]/filter[2]/param[2]/name", equalTo( "test-param-name" ) ) 
);
@@ -252,15 +252,15 @@ public class DeploymentFactoryFuncTest {
 topology.addProvider( authorizer );
 
 EnterpriseArchive war = DeploymentFactory.createDeployment( config, 
topology );
-//File dir = new File( System.getProperty( "user.dir" ) );
-//File file = war.as( ExplodedExporter.class ).exportExploded( dir, 
"test-cluster.war" );
+//File dir = new File( System.getProperty( "user.dir" ) );
+//File file = war.as( ExplodedExporter.class ).exportExploded( dir, 
"test-cluster.war" );
 
 Document web = XmlUtils.readXml( war.get( "%2F/WEB-INF/web.xml" 
).getAsset().openStream() );
 assertThat( web, hasXPath( "/web-app" ) );
 assertThat( web, hasXPath( "/web-app/servlet" ) );
 assertThat( web, hasXPath( "/web-app/servlet/servlet-name" ) );
 assertThat( web, hasXPath( "/web-app/servlet/servlet-name", equalTo( 
"test-cluster-knox-gateway-servlet" ) ) );
-assertThat( web, hasXPath( "/web-app/servlet/servlet-class", equalTo( 
"GatewayServlet" ) ) );
+assertThat( web, hasXPath( "/web-app/servlet/servlet-class", equalTo( 
"org.apache.knox.gateway.GatewayServlet" ) ) );
 assertThat( web, hasXPath( "/web-app/servlet/init-param/param-name", 
equalTo( "gatewayDescriptorLocation" ) ) );
 assertThat( web, hasXPath( "/web-app/servlet/init-param/param-value", 
equalTo( "/WEB-INF/gateway.xml" ) ) );
 assertThat( web, hasXPath( "/web-app/servlet-mapping/servlet-name", 
equalTo( "test-cluster-knox-gateway-servlet" ) ) );
@@ -272,137 +272,137 @@ public class DeploymentFactoryFuncTest {
 //assertThat( gateway, hasXPath( "/gateway/resource[1]/target", equalTo( 
"http://localhost:50070/webhdfs/v1/?{**}; ) ) );
 
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/role", 
equalTo( "authentication" ) ) );
-assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/class", 
equalTo( "ResponseCookieFilter" ) ) );
+assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[1]/class", 
equalTo( "org.apache.knox.gateway.filter.ResponseCookieFilter" ) ) );
 
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/role", 
equalTo( "authentication" ) ) );
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[2]/class", 
equalTo( "org.apache.shiro.web.servlet.ShiroFilter" ) ) );
 
 assertThat( gateway, hasXPath( "/gateway/resource[1]/filter[3]/role", 
equalTo( "authentication" ) ) );
-assertThat( gateway, hasXPath( 

[41/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/hadoop/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderMessages.java
--
diff --git 
a/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/hadoop/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderMessages.java
 
b/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/hadoop/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderMessages.java
deleted file mode 100644
index d67b811..000
--- 
a/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/hadoop/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderMessages.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.identityasserter.hadoop.groups.filter;
-
-import org.apache.hadoop.gateway.i18n.messages.Message;
-import org.apache.hadoop.gateway.i18n.messages.MessageLevel;
-import org.apache.hadoop.gateway.i18n.messages.Messages;
-import org.apache.hadoop.gateway.i18n.messages.StackTrace;
-
-/**
- * Messages for provider - HadoopGroupProvider
- * 
- * @since 0.11
- */
-
-@Messages(logger="org.apache.hadoop.gateway")
-public interface HadoopGroupProviderMessages {
-
-  @Message( level = MessageLevel.ERROR, text = "Error getting groups for 
principal {0}" )
-  void errorGettingUserGroups(final String principal , @StackTrace( level = 
MessageLevel.DEBUG ) Exception e );
-  
-  @Message( level = MessageLevel.INFO, text = "No groups for principal {0} 
found" )
-  void noGroupsFound(final String principal);
-  
-  @Message( level = MessageLevel.DEBUG, text = "Found groups for principal {0} 
: {1}" )
-  void groupsFound(final String principal, final String groups );
-  
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/knox/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderDeploymentContributor.java
--
diff --git 
a/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/knox/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderDeploymentContributor.java
 
b/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/knox/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderDeploymentContributor.java
new file mode 100644
index 000..d04713d
--- /dev/null
+++ 
b/gateway-provider-identity-assertion-hadoop-groups/src/main/java/org/apache/knox/gateway/identityasserter/hadoop/groups/filter/HadoopGroupProviderDeploymentContributor.java
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.identityasserter.hadoop.groups.filter;
+
+import 
org.apache.knox.gateway.identityasserter.common.filter.AbstractIdentityAsserterDeploymentContributor;
+
+/**
+ * A provider deployment contributor for looking up authenticated user groups 
as
+ * seen by Hadoop implementation.
+ * 
+ * @since 0.11.0
+ */
+
+public class HadoopGroupProviderDeploymentContributor
+extends AbstractIdentityAsserterDeploymentContributor {
+
+  /**
+   * Name of our identity-assertion provider.
+   */
+  public static final String 

[49/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-demo-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
--
diff --git 
a/gateway-demo-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
 
b/gateway-demo-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
deleted file mode 100644
index 12fe30d..000
--- 
a/gateway-demo-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.security.ldap;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.api.ldap.model.entry.DefaultModification;
-import org.apache.directory.api.ldap.model.entry.ModificationOperation;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.server.core.api.CoreSession;
-import org.apache.directory.server.core.api.DirectoryService;
-import org.apache.directory.server.core.api.partition.Partition;
-import org.apache.directory.server.core.factory.DirectoryServiceFactory;
-import org.apache.directory.server.ldap.LdapServer;
-import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
-import org.apache.directory.server.protocol.shared.transport.TcpTransport;
-import org.apache.directory.server.protocol.shared.transport.Transport;
-import org.apache.log4j.PropertyConfigurator;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.ServerSocket;
-import java.util.UUID;
-
-public class SimpleLdapDirectoryServer {
-
-  private DirectoryServiceFactory factory;
-
-  private DirectoryService service;
-
-  private LdapServer server;
-
-  public SimpleLdapDirectoryServer( String rootDn, File usersLdif, 
Transport... transports ) throws Exception {
-if( !usersLdif.exists() ) {
-  throw new FileNotFoundException( usersLdif.getAbsolutePath() );
-}
-
-factory = new SimpleDirectoryServiceFactory();
-factory.init( UUID.randomUUID().toString() );
-service = factory.getDirectoryService();
-
-enabledPosixSchema( service );
-
-Partition partition = factory.getPartitionFactory().createPartition(
-service.getSchemaManager(), service.getDnFactory(), "users", rootDn, 
500,
-service.getInstanceLayout().getInstanceDirectory() );
-service.addPartition( partition );
-
-CoreSession session = service.getAdminSession();
-LdifFileLoader lfl = new LdifFileLoader( session, usersLdif, null );
-lfl.execute();
-
-server = new LdapServer();
-server.setTransports( transports );
-server.setDirectoryService( service );
-  }
-
-  private static void enabledPosixSchema( DirectoryService service ) throws 
LdapException {
-service.getSchemaManager().getLoadedSchema( "nis" ).enable();
-service.getAdminSession().modify(
-new Dn( "cn=nis,ou=schema" ),
-new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, 
"m-disabled", "FALSE" ) );
-  }
-
-  public void start() throws Exception {
-service.startup();
-server.start();
-  }
-
-  public void stop( boolean clean ) throws Exception {
-server.stop();
-service.shutdown();
-if( clean ) {
-  FileUtils.deleteDirectory( 
service.getInstanceLayout().getInstanceDirectory() );
-}
-  }
-
-  public static void main( String[] args ) throws Exception {
-PropertyConfigurator.configure( System.getProperty( "log4j.configuration" 
) );
-
-SimpleLdapDirectoryServer ldap;
-
-File file;
-if ( args.length < 1 ) {
-  file = new File( "conf/users.ldif" );
-} else {
-  File dir = new File( args[0] );
-  if( !dir.exists() || !dir.isDirectory() ) {
-throw new FileNotFoundException( dir.getAbsolutePath() );
-  }
-  file = new File( dir, "users.ldif" );
-}
-
-if( !file.exists() || !file.canRead() ) {
-  throw new FileNotFoundException( file.getAbsolutePath() );
-}
-
-int port = 33389;
-
-// Make sure the 

[27/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteStreamFilter.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteStreamFilter.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteStreamFilter.java
deleted file mode 100644
index 41f141b..000
--- 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteStreamFilter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.impl.javascript;
-
-import org.apache.commons.io.input.ReaderInputStream;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStreamFilter;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-public class JavaScriptUrlRewriteStreamFilter implements 
UrlRewriteStreamFilter {
-
-  private static String[] TYPES = new String[]{ "application/javascript", 
"text/javascript", "*/javascript",
-  "application/x-javascript", "text/x-javascript", "*/x-javascript" };
-  private static String[] NAMES = new String[]{ null };
-
-  @Override
-  public String[] getTypes() {
-return TYPES;
-  }
-
-  @Override
-  public String[] getNames() {
-return NAMES;
-  }
-
-  @Override
-  public InputStream filter(
-  InputStream stream,
-  String encoding,
-  UrlRewriter rewriter,
-  Resolver resolver,
-  UrlRewriter.Direction direction,
-  UrlRewriteFilterContentDescriptor config )
-  throws IOException {
-
-if ( config != null ) {
-  return new ReaderInputStream(
-  new JavaScriptUrlRewriteFilterReader(
-  new InputStreamReader( stream, encoding ), rewriter, resolver, 
direction, config ), encoding );
-} else {
-  return stream;
-}
-  }
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonFilterReader.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonFilterReader.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonFilterReader.java
deleted file mode 100644
index 10fc9b8..000
--- 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonFilterReader.java
+++ /dev/null
@@ -1,644 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.impl.json;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;

[61/64] knox git commit: Merge branch 'master' into KNOX-998-Package_Restructuring

2017-09-01 Thread more
Merge branch 'master' into KNOX-998-Package_Restructuring

# Conflicts:
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayLocalServiceFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewayMultiFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/GatewaySslFuncTest.java
#   gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java
#   
gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/912c5360
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/912c5360
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/912c5360

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 912c53602a409e4361a73130e4dbc55a7b73c8ea
Parents: a25f8a7 6657f2f
Author: Sandeep More 
Authored: Tue Aug 29 11:02:24 2017 -0400
Committer: Sandeep More 
Committed: Tue Aug 29 11:02:24 2017 -0400

--
 .../apache/knox/gateway/GatewayTestDriver.java  | 20 +
 .../knox/gateway/GatewayAdminFuncTest.java  | 27 +++-
 .../gateway/GatewayAdminTopologyFuncTest.java   | 36 +---
 .../apache/knox/gateway/GatewayAppFuncTest.java | 26 ++--
 .../knox/gateway/GatewayBasicFuncTest.java  | 42 +--
 .../knox/gateway/GatewayDeployFuncTest.java | 26 +++-
 .../GatewayLdapDynamicGroupFuncTest.java| 44 +++-
 .../knox/gateway/GatewayLdapGroupFuncTest.java  | 36 +---
 .../gateway/GatewayLdapPosixGroupFuncTest.java  | 34 ++-
 .../gateway/GatewayLocalServiceFuncTest.java| 26 +++-
 .../knox/gateway/GatewayMultiFuncTest.java  | 29 -
 .../knox/gateway/GatewaySampleFuncTest.java | 26 +++-
 .../apache/knox/gateway/GatewaySslFuncTest.java | 23 ++
 .../apache/knox/gateway/Knox242FuncTest.java| 43 +++
 .../gateway/KnoxCliLdapFuncTestNegative.java| 32 --
 .../gateway/KnoxCliLdapFuncTestPositive.java| 32 --
 .../apache/knox/gateway/KnoxCliSysBindTest.java | 32 --
 .../solr/query_response.xml | 20 +
 18 files changed, 194 insertions(+), 360 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/912c5360/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java
--
diff --cc 
gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java
index 28c0043,000..a893cb4
mode 100644,00..100644
--- 
a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java
+++ 
b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java
@@@ -1,347 -1,0 +1,351 @@@
 +/**
 + * 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.
 + */
 +package org.apache.knox.gateway;
 +
 +import static org.junit.Assert.assertThat;
 +import static org.junit.Assert.fail;
 +
 +import java.io.File;
 +import 

[36/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServicePortFunctionDescriptor.java
--
diff --git 
a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServicePortFunctionDescriptor.java
 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServicePortFunctionDescriptor.java
new file mode 100644
index 000..fa359e8
--- /dev/null
+++ 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServicePortFunctionDescriptor.java
@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.svcregfunc.api;
+
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
+
+public class ServicePortFunctionDescriptor implements
+UrlRewriteFunctionDescriptor {
+
+  public static final String FUNCTION_NAME = "servicePort";
+
+  @Override
+  public String name() {
+return FUNCTION_NAME;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceSchemeFunctionDescriptor.java
--
diff --git 
a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceSchemeFunctionDescriptor.java
 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceSchemeFunctionDescriptor.java
new file mode 100644
index 000..7bb20aa
--- /dev/null
+++ 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceSchemeFunctionDescriptor.java
@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.svcregfunc.api;
+
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
+
+public class ServiceSchemeFunctionDescriptor implements
+UrlRewriteFunctionDescriptor {
+
+  public static final String FUNCTION_NAME = "serviceScheme";
+
+  @Override
+  public String name() {
+return FUNCTION_NAME;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceUrlFunctionDescriptor.java
--
diff --git 
a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceUrlFunctionDescriptor.java
 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceUrlFunctionDescriptor.java
new file mode 100644
index 000..fa51283
--- /dev/null
+++ 
b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/knox/gateway/svcregfunc/api/ServiceUrlFunctionDescriptor.java
@@ -0,0 +1,32 @@
+/**
+ * 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 

[22/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonUrlRewriteStreamFilter.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonUrlRewriteStreamFilter.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonUrlRewriteStreamFilter.java
new file mode 100644
index 000..bebc616
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonUrlRewriteStreamFilter.java
@@ -0,0 +1,59 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl.json;
+
+import org.apache.commons.io.input.ReaderInputStream;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStreamFilter;
+import org.apache.knox.gateway.util.urltemplate.Resolver;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+public class JsonUrlRewriteStreamFilter implements UrlRewriteStreamFilter {
+
+  private static String[] TYPES = new String[]{ "application/json", 
"text/json", "*/json" };
+  private static String[] NAMES = new String[]{ null };
+
+  @Override
+  public String[] getTypes() {
+return TYPES;
+  }
+
+  @Override
+  public String[] getNames() {
+return NAMES;
+  }
+
+  @Override
+  public InputStream filter(
+  InputStream stream,
+  String encoding,
+  UrlRewriter rewriter,
+  Resolver resolver,
+  UrlRewriter.Direction direction,
+  UrlRewriteFilterContentDescriptor config )
+  throws IOException {
+return new ReaderInputStream(
+new JsonUrlRewriteFilterReader(
+new InputStreamReader( stream, encoding ), rewriter, resolver, 
direction, config ), encoding );
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/noop/NoOpUrlRewriteStreamFilter.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/noop/NoOpUrlRewriteStreamFilter.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/noop/NoOpUrlRewriteStreamFilter.java
new file mode 100644
index 000..3db2bbd
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/noop/NoOpUrlRewriteStreamFilter.java
@@ -0,0 +1,55 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl.noop;
+
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStreamFilter;
+import org.apache.knox.gateway.util.urltemplate.Resolver;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class NoOpUrlRewriteStreamFilter implements UrlRewriteStreamFilter {
+
+  private static String[] TYPES = new String[]{ null };
+  private static String[] NAMES = new 

[58/64] knox git commit: Merge branch 'master' into KNOX-998-Package_Restructuring

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/912c5360/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java
--
diff --cc 
gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java
index ea19962,000..7df6b7a
mode 100644,00..100644
--- 
a/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/knox/gateway/GatewaySampleFuncTest.java
@@@ -1,219 -1,0 +1,203 @@@
 +/**
 + * 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.
 + */
 +package org.apache.knox.gateway;
 +
 +import com.mycila.xmltool.XMLDoc;
 +import com.mycila.xmltool.XMLTag;
 +import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 +import org.apache.knox.gateway.config.GatewayConfig;
 +import org.apache.knox.gateway.security.ldap.SimpleLdapDirectoryServer;
 +import org.apache.knox.gateway.services.DefaultGatewayServices;
 +import org.apache.knox.gateway.services.ServiceLifecycleException;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.http.HttpStatus;
 +import org.apache.log4j.Appender;
 +import org.hamcrest.MatcherAssert;
 +import org.hamcrest.Matchers;
 +import org.junit.AfterClass;
 +import org.junit.BeforeClass;
 +import org.junit.Test;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
 +import java.io.File;
 +import java.io.FileOutputStream;
 +import java.io.IOException;
 +import java.io.InputStream;
 +import java.net.URL;
- import java.nio.file.FileSystems;
- import java.nio.file.Path;
 +import java.util.Enumeration;
 +import java.util.HashMap;
 +import java.util.Map;
 +import java.util.UUID;
 +
 +import static com.jayway.restassured.RestAssured.given;
 +import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 +import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 +import static org.hamcrest.CoreMatchers.is;
 +import static org.hamcrest.CoreMatchers.notNullValue;
 +import static org.junit.Assert.assertThat;
 +
 +public class GatewaySampleFuncTest {
 +
 +  private static Class RESOURCE_BASE_CLASS = GatewaySampleFuncTest.class;
 +  private static Logger LOG = LoggerFactory.getLogger( 
GatewaySampleFuncTest.class );
 +
 +  public static Enumeration appenders;
 +  public static GatewayConfig config;
 +  public static GatewayServer gateway;
 +  public static String gatewayUrl;
 +  public static String clusterUrl;
-   public static SimpleLdapDirectoryServer ldap;
-   public static TcpTransport ldapTransport;
++  private static GatewayTestDriver driver = new GatewayTestDriver();
 +
 +  @BeforeClass
 +  public static void setupSuite() throws Exception {
 +LOG_ENTER();
 +//appenders = NoOpAppender.setUp();
- setupLdap();
++driver.setupLdap(0);
 +setupGateway();
 +LOG_EXIT();
 +  }
 +
 +  @AfterClass
 +  public static void cleanupSuite() throws Exception {
 +LOG_ENTER();
 +gateway.stop();
- ldap.stop( true );
++driver.cleanup();
 +//FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) );
 +//NoOpAppender.tearDown( appenders );
 +LOG_EXIT();
 +  }
 +
-   public static void setupLdap() throws Exception {
- String basedir = System.getProperty("basedir");
- if (basedir == null) {
-   basedir = new File(".").getCanonicalPath();
- }
- Path path = FileSystems.getDefault().getPath(basedir, 
"/src/test/resources/users.ldif");
- 
- ldapTransport = new TcpTransport( 0 );
- ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", 
path.toFile(), ldapTransport );
- ldap.start();
- LOG.info( "LDAP port = " + 
ldapTransport.getAcceptor().getLocalAddress().getPort() );
-   }
- 
 +  public static void setupGateway() throws Exception {
 +
 +File targetDir = new File( System.getProperty( "user.dir" ), "target" );
 +File gatewayDir = new File( targetDir, "gateway-home-" + 
UUID.randomUUID() );
 +gatewayDir.mkdirs();
 +
 +GatewayTestConfig testConfig = new GatewayTestConfig();
 +config = testConfig;
 +testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 +
 +File topoDir = new File( testConfig.getGatewayTopologyDir() );
 +

[56/64] knox git commit: Merge branch 'master' into KNOX-998-Package_Restructuring

2017-09-01 Thread more
Merge branch 'master' into KNOX-998-Package_Restructuring


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/a4ba9bb5
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/a4ba9bb5
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/a4ba9bb5

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: a4ba9bb5c46a36649907b9662ee7686c2c1d943a
Parents: af9b0c3 ac532bd
Author: Sandeep More 
Authored: Tue Aug 29 10:34:03 2017 -0400
Committer: Sandeep More 
Committed: Tue Aug 29 10:34:03 2017 -0400

--
 .../services/metrics/impl/instr/InstrUtils.java | 54 
 .../instr/InstrHttpClientBuilderProvider.java   |  3 +-
 .../impl/instr/InstrumentedGatewayFilter.java   |  2 +-
 .../services/zeppelinui/0.6.0/rewrite.xml   |  4 +-
 4 files changed, 60 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/a4ba9bb5/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
--
diff --cc 
gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
index 341b35c,000..073adcd
mode 100644,00..100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
@@@ -1,70 -1,0 +1,71 @@@
 +/**
 + * 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.
 + */
 +package org.apache.knox.gateway.services.metrics.impl.instr;
 +
 +import com.codahale.metrics.MetricRegistry;
 +import com.codahale.metrics.httpclient.HttpClientMetricNameStrategy;
 +import com.codahale.metrics.httpclient.InstrumentedHttpRequestExecutor;
 +import org.apache.knox.gateway.services.metrics.InstrumentationProvider;
 +import org.apache.knox.gateway.services.metrics.MetricsContext;
 +import org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService;
 +import org.apache.http.Header;
 +import org.apache.http.HttpRequest;
 +import org.apache.http.RequestLine;
 +import org.apache.http.client.utils.URIBuilder;
 +import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 +
 +import java.net.URISyntaxException;
 +
 +public class InstrHttpClientBuilderProvider implements
 +InstrumentationProvider {
 +
 +  @Override
 +  public HttpClientBuilder getInstrumented(MetricsContext metricsContext) {
 +MetricRegistry registry = (MetricRegistry) 
metricsContext.getProperty(DefaultMetricsService.METRICS_REGISTRY);
 +return  HttpClientBuilder.create().setRequestExecutor(new 
InstrumentedHttpRequestExecutor(registry, TOPOLOGY_URL_AND_METHOD)).
 +setConnectionManager(new PoolingHttpClientConnectionManager());
 +  }
 +
 +  @Override
 +  public HttpClientBuilder getInstrumented(HttpClientBuilder instanceClass, 
MetricsContext metricsContext) {
 +throw new UnsupportedOperationException();
 +  }
 +
 +  private static final HttpClientMetricNameStrategy TOPOLOGY_URL_AND_METHOD = 
new HttpClientMetricNameStrategy() {
 +public String getNameFor(String name, HttpRequest request) {
 +  try {
 +String context = "";
 +Header header = request.getFirstHeader("X-Forwarded-Context");
 +if (header != null) {
 +  context = header.getValue();
 +}
 +RequestLine requestLine = request.getRequestLine();
 +URIBuilder uriBuilder = new URIBuilder(requestLine.getUri());
- return MetricRegistry.name("service", new String[]{name, context + 
uriBuilder.removeQuery().build().toString(), methodNameString(request)});
++String resourcePath = 
InstrUtils.getResourcePath(uriBuilder.removeQuery().build().toString());
++return MetricRegistry.name("service", new String[]{name, context + 
resourcePath, methodNameString(request)});

[34/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/knox/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
--
diff --git 
a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/knox/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
 
b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/knox/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
new file mode 100644
index 000..51d14ca
--- /dev/null
+++ 
b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/knox/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
@@ -0,0 +1,153 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.svcregfunc.impl;
+
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.apache.knox.gateway.ha.provider.HaProvider;
+import org.apache.knox.gateway.ha.provider.HaServletContextListener;
+import org.apache.knox.gateway.services.GatewayServices;
+import org.apache.knox.gateway.services.hostmap.HostMapper;
+import org.apache.knox.gateway.services.hostmap.HostMapperService;
+import org.apache.knox.gateway.services.registry.ServiceRegistry;
+import 
org.apache.knox.gateway.svcregfunc.api.ServiceMappedAddressFunctionDescriptor;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.fail;
+
+public class ServiceMappedAddressFunctionProcessorTest {
+
+  HostMapperService hms;
+  HostMapper hm;
+  ServiceRegistry reg;
+  GatewayServices svc;
+  UrlRewriteEnvironment env;
+  UrlRewriteContext ctx;
+  ServiceMappedAddressFunctionDescriptor desc;
+
+  @Before
+  public void setUp() {
+hm = EasyMock.createNiceMock( HostMapper.class );
+EasyMock.expect( hm.resolveInboundHostName( "test-host" ) ).andReturn( 
"test-internal-host" ).anyTimes();
+
+hms = EasyMock.createNiceMock( HostMapperService.class );
+EasyMock.expect( hms.getHostMapper( "test-cluster" ) ).andReturn( hm 
).anyTimes();
+
+reg = EasyMock.createNiceMock( ServiceRegistry.class );
+EasyMock.expect( reg.lookupServiceURL( "test-cluster", "test-service" ) 
).andReturn( "test-scheme://test-host:777/test-path" ).anyTimes();
+
+svc = EasyMock.createNiceMock( GatewayServices.class );
+EasyMock.expect( svc.getService( GatewayServices.SERVICE_REGISTRY_SERVICE 
) ).andReturn( reg ).anyTimes();
+EasyMock.expect( svc.getService( GatewayServices.HOST_MAPPING_SERVICE ) 
).andReturn( hms ).anyTimes();
+
+env = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
+EasyMock.expect( env.getAttribute( 
GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( svc ).anyTimes();
+EasyMock.expect( env.getAttribute( 
GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster" 
).anyTimes();
+
+ctx = EasyMock.createNiceMock( UrlRewriteContext.class );
+EasyMock.expect( ctx.getDirection() ).andReturn( UrlRewriter.Direction.IN 
).anyTimes();
+
+desc = EasyMock.createNiceMock( 
ServiceMappedAddressFunctionDescriptor.class );
+
+ HaProvider haProvider = EasyMock.createNiceMock( HaProvider.class );
+
+ 
EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
+
+ 
EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
+
+ EasyMock.replay( hm, hms, reg, svc, env, desc, ctx, haProvider );
+  }
+
+  @Test
+  public void testServiceLoader() throws Exception {
+ServiceLoader 

[13/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-authc-anon/src/test/java/org/apache/knox/gateway/deploy/AnonymousAuthDeploymentContributorTest.java
--
diff --git 
a/gateway-provider-security-authc-anon/src/test/java/org/apache/knox/gateway/deploy/AnonymousAuthDeploymentContributorTest.java
 
b/gateway-provider-security-authc-anon/src/test/java/org/apache/knox/gateway/deploy/AnonymousAuthDeploymentContributorTest.java
new file mode 100644
index 000..c1d8fcb
--- /dev/null
+++ 
b/gateway-provider-security-authc-anon/src/test/java/org/apache/knox/gateway/deploy/AnonymousAuthDeploymentContributorTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.deploy;
+
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+public class AnonymousAuthDeploymentContributorTest {
+
+  @Test
+  public void testServiceLoader() throws Exception {
+ServiceLoader loader = ServiceLoader.load( 
ProviderDeploymentContributor.class );
+Iterator iterator = loader.iterator();
+assertThat( "Service iterator empty.", iterator.hasNext() );
+while( iterator.hasNext() ) {
+  Object object = iterator.next();
+  if( object instanceof AnonymousAuthDeploymentContributor ) {
+return;
+  }
+}
+fail( "Failed to find " + 
AnonymousAuthDeploymentContributor.class.getName() + " via service loader." );
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-authz-acls/src/main/java/org/apache/hadoop/gateway/deploy/impl/AclsAuthzDeploymentContributor.java
--
diff --git 
a/gateway-provider-security-authz-acls/src/main/java/org/apache/hadoop/gateway/deploy/impl/AclsAuthzDeploymentContributor.java
 
b/gateway-provider-security-authz-acls/src/main/java/org/apache/hadoop/gateway/deploy/impl/AclsAuthzDeploymentContributor.java
deleted file mode 100644
index 2c150e3..000
--- 
a/gateway-provider-security-authz-acls/src/main/java/org/apache/hadoop/gateway/deploy/impl/AclsAuthzDeploymentContributor.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.deploy.impl;
-
-import org.apache.hadoop.gateway.deploy.DeploymentContext;
-import org.apache.hadoop.gateway.deploy.ProviderDeploymentContributorBase;
-import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
-import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
-import org.apache.hadoop.gateway.services.security.KeystoreService;
-import org.apache.hadoop.gateway.services.security.KeystoreServiceException;
-import org.apache.hadoop.gateway.topology.Provider;
-import org.apache.hadoop.gateway.topology.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-public class AclsAuthzDeploymentContributor extends 
ProviderDeploymentContributorBase {
-
-  private static final String FILTER_CLASSNAME = 
"org.apache.hadoop.gateway.filter.AclsAuthorizationFilter";
-
-  @Override
-  public String getRole() {
-return "authorization";
-  }
-
-  @Override
-  public String getName() {
-return "AclsAuthz";
-  }
-
-  

[23/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormFilterReader.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormFilterReader.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormFilterReader.java
new file mode 100644
index 000..7d82633
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormFilterReader.java
@@ -0,0 +1,105 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl.form;
+
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
+import org.apache.knox.gateway.filter.rewrite.i18n.UrlRewriteMessages;
+import org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteUtil;
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringWriter;
+
+public class FormFilterReader extends Reader {
+
+  private static final UrlRewriteMessages LOG = MessagesFactory.get( 
UrlRewriteMessages.class );
+
+  private int offset;
+  private StringWriter writer;
+  private StringBuffer buffer;
+  private Reader reader;
+  private FormReader parser;
+  private FormWriter generator;
+  private UrlRewriteFilterContentDescriptor config;
+
+  public FormFilterReader( Reader reader, UrlRewriteFilterContentDescriptor 
config ) throws IOException {
+this.reader = reader;
+this.config = config;
+parser = new FormReader( reader );
+writer = new StringWriter();
+buffer = writer.getBuffer();
+offset = 0;
+generator = new FormWriter( writer );
+  }
+
+  @Override
+  public int read( char[] destBuffer, int destOffset, int destCount ) throws 
IOException {
+int count = 0;
+int available = buffer.length() - offset;
+
+if( available == 0 ) {
+  FormPair pair = parser.getNextPair();
+  if( pair == null ) {
+count = -1;
+  } else {
+processPair();
+available = buffer.length() - offset;
+  }
+}
+
+if( available > 0 ) {
+  count = Math.min( destCount, available );
+  buffer.getChars( offset, offset+count, destBuffer, destOffset );
+  offset += count;
+  if( offset == buffer.length() ) {
+offset = 0;
+buffer.setLength( 0 );
+  }
+}
+
+return count;
+  }
+
+  private void processPair() throws IOException {
+FormPair pair = parser.getCurrentPair();
+String name = pair.getName();
+String value = pair.getValue();
+String rule = UrlRewriteUtil.pickFirstRuleWithEqualsIgnoreCasePathMatch( 
config, name );
+try {
+  value = filterValue( name, pair.getValue(), rule );
+  pair.setValue( value );
+} catch( Exception e ) {
+  LOG.failedToFilterValue( pair.getValue(), rule, e );
+  // Write original value.
+}
+generator.writePair( pair );
+  }
+
+  protected String filterValue( String name, String value, String rule ) {
+return value;
+  }
+
+  @Override
+  public void close() throws IOException {
+writer.close();
+reader.close();
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormPair.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormPair.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormPair.java
new file mode 100644
index 000..95c896b
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/form/FormPair.java
@@ -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 

[37/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
--
diff --git 
a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
 
b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
deleted file mode 100644
index 59d1f8a..000
--- 
a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.inboundurl.api;
-
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.fail;
-
-public class InboundUrlFunctionDescriptorTest {
-
-  @Test
-  public void testServiceLoader() throws Exception {
-ServiceLoader loader = ServiceLoader.load( 
UrlRewriteFunctionDescriptor.class );
-Iterator iterator = loader.iterator();
-assertThat( "Service iterator empty.", iterator.hasNext() );
-while( iterator.hasNext() ) {
-  Object object = iterator.next();
-  if( object instanceof InboundUrlFunctionDescriptor ) {
-String name = ((InboundUrlFunctionDescriptor)object).name();
-assertThat( name, is("inboundurl"));
-return;
-  }
-}
-fail( "Failed to find " + InboundUrlFunctionDescriptor.class.getName() + " 
via service loader." );
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
--
diff --git 
a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
 
b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
deleted file mode 100644
index f78bf50..000
--- 
a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.inboundurl.impl;
-
-import com.google.common.collect.Lists;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt;
-import 
org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;

[43/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
--
diff --git 
a/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
 
b/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
deleted file mode 100644
index 961fef7..000
--- 
a/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.identityasserter.common.filter;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.hadoop.gateway.SpiGatewayMessages;
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.apache.hadoop.gateway.servlet.SynchronousServletInputStreamAdapter;
-import org.apache.hadoop.gateway.util.HttpUtils;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.charset.Charset;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-public class IdentityAsserterHttpServletRequestWrapper extends 
HttpServletRequestWrapper {
-
-private static SpiGatewayMessages log = MessagesFactory.get( 
SpiGatewayMessages.class );
-
-  private static final String PRINCIPAL_PARAM = "user.name";
-  private static final String DOAS_PRINCIPAL_PARAM = "doAs";
-  
-  String username = null;
-
-  public IdentityAsserterHttpServletRequestWrapper( HttpServletRequest 
request, String principal ) {
-super(request);
-username = principal;
-  }
-
-  @Override
-  public Principal getUserPrincipal() {
-return new PrimaryPrincipal(username);
-  }
-
-  @Override
-  public String getParameter(String name) {
-if (name.equals(PRINCIPAL_PARAM)) {
-  return username;
-}
-return super.getParameter(name);
-  }
-  
-  @SuppressWarnings("rawtypes")
-  @Override
-  public Map getParameterMap() {
-Map map = null;
-try {
-  map = getParams();
-} catch (UnsupportedEncodingException e) {
-  log.unableToGetParamsFromQueryString(e);
-}
-return map;
-  }
-
-  @SuppressWarnings({ "unchecked", "rawtypes" })
-  @Override
-  public Enumeration getParameterNames() {
-Enumeration e = null;
-Map params;
-try {
-  params = getParams();
-  if (params == null) {
-params = new HashMap<>();
-  }
-  e = Collections.enumeration((Collection) params.keySet());
-} catch (UnsupportedEncodingException e1) {
-  log.unableToGetParamsFromQueryString(e1);
-}
-
-return e;
-  }
-
-  @Override
-  public String[] getParameterValues(String name) {
-String[] p = null;
-Map params;
-try {
-  params = getParams();
-  if (params == null) {
-params = new HashMap<>();
-  }
-  p = (String[]) params.get(name).toArray();
-} catch (UnsupportedEncodingException e) {
-  log.unableToGetParamsFromQueryString(e);
-}
-
-return p;
-  }
-
-  private Map getParams( String qString )
-  throws UnsupportedEncodingException {
-Map params = null;
-if (getMethod().equals("GET")) {
-  if (qString != null && qString.length() > 0) {
-params = HttpUtils.splitQuery( qString 

[01/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
Repository: knox
Updated Branches:
  refs/heads/KNOX-998-Package_Restructuring 115913527 -> 2e6713b6c


http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentContextImpl.java
--
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentContextImpl.java
 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentContextImpl.java
deleted file mode 100644
index 39a2a1b..000
--- 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentContextImpl.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.deploy;
-
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
-import org.apache.hadoop.gateway.descriptor.GatewayDescriptor;
-import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
-import org.apache.hadoop.gateway.topology.Provider;
-import org.apache.hadoop.gateway.topology.Service;
-import org.apache.hadoop.gateway.topology.Topology;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class DeploymentContextImpl implements DeploymentContext {
-
-  private GatewayConfig gatewayConfig;
-  private Topology topology;
-  private GatewayDescriptor gatewayDescriptor;
-  private WebArchive webArchive;
-  private WebAppDescriptor webAppDescriptor;
-  Map providers;
-  private Map descriptors;
-
-  public DeploymentContextImpl(
-  GatewayConfig gatewayConfig,
-  Topology topology,
-  GatewayDescriptor gatewayDescriptor,
-  WebArchive webArchive,
-  WebAppDescriptor webAppDescriptor,
-  Map providers ) {
-this.gatewayConfig = gatewayConfig;
-this.topology = topology;
-this.gatewayDescriptor = gatewayDescriptor;
-this.webArchive = webArchive;
-this.webAppDescriptor = webAppDescriptor;
-this.providers = providers;
-this.descriptors = new HashMap<>();
-  }
-
-//  @Override
-//  public ServiceDeploymentContributor getServiceContributor( String role, 
String name ) {
-//ServiceDeploymentContributor contributor = null;
-//if( name == null ) {
-//  List list = services.get( role );
-//  if( !list.isEmpty() ) {
-//contributor = list.get( 0 );
-//  }
-//} else {
-//  contributor = DeploymentFactory.getServiceContributor( role, name );
-//}
-//return contributor;
-//  }
-
-//  @Override
-//  public ResourceDescriptorFactory getResourceDescriptorFactory( Service 
service ) {
-//return GatewayDescriptorFactory.getResourceDescriptorFactory( service );
-//  }
-//
-//  @Override
-//  public FilterDescriptorFactory getFilterDescriptorFactory( String 
filterRole ) {
-//return GatewayDescriptorFactory.getFilterDescriptorFactory( filterRole );
-//  }
-
-  @Override
-  public GatewayConfig getGatewayConfig() {
-return gatewayConfig;
-  }
-
-  @Override
-  public Topology getTopology() {
-return topology;
-  }
-
-  @Override
-  public WebArchive getWebArchive() {
-return webArchive;
-  }
-
-  @Override
-  public WebAppDescriptor getWebAppDescriptor() {
-return webAppDescriptor;
-  }
-
-  @Override
-  public GatewayDescriptor getGatewayDescriptor() {
-return gatewayDescriptor;
-  }
-
-  @Override
-  public void contributeFilter(
-  Service service,
-  ResourceDescriptor resource,
-  String role,
-  String name,
-  List params ) {
-ProviderDeploymentContributor contributor = 
DeploymentFactory.getProviderContributor( providers, role, name );
-Provider provider = getTopology().getProvider( role, name );
-if( provider == null ) {
-  provider = new Provider();
-  provider.setRole( role );
-  provider.setName( name );
-  provider.setEnabled( true );
-}
-if( provider.isEnabled() ) {
-  contributor.contributeFilter( this, provider, service, resource, params 
);
-

[53/64] knox git commit: KNOX-989 - Report metrics at service level (/webhdfs/v1) instead of url with args (/webhdfs/v1/?op=LISTSTATUS) (Mohammad Kamrul Islam via Sandeep More)

2017-09-01 Thread more
KNOX-989 - Report metrics at service level (/webhdfs/v1) instead of url with 
args (/webhdfs/v1/?op=LISTSTATUS) (Mohammad Kamrul Islam via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/ac532bd7
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/ac532bd7
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/ac532bd7

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: ac532bd73c5da8997f865e048b36c76fd3c11301
Parents: bea3974
Author: Sandeep More 
Authored: Fri Aug 25 12:08:17 2017 -0400
Committer: Sandeep More 
Committed: Fri Aug 25 12:09:21 2017 -0400

--
 .../instr/InstrHttpClientBuilderProvider.java   |  3 +-
 .../services/metrics/impl/instr/InstrUtils.java | 54 
 .../impl/instr/InstrumentedGatewayFilter.java   |  2 +-
 3 files changed, 57 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
--
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
index eb3ec57..e96c05e 100644
--- 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
+++ 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrHttpClientBuilderProvider.java
@@ -57,7 +57,8 @@ public class InstrHttpClientBuilderProvider implements 
InstrumentationProviderhttp://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
--
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
new file mode 100644
index 000..20e359b
--- /dev/null
+++ 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrUtils.java
@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.gateway.services.metrics.impl.instr;
+
+import com.google.common.base.Strings;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class InstrUtils {
+
+//This regular expression pattern is used to parse the *first* two elements
+//of a path. For example, if the path is “/webhdfs/v1/d1/d2/d2/d4”, 
this pattern
+//can be used to get the first two ("/webhdfs/v1/"). The "?" in pattern
+//ensures not to be greedy in matching.
+private static Pattern p = Pattern.compile("/.*?/.*?/");
+
+/**
+ * This function parses the pathinfo provided  in any servlet context and
+ * returns the segment that is related to the resource.
+ * For example, if the path is "/webhdfs/v1/d1/d2/d2/d4". it returns 
"/webhdfs/v1"
+ *
+ * @param fullPath
+ * @return
+ */
+public static String getResourcePath(String fullPath) {
+String resourcePath = "";
+if (!Strings.isNullOrEmpty(fullPath)) {
+Matcher m = p.matcher(fullPath);
+if (m.find()) {
+resourcePath = m.group(0);
+} else {
+resourcePath = fullPath;
+}
+}
+return resourcePath;
+}
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/ac532bd7/gateway-server/src/main/java/org/apache/hadoop/gateway/services/metrics/impl/instr/InstrumentedGatewayFilter.java
--
diff --git 

[20/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
deleted file mode 100644
index 55ef322..000
--- 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
+++ /dev/null
@@ -1,921 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.api;
-
-import com.jayway.jsonassert.JsonAssert;
-import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.test.TestUtils;
-import org.apache.hadoop.test.log.NoOpAppender;
-import org.apache.hadoop.test.mock.MockInteraction;
-import org.apache.hadoop.test.mock.MockServlet;
-import org.apache.log4j.Appender;
-import org.apache.log4j.Logger;
-import org.eclipse.jetty.http.HttpHeader;
-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.junit.After;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.EnumSet;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.fail;
-import static org.xmlmatchers.XmlMatchers.hasXPath;
-import static org.xmlmatchers.transform.XmlConverters.the;
-
-public class UrlRewriteServletFilterTest {
-
-  Logger LOG = Logger.getLogger(UrlRewriteServletFilterTest.class);
-
-  private ServletTester server;
-  private HttpTester.Request request;
-  private HttpTester.Response response;
-  private ArrayQueue interactions;
-  private MockInteraction interaction;
-
-  private static URL getTestResource( String name ) {
-name = UrlRewriteServletFilterTest.class.getName().replaceAll( "\\.", "/" 
) + "/" + name;
-URL url = ClassLoader.getSystemResource( name );
-return url;
-  }
-
-  public void setUp( Map initParams ) throws Exception {
-String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm();
-
-server = new ServletTester();
-server.setContextPath( "/" );
-server.getContext().addEventListener( new 
UrlRewriteServletContextListener() );
-server.getContext().setInitParameter(
-UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, 
descriptorUrl );
-
-FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", 
EnumSet.of( DispatcherType.REQUEST ) );
-setupFilter.setFilter( new SetupFilter() );
-FilterHolder rewriteFilter = server.addFilter( 
UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
-if( initParams != null ) {
-  for( Map.Entry entry : initParams.entrySet() ) {
-rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() );
-  }
-}
-rewriteFilter.setFilter( new UrlRewriteServletFilter() );
-
-interactions = new ArrayQueue();
-
-ServletHolder servlet = server.addServlet( MockServlet.class, "/" );
-servlet.setServlet( new MockServlet( "mock-servlet", interactions ) );
-
-server.start();
-
-

[55/64] knox git commit: KNOX-963 - Use GatewayTestDriver to configure LDAP in gateway-tests

2017-09-01 Thread more
KNOX-963 - Use GatewayTestDriver to configure LDAP in gateway-tests


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/6657f2fd
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/6657f2fd
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/6657f2fd

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 6657f2fd9f52c8303fc9a2d1d72eef38be719288
Parents: d2f0fc0
Author: Colm O hEigeartaigh 
Authored: Tue Aug 29 15:28:01 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Tue Aug 29 15:28:01 2017 +0100

--
 .../hadoop/gateway/GatewayTestDriver.java   | 20 +
 .../hadoop/gateway/GatewayAdminFuncTest.java| 26 ++-
 .../gateway/GatewayAdminTopologyFuncTest.java   | 30 +++--
 .../hadoop/gateway/GatewayAppFuncTest.java  | 28 ++--
 .../hadoop/gateway/GatewayBasicFuncTest.java|  4 +-
 .../hadoop/gateway/GatewayDeployFuncTest.java   | 27 ++--
 .../GatewayLdapDynamicGroupFuncTest.java| 43 ++-
 .../gateway/GatewayLdapGroupFuncTest.java   | 38 -
 .../gateway/GatewayLdapPosixGroupFuncTest.java  | 34 +--
 .../gateway/GatewayLocalServiceFuncTest.java| 27 ++--
 .../hadoop/gateway/GatewayMultiFuncTest.java| 30 +++--
 .../hadoop/gateway/GatewaySampleFuncTest.java   | 26 ++-
 .../hadoop/gateway/GatewaySslFuncTest.java  | 28 ++--
 .../apache/hadoop/gateway/Knox242FuncTest.java  | 45 ++--
 .../gateway/KnoxCliLdapFuncTestNegative.java| 29 +++--
 .../gateway/KnoxCliLdapFuncTestPositive.java| 29 +++--
 .../hadoop/gateway/KnoxCliSysBindTest.java  | 29 +++--
 17 files changed, 111 insertions(+), 382 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/6657f2fd/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
--
diff --git 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
index bcbeeea..3135123 100644
--- 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
+++ 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
@@ -95,7 +95,7 @@ public class GatewayTestDriver {
 Path path = FileSystems.getDefault().getPath(basedir, 
"/src/test/resources/users.ldif");
 return setupLdap( port, path.toFile() );
   }
-  
+
   public int setupLdap( int port, File ldifConfig ) throws Exception {
 ldapTransport = new TcpTransport( port );
 ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", 
ldifConfig, ldapTransport );
@@ -169,13 +169,17 @@ public class GatewayTestDriver {
   }
 
   public void cleanup() throws Exception {
-gateway.stop();
-FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) );
-FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) );
-FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) );
-FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) );
-FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) );
-FileUtils.deleteQuietly( new File( config.getGatewayServicesDir() ) );
+if ( gateway != null ) {
+  gateway.stop();
+}
+if ( config != null ) {
+  FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) );
+  FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) );
+  FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) );
+  FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) );
+  FileUtils.deleteQuietly( new File( config.getGatewayDataDir() ) );
+  FileUtils.deleteQuietly( new File( config.getGatewayServicesDir() ) );
+}
 
 for( Service service : services.values() ) {
   service.server.stop();

http://git-wip-us.apache.org/repos/asf/knox/blob/6657f2fd/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
index 8c73b57..ea4c779 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
@@ -19,9 +19,7 @@ package org.apache.hadoop.gateway;
 
 import com.mycila.xmltool.XMLDoc;
 import com.mycila.xmltool.XMLTag;
-import 

[21/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
new file mode 100644
index 000..48e8282
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/spi/UrlRewriteStreamFilter.java
@@ -0,0 +1,43 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.spi;
+
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.knox.gateway.util.urltemplate.Resolver;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+// The rewriter will try to find either a stream or reader createFilter for 
the mime/type and name.
+public interface UrlRewriteStreamFilter {
+
+  String[] getTypes();
+
+  String[] getNames();
+
+  InputStream filter(
+  InputStream stream,
+  String encoding,
+  UrlRewriter rewriter,
+  Resolver resolver,
+  UrlRewriter.Direction direction,
+  UrlRewriteFilterContentDescriptor config )
+  throws IOException;
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
--
diff --git 
a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
 
b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
deleted file mode 100644
index b17abbb..000
--- 
a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
+++ /dev/null
@@ -1,19 +0,0 @@
-##
-# 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.
-##
-
-org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteDeploymentContributor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
--
diff --git 
a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
 
b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
deleted file mode 100644
index 7a086ca..000
--- 
a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
+++ /dev/null
@@ -1,21 +0,0 @@
-##
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more 

[39/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-switchcase/src/test/java/org/apache/hadoop/gateway/identityasserter/switchcase/SwitchCaseIdentityAssertionFilterTest.java
--
diff --git 
a/gateway-provider-identity-assertion-switchcase/src/test/java/org/apache/hadoop/gateway/identityasserter/switchcase/SwitchCaseIdentityAssertionFilterTest.java
 
b/gateway-provider-identity-assertion-switchcase/src/test/java/org/apache/hadoop/gateway/identityasserter/switchcase/SwitchCaseIdentityAssertionFilterTest.java
deleted file mode 100644
index 8637f62..000
--- 
a/gateway-provider-identity-assertion-switchcase/src/test/java/org/apache/hadoop/gateway/identityasserter/switchcase/SwitchCaseIdentityAssertionFilterTest.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.identityasserter.switchcase;
-
-import java.security.Principal;
-import javax.security.auth.Subject;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-
-import org.apache.hadoop.gateway.security.GroupPrincipal;
-import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
-
-public class SwitchCaseIdentityAssertionFilterTest {
-
-  @Test
-  public void testDefaultConfig() throws Exception {
-FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
-EasyMock.expect(config.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
-ServletContext context = EasyMock.createNiceMock(ServletContext.class);
-EasyMock.expect(config.getServletContext() ).andReturn( context 
).anyTimes();
-EasyMock.expect(context.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
-EasyMock.replay( config );
-EasyMock.replay( context );
-
-SwitchCaseIdentityAssertionFilter filter = new 
SwitchCaseIdentityAssertionFilter();
-
-Subject subject = new Subject();
-subject.getPrincipals().add( new PrimaryPrincipal( "mem...@us.apache.org" 
) );
-subject.getPrincipals().add( new GroupPrincipal( "users" ) );
-subject.getPrincipals().add( new GroupPrincipal( "Admin" ) );
-
-filter.init(config);
-String actual = filter.mapUserPrincipal(((Principal) 
subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
-String[] groups = filter.mapGroupPrincipals(actual, subject);
-assertThat( actual, is( "mem...@us.apache.org" ) );
-assertThat( groups, is( arrayContainingInAnyOrder( "admin", "users" ) ) );
-
-  }
-
-  @Test
-  public void testUpperPrincipalAndGroups() throws Exception {
-FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
-EasyMock.expect( config.getInitParameter( "principal.case" ) ).andReturn( 
"Upper" ).anyTimes();
-EasyMock.expect( config.getInitParameter( "group.principal.case" ) 
).andReturn( "Upper" ).anyTimes();
-EasyMock.expect(config.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
-ServletContext context = EasyMock.createNiceMock(ServletContext.class);
-EasyMock.expect(config.getServletContext() ).andReturn( context 
).anyTimes();
-EasyMock.expect(context.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
-EasyMock.replay( config );
-EasyMock.replay( context );
-
-SwitchCaseIdentityAssertionFilter filter = new 
SwitchCaseIdentityAssertionFilter();
-
-Subject subject = new Subject();
-subject.getPrincipals().add( new PrimaryPrincipal( "mem...@us.apache.org" 
) );
-subject.getPrincipals().add( new GroupPrincipal( "users" ) );
-subject.getPrincipals().add( new GroupPrincipal( "Admin" ) );
-
-filter.init(config);
-String actual = filter.mapUserPrincipal(((Principal) 
subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
-String[] groups = filter.mapGroupPrincipals(actual, subject);
-

[63/64] knox git commit: KNOX-998 - Some more refactoring, making sure all the Unit Tests run and build passes !

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
index ab4ab2b..c6135ae 100644
--- 
a/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
@@ -87,6 +87,6 @@
 
 
 
-
+
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/atlas-api/0.8.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/atlas-api/0.8.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/atlas-api/0.8.0/service.xml
index 0711dea..3ae7b24 100644
--- 
a/gateway-service-definitions/src/main/resources/services/atlas-api/0.8.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/atlas-api/0.8.0/service.xml
@@ -28,5 +28,5 @@
 
 
 
-
+
 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/atlas/0.8.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/atlas/0.8.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/atlas/0.8.0/service.xml
index ec1376c..6d99f30 100644
--- 
a/gateway-service-definitions/src/main/resources/services/atlas/0.8.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/atlas/0.8.0/service.xml
@@ -46,6 +46,6 @@
 
 
 
-
+
 
 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
index 181b536..e4e2926 100644
--- 
a/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/hbase/0.98.0/service.xml
@@ -29,7 +29,7 @@
 
 
 
-
+
 
 /hbase/version
 /hbase/version/cluster

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/hbaseui/1.1.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/hbaseui/1.1.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/hbaseui/1.1.0/service.xml
index 7a7de1e..09e78ea 100644
--- 
a/gateway-service-definitions/src/main/resources/services/hbaseui/1.1.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/hbaseui/1.1.0/service.xml
@@ -65,5 +65,5 @@
 
 
 
-
+
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/service.xml
index f33aab6..ac075eb 100644
--- 
a/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/hdfsui/2.7.0/service.xml
@@ -35,5 +35,5 @@
 
 
 
-
+
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
 
b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
index 3ea5b20..26875ff 100644
--- 
a/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/hive/0.13.0/service.xml
@@ -18,5 +18,5 @@
 
 
 
-
+
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2e6713b6/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
 

[40/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-pseudo/src/test/java/org/apache/knox/gateway/identityasserter/filter/DefaultIdentityAssertionFilterTest.java
--
diff --git 
a/gateway-provider-identity-assertion-pseudo/src/test/java/org/apache/knox/gateway/identityasserter/filter/DefaultIdentityAssertionFilterTest.java
 
b/gateway-provider-identity-assertion-pseudo/src/test/java/org/apache/knox/gateway/identityasserter/filter/DefaultIdentityAssertionFilterTest.java
new file mode 100644
index 000..adfc95d
--- /dev/null
+++ 
b/gateway-provider-identity-assertion-pseudo/src/test/java/org/apache/knox/gateway/identityasserter/filter/DefaultIdentityAssertionFilterTest.java
@@ -0,0 +1,173 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.identityasserter.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.knox.gateway.security.GroupPrincipal;
+import org.apache.knox.gateway.security.PrimaryPrincipal;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class DefaultIdentityAssertionFilterTest {
+
+  @Test
+  public void testInitParameters() throws Exception {
+FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
+EasyMock.expect(config.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
+ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+EasyMock.expect(config.getServletContext() ).andReturn( context 
).anyTimes();
+EasyMock.expect(context.getInitParameter("principal.mapping") ).andReturn( 
"" ).anyTimes();
+EasyMock.replay( config );
+EasyMock.replay( context );
+
+IdentityAsserterFilter filter = new IdentityAsserterFilter();
+Subject subject = new Subject();
+
+subject.getPrincipals().add(new PrimaryPrincipal("lmccay"));
+subject.getPrincipals().add(new GroupPrincipal("users"));
+subject.getPrincipals().add(new GroupPrincipal("admin"));
+
+filter.init(config);
+String username = filter.mapUserPrincipal(((Principal) 
subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
+String[] groups = filter.mapGroupPrincipals(username, subject);
+assertEquals("lmccay", username);
+assertNull(groups); // means for the caller to use the existing subject 
groups
+
+config = EasyMock.createNiceMock( FilterConfig.class );
+EasyMock.expect(config.getInitParameter("principal.mapping") ).andReturn( 
"lmccay,kminder=hdfs;newuser=mapred" ).anyTimes();
+EasyMock.expect(config.getInitParameter("group.principal.mapping") 
).andReturn( "kminder=group1;lmccay=mrgroup,mrducks" ).anyTimes();
+context = EasyMock.createNiceMock(ServletContext.class);
+EasyMock.expect(config.getServletContext() ).andReturn( context 
).anyTimes();
+EasyMock.replay( config );
+filter.init(config);
+username = filter.mapUserPrincipal(((Principal) 
subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
+String[] mappedGroups = filter.mapGroupPrincipals(((Principal) 
subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName(), subject);
+assertEquals("hdfs", username);
+assertTrue("mrgroup not found in groups: " + mappedGroups, 
groupFoundIn("mrgroup", mappedGroups));
+assertTrue("mrducks not found in groups: " + mappedGroups, 
groupFoundIn("mrducks", mappedGroups));
+assertFalse("group1 WAS found in groups: " + mappedGroups, 
groupFoundIn("group1", mappedGroups));
+
+subject = new Subject();
+
+subject.getPrincipals().add(new PrimaryPrincipal("kminder"));
+subject.getPrincipals().add(new GroupPrincipal("users"));
+subject.getPrincipals().add(new GroupPrincipal("admin"));
+
+config = EasyMock.createNiceMock( FilterConfig.class );
+

[09/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
--
diff --git 
a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
 
b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
new file mode 100644
index 000..a87c8d0
--- /dev/null
+++ 
b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
@@ -0,0 +1,215 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.pac4j.filter;
+
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+import org.apache.knox.gateway.pac4j.Pac4jMessages;
+import org.apache.knox.gateway.pac4j.session.KnoxSessionStore;
+import org.apache.knox.gateway.services.GatewayServices;
+import org.apache.knox.gateway.services.security.KeystoreService;
+import org.apache.knox.gateway.services.security.MasterService;
+import org.apache.knox.gateway.services.security.AliasService;
+import org.apache.knox.gateway.services.security.AliasServiceException;
+import org.apache.knox.gateway.services.security.CryptoService;
+import org.pac4j.config.client.PropertiesConfigFactory;
+import org.pac4j.core.client.Client;
+import org.pac4j.core.config.Config;
+import org.pac4j.core.config.ConfigSingleton;
+import org.pac4j.core.context.J2EContext;
+import org.pac4j.core.context.Pac4jConstants;
+import org.pac4j.core.util.CommonHelper;
+import org.pac4j.http.client.indirect.IndirectBasicAuthClient;
+import 
org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
+import org.pac4j.j2e.filter.CallbackFilter;
+import org.pac4j.j2e.filter.RequiresAuthenticationFilter;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This is the main filter for the pac4j provider. The pac4j provider 
module heavily relies on the j2e-pac4j library 
(https://github.com/pac4j/j2e-pac4j).
+ * This filter dispatches the HTTP calls between the j2e-pac4j filters:
+ * 
+ * to the {@link CallbackFilter} if the client_name 
parameter exists: it finishes the authentication process
+ * to the {@link RequiresAuthenticationFilter} otherwise: it starts 
the authentication process (redirection to the identity provider) if the user 
is not authenticated
+ * 
+ * It uses the {@link KnoxSessionStore} to manage session data. The 
generated cookies are defined on a domain name
+ * which can be configured via the domain suffix parameter: 
pac4j.cookie.domain.suffix.
+ * The callback url must be defined to the current protected url (KnoxSSO 
service for example) via the parameter: pac4j.callbackUrl.
+ *
+ * @since 0.8.0
+ */
+public class Pac4jDispatcherFilter implements Filter {
+
+  private static Pac4jMessages log = MessagesFactory.get(Pac4jMessages.class);
+
+  public static final String TEST_BASIC_AUTH = "testBasicAuth";
+
+  public static final String PAC4J_CALLBACK_URL = "pac4j.callbackUrl";
+
+  public static final String PAC4J_CALLBACK_PARAMETER = "pac4jCallback";
+
+  private static final String PAC4J_COOKIE_DOMAIN_SUFFIX_PARAM = 
"pac4j.cookie.domain.suffix";
+
+  private CallbackFilter callbackFilter;
+
+  private RequiresAuthenticationFilter requiresAuthenticationFilter;
+  private MasterService masterService = null;
+  private KeystoreService keystoreService = null;
+  private AliasService aliasService = null;
+
+  @Override
+  public void init( FilterConfig filterConfig ) throws ServletException {
+// JWT service
+final ServletContext context = filterConfig.getServletContext();
+CryptoService cryptoService = null;
+String clusterName = null;
+if (context != null) {
+  GatewayServices services = (GatewayServices) 
context.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
+  clusterName = (String) 

[17/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest.java
new file mode 100644
index 000..f1d9687
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest.java
@@ -0,0 +1,253 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.api;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+import org.xmlmatchers.transform.XmlConverters;
+
+import javax.xml.transform.Source;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.xmlmatchers.XmlMatchers.hasXPath;
+
+public class UrlRewriteRulesDescriptorFactoryTest {
+
+  @Test
+  public void testCreate() throws Exception {
+UrlRewriteRulesDescriptor descriptor = 
UrlRewriteRulesDescriptorFactory.create();
+assertThat( descriptor, notNullValue() );
+assertThat( descriptor.getRules(), notNullValue() );
+assertThat( descriptor.getRules().isEmpty(), is( true ) );
+
+UrlRewriteRuleDescriptor rule = descriptor.newRule();
+assertThat( rule, notNullValue() );
+assertThat( descriptor.getRules().isEmpty(), is( true ) );
+rule.name( "first" );
+descriptor.addRule( rule );
+assertThat( descriptor.getRules().size(), is( 1 ) );
+assertThat( descriptor.getRule( "first" ), sameInstance( rule ) );
+
+rule = descriptor.addRule( "second" );
+assertThat( descriptor.getRules().size(), is( 2 ) );
+  }
+
+  private static URL getTestResourceUrl( String name ) throws 
FileNotFoundException {
+name = UrlRewriteRulesDescriptorFactoryTest.class.getName().replaceAll( 
"\\.", "/" ) + "/" + name;
+URL url = ClassLoader.getSystemResource( name );
+if( url == null ) {
+  throw new FileNotFoundException( name );
+}
+return url;
+  }
+
+  private static InputStream getTestResourceStream( String name ) throws 
IOException {
+URL url = getTestResourceUrl( name );
+InputStream stream = url.openStream();
+return stream;
+  }
+
+  private static Reader getTestResourceReader( String name, String charset ) 
throws IOException {
+return new InputStreamReader( getTestResourceStream( name ), charset );
+  }
+
+  @Test
+  public void testLoadMissingFile() throws IOException {
+try {
+  UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( 
"missing.xml", "UTF-8" ) );
+  fail( "Should have thrown a FileNotFoundException." );
+} catch ( FileNotFoundException e ) {
+  assertThat( e.getMessage(), containsString( "missing.xml" ) );
+}
+  }
+
+  @Test
+  public void testLoadEmptyFile() throws IOException {
+Logger logger = org.apache.log4j.LogManager.getLogger( 
"org.apache.commons.digester3.Digester" );
+Level level = logger.getLevel();
+try {
+  logger.setLevel( org.apache.log4j.Level.OFF );
+  UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( 
"empty.xml", "UTF-8" ) );
+  fail( "Should have thrown an IOException." );
+} catch ( IOException e ) {
+  // Expected.
+} catch ( Throwable t ) {
+  fail( "Should have thrown an 

[48/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-demo-ldap/src/main/java/org/apache/knox/gateway/security/ldap/SimpleLdapDirectoryServer.java
--
diff --git 
a/gateway-demo-ldap/src/main/java/org/apache/knox/gateway/security/ldap/SimpleLdapDirectoryServer.java
 
b/gateway-demo-ldap/src/main/java/org/apache/knox/gateway/security/ldap/SimpleLdapDirectoryServer.java
new file mode 100644
index 000..9f59e9b
--- /dev/null
+++ 
b/gateway-demo-ldap/src/main/java/org/apache/knox/gateway/security/ldap/SimpleLdapDirectoryServer.java
@@ -0,0 +1,124 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.security.ldap;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.api.ldap.model.entry.DefaultModification;
+import org.apache.directory.api.ldap.model.entry.ModificationOperation;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.factory.DirectoryServiceFactory;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.server.protocol.shared.transport.Transport;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.ServerSocket;
+import java.util.UUID;
+
+public class SimpleLdapDirectoryServer {
+
+  private DirectoryServiceFactory factory;
+
+  private DirectoryService service;
+
+  private LdapServer server;
+
+  public SimpleLdapDirectoryServer( String rootDn, File usersLdif, 
Transport... transports ) throws Exception {
+if( !usersLdif.exists() ) {
+  throw new FileNotFoundException( usersLdif.getAbsolutePath() );
+}
+
+factory = new SimpleDirectoryServiceFactory();
+factory.init( UUID.randomUUID().toString() );
+service = factory.getDirectoryService();
+
+enabledPosixSchema( service );
+
+Partition partition = factory.getPartitionFactory().createPartition(
+service.getSchemaManager(), service.getDnFactory(), "users", rootDn, 
500,
+service.getInstanceLayout().getInstanceDirectory() );
+service.addPartition( partition );
+
+CoreSession session = service.getAdminSession();
+LdifFileLoader lfl = new LdifFileLoader( session, usersLdif, null );
+lfl.execute();
+
+server = new LdapServer();
+server.setTransports( transports );
+server.setDirectoryService( service );
+  }
+
+  private static void enabledPosixSchema( DirectoryService service ) throws 
LdapException {
+service.getSchemaManager().getLoadedSchema( "nis" ).enable();
+service.getAdminSession().modify(
+new Dn( "cn=nis,ou=schema" ),
+new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, 
"m-disabled", "FALSE" ) );
+  }
+
+  public void start() throws Exception {
+service.startup();
+server.start();
+  }
+
+  public void stop( boolean clean ) throws Exception {
+server.stop();
+service.shutdown();
+if( clean ) {
+  FileUtils.deleteDirectory( 
service.getInstanceLayout().getInstanceDirectory() );
+}
+  }
+
+  public static void main( String[] args ) throws Exception {
+PropertyConfigurator.configure( System.getProperty( "log4j.configuration" 
) );
+
+SimpleLdapDirectoryServer ldap;
+
+File file;
+if ( args.length < 1 ) {
+  file = new File( "conf/users.ldif" );
+} else {
+  File dir = new File( args[0] );
+  if( !dir.exists() || !dir.isDirectory() ) {
+throw new FileNotFoundException( dir.getAbsolutePath() );
+  }
+  file = new File( dir, "users.ldif" );
+}
+
+if( !file.exists() || !file.canRead() ) {
+  throw new FileNotFoundException( file.getAbsolutePath() );
+}
+
+int port = 33389;
+
+// Make sure the port is free.
+  

[30/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessor.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessor.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessor.java
deleted file mode 100644
index c0a5639..000
--- 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessor.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.api;
-
-import org.apache.hadoop.gateway.filter.rewrite.ext.ScopedMatcher;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
-import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteContextImpl;
-import 
org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteFunctionProcessorFactory;
-import 
org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder;
-import 
org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteStepProcessorHolder;
-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.UrlRewriteStepStatus;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.util.urltemplate.Matcher;
-import org.apache.hadoop.gateway.util.urltemplate.Resolver;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter.Direction.IN;
-import static 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter.Direction.OUT;
-
-public class UrlRewriteProcessor implements UrlRewriter {
-
-  private static final UrlRewriteMessages LOG = MessagesFactory.get( 
UrlRewriteMessages.class );
-
-  UrlRewriteEnvironment environment;
-  UrlRewriteRulesDescriptor descriptor;
-  Map rules = new HashMap<>();
-  ScopedMatcher inbound = new ScopedMatcher();
-  ScopedMatcher outbound = new ScopedMatcher();
-  Map functions = new HashMap<>();
-
-  public UrlRewriteProcessor() {
-  }
-
-  // Convert the descriptor into processors.
-  public void initialize( UrlRewriteEnvironment environment, 
UrlRewriteRulesDescriptor descriptor ) {
-this.environment = environment;
-this.descriptor = descriptor;
-initializeFunctions( descriptor );
-initializeRules( descriptor );
-  }
-
-  public UrlRewriteRulesDescriptor getConfig() {
-return descriptor;
-  }
-
-  @SuppressWarnings("unchecked")
-  private void initializeFunctions( UrlRewriteRulesDescriptor rules ) {
-for( String name : UrlRewriteFunctionDescriptorFactory.getNames() ) {
-  try {
-UrlRewriteFunctionDescriptor descriptor = rules.getFunction( name );
-UrlRewriteFunctionProcessor processor = 
UrlRewriteFunctionProcessorFactory.create( name, descriptor );
-processor.initialize( environment, descriptor );
-functions.put( name, processor );
-  } catch( Exception e ) {
-// Ignore it and it won't be available as a function.
-LOG.failedToInitializeRewriteFunctions( e );
-  }
-}
-  }
-
-  private void initializeRules( UrlRewriteRulesDescriptor descriptor ) {
-for( UrlRewriteRuleDescriptor ruleDescriptor : descriptor.getRules() ) {
-  try {
-UrlRewriteRuleProcessorHolder ruleProcessor = new 
UrlRewriteRuleProcessorHolder();
-ruleProcessor.initialize( environment, ruleDescriptor );
-if( !rules.containsKey( ruleDescriptor.name() ) ) {
-  rules.put( ruleDescriptor.name(), ruleProcessor );
-}
-Template template = ruleDescriptor.template();
-if( template != null ) {
-  EnumSet directions = ruleDescriptor.directions();
-  if( directions == 

[54/64] knox git commit: KNOX-978 - Add a test for the SOLR REST API

2017-09-01 Thread more
KNOX-978 - Add a test for the SOLR REST API


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/d2f0fc0e
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/d2f0fc0e
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/d2f0fc0e

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: d2f0fc0e5ec07d0e8d4633ce8bc0f0723a34efbe
Parents: ac532bd
Author: Colm O hEigeartaigh 
Authored: Tue Jun 27 11:13:56 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Tue Aug 29 14:50:24 2017 +0100

--
 .../hadoop/gateway/GatewayBasicFuncTest.java| 39 +++-
 .../solr/query_response.xml | 20 ++
 2 files changed, 58 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/d2f0fc0e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 2cc1573..d8f1352 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -92,6 +92,7 @@ import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.text.IsEmptyString.isEmptyString;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 import static org.xmlmatchers.XmlMatchers.isEquivalentTo;
 import static org.xmlmatchers.transform.XmlConverters.the;
 import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
@@ -161,6 +162,7 @@ public class GatewayBasicFuncTest {
 driver.setupService( "FALCON", "http://; + TEST_HOST + ":15000", 
"/cluster/falcon", USE_MOCK_SERVICES );
 driver.setupService( "STORM", "http://; + TEST_HOST + ":8477", 
"/cluster/storm", USE_MOCK_SERVICES );
 driver.setupService( "STORM-LOGVIEWER", "http://; + TEST_HOST + ":8477", 
"/cluster/storm", USE_MOCK_SERVICES );
+driver.setupService( "SOLR", "http://; + TEST_HOST + ":8983", 
"/cluster/solr", USE_MOCK_SERVICES );
 driver.setupGateway( config, "cluster", createTopology(), USE_GATEWAY );
 LOG_EXIT();
   }
@@ -263,6 +265,9 @@ public class GatewayBasicFuncTest {
 .addTag("role").addText("STORM-LOGVIEWER")
 
.addTag("url").addText(driver.getRealUrl("STORM-LOGVIEWER")).gotoParent()
 .addTag("service")
+.addTag("role").addText("SOLR")
+.addTag("url").addText(driver.getRealUrl("SOLR")).gotoParent()
+.addTag("service")
 .addTag("role").addText("SERVICE-TEST")
 .gotoRoot();
 // System.out.println( "GATEWAY=" + xml.toString() );
@@ -3703,6 +3708,38 @@ public class GatewayBasicFuncTest {
 LOG_EXIT();
   }
 
+  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testSolrRESTAPI() throws Exception {
+LOG_ENTER();
+String resourceName = "solr/query_response.xml";
+String username = "hdfs";
+String password = "hdfs-password";
+
+String gatewayPath = driver.getUrl( "SOLR" ) + 
"/gettingstarted/select?q=author_s:William+Shakespeare";
+driver.getMock("SOLR")
+.expect()
+.method("GET")
+.pathInfo("/gettingstarted/select")
+.queryParam("q", "author_s:William+Shakespeare")
+.respond()
+.status(HttpStatus.SC_OK)
+.content(driver.getResourceBytes(resourceName))
+.contentType(ContentType.XML.toString());
+
+Response response = given()
+.auth().preemptive().basic(username, password)
+.header("X-XSRF-Header", "jksdhfkhdsf")
+.header("Accept", ContentType.XML.toString())
+.expect()
+.statusCode(HttpStatus.SC_OK)
+.contentType( ContentType.XML.toString() )
+.when().get( gatewayPath );
+
+assertTrue(response.getBody().asString().contains("The Merchant of 
Venice"));
+
+driver.assertComplete();
+LOG_EXIT();
+  }
 
   void setupResource(String serviceRole, String path){
 driver.getMock(serviceRole)
@@ -3750,7 +3787,7 @@ public class GatewayBasicFuncTest {
   System.out.println(e.getMessage());
 }
   }
-  
+
   private String createFileNN( String user, String password, String file, 
String permsOctal, int status ) throws IOException {
 if( status == HttpStatus.SC_TEMPORARY_REDIRECT ) {
   driver.getMock( "WEBHDFS" )

http://git-wip-us.apache.org/repos/asf/knox/blob/d2f0fc0e/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayBasicFuncTest/solr/query_response.xml

[03/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
--
diff --git 
a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
 
b/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
deleted file mode 100644
index 1ab8e22..000
--- 
a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/TestFilterChain.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
-import java.util.Stack;
-
-public class TestFilterChain extends Stack implements FilterChain {
-  @Override
-  public void doFilter( ServletRequest request, ServletResponse response ) 
throws IOException, ServletException {
-if( !isEmpty() ) pop().doFilter( request, response, this );
-  }
-}
-
-

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
--
diff --git 
a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
 
b/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
deleted file mode 100644
index d1d1a99..000
--- 
a/gateway-server-xforwarded-filter/src/test/java/org/apache/hadoop/gateway/filter/XForwardHeaderFilterTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter;
-
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class XForwardHeaderFilterTest {
-
-  public static class AssertXForwardedHeaders extends TestFilterAdapter {
-@Override
-public void doFilter( HttpServletRequest request, HttpServletResponse 
response, FilterChain chain ) throws IOException, ServletException {
-  assertThat( request.getHeader( "X-Forwarded-For" ), is( "127.0.0.1" ) );
-  assertThat( request.getHeader( "X-Forwarded-Proto" ), is( "http" ) );
-  assertThat( request.getHeader( "X-Forwarded-Port" ), is( "" ) );
-  assertThat( request.getHeader( "X-Forwarded-Host" ), is( 
"localhost:" ) );
-  assertThat( request.getHeader( "X-Forwarded-Server" ), is( "localhost" ) 
);
-  assertThat( request.getHeader( "X-Forwarded-Context" ), is( "/context" ) 
);
-}
-  }
-
-  @Test
-  public void testXForwardHeaders() throws ServletException, IOException {
-HttpServletRequest request = EasyMock.createNiceMock( 
HttpServletRequest.class );
-EasyMock.expect( request.getRemoteAddr() ).andReturn( "127.0.0.1" 
).anyTimes();
-EasyMock.expect( 

[18/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
deleted file mode 100644
index 82948a3..000
--- 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
+++ /dev/null
@@ -1,1003 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.impl.xml;
-
-import org.apache.commons.digester3.Digester;
-import org.apache.commons.digester3.ExtendedBaseRules;
-import org.apache.commons.digester3.binder.DigesterLoader;
-import org.apache.commons.io.IOUtils;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepFlow;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptorExt;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptorExt;
-import 
org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteActionDescriptorBase;
-import org.apache.hadoop.test.TestUtils;
-import org.hamcrest.Matchers;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.SAXException;
-import org.xmlmatchers.namespace.SimpleNamespaceContext;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.XMLStreamException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.fail;
-import static org.xmlmatchers.XmlMatchers.hasXPath;
-import static org.xmlmatchers.transform.XmlConverters.the;
-
-public class XmlFilterReaderTest {
-
-  public static class NoopXmlFilterReader extends XmlFilterReader {
-public NoopXmlFilterReader( Reader reader, 
UrlRewriteFilterContentDescriptor config ) throws IOException, 
ParserConfigurationException, XMLStreamException {
-  super( reader, config );
-}
-
-@Override
-protected String filterText( QName elementName, String text, String 
ruleName ) {
-  return text;
-}
-
-@Override
-protected String filterAttribute( QName elementName, QName attributeName, 
String attributeValue, String ruleName ) {
-  return attributeValue;
-}
-  }
-
-  public static class MapXmlFilterReader extends XmlFilterReader {
-

[32/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
--
diff --git 
a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
 
b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
deleted file mode 100644
index c42233a..000
--- 
a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.securequery;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepProcessor;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepStatus;
-import org.apache.hadoop.gateway.util.urltemplate.Builder;
-import org.apache.hadoop.gateway.util.urltemplate.Query;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-public class SecureQueryDecodeProcessor implements 
UrlRewriteStepProcessor {
-
-  private static final String ENCODED_PARAMETER_NAME = "_";
-
-  @Override
-  public String getType() {
-return SecureQueryDecodeDescriptor.STEP_NAME;
-  }
-
-  @Override
-  public void initialize( UrlRewriteEnvironment environment, 
SecureQueryDecodeDescriptor descriptor ) throws Exception {
-  }
-
-  @Override
-  public UrlRewriteStepStatus process( UrlRewriteContext context ) throws 
Exception {
-//TODO: Need some way to get a reference to the keystore service and the 
encryption key in particular.
-Template currUrl = context.getCurrentUrl();
-Builder newUrl = new Builder( currUrl );
-Map map = newUrl.getQuery();
-Query query = map.remove( ENCODED_PARAMETER_NAME );
-if( query != null ) {
-  String value = query.getFirstValue().getPattern();
-  value = decode( value );
-  StringTokenizer outerParser = new StringTokenizer( value, "&" );
-  while( outerParser.hasMoreTokens() ) {
-String pair = outerParser.nextToken();
-StringTokenizer innerParser = new StringTokenizer( pair, "=" );
-if( innerParser.hasMoreTokens() ) {
-  String paramName = innerParser.nextToken();
-  if( innerParser.hasMoreTokens() ) {
-String paramValue = innerParser.nextToken();
-// Need to take out any existing query param.
-// If we don't then someone could override something in the 
encoded param.
-map.remove( paramName );
-newUrl.addQuery( paramName, "", paramValue, true );
-  } else {
-newUrl.addQuery( paramName, "", null, true );
-  }
-}
-  }
-  context.setCurrentUrl( newUrl.build() );
-}
-return UrlRewriteStepStatus.SUCCESS;
-  }
-
-  @Override
-  public void destroy() {
-  }
-
-  private static String decode( String string ) throws 
UnsupportedEncodingException {
-return new String( Base64.decodeBase64( string ), "UTF-8" );
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptDescriptor.java
--
diff --git 
a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptDescriptor.java
 
b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptDescriptor.java
deleted file mode 100644
index 8db2070..000
--- 

[29/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/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
deleted file mode 100644
index be1eca5..000
--- 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessor.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.FrontendFunctionDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteResources;
-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;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class FrontendFunctionProcessor implements 
UrlRewriteFunctionProcessor {
-
-  private static UrlRewriteResources RES = ResourcesFactory.get( 
UrlRewriteResources.class );
-
-  private Map resolvers;
-
-  @Override
-  public String name() {
-return FrontendFunctionDescriptor.FUNCTION_NAME;
-  }
-
-  @Override
-  public void initialize( UrlRewriteEnvironment environment, 
FrontendFunctionDescriptor descriptor ) throws Exception {
-if( environment == null ) {
-  throw new IllegalArgumentException( "environment==null" );
-}
-URI frontend = environment.getAttribute( 
FrontendFunctionDescriptor.FRONTEND_URI_ATTRIBUTE );
-resolvers = new HashMap<>();
-if( frontend == null ) {
-  resolvers.put( "url", new ParamResolver( "gateway.url" ) );
-  resolvers.put( "addr", new ParamResolver( "gateway.addr" ) );
-  resolvers.put( "scheme", new ParamResolver( "gateway.scheme" ) );
-  resolvers.put( "host", new ParamResolver( "gateway.host" ) );
-  resolvers.put( "port", new ParamResolver( "gateway.port" ) );
-  resolvers.put( "path", new ParamResolver( "gateway.path" ) );
-} else {
-  resolvers.put( "url", new FixedResolver( frontend.toString() ) );
-  resolvers.put( "addr", new FixedResolver( frontend.getHost() + ":" + 
frontend.getPort() ) );
-  resolvers.put( "scheme", new FixedResolver( frontend.getScheme() ) );
-  resolvers.put( "host", new FixedResolver( frontend.getHost() ) );
-  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" ) );
-  }
-
-  @Override
-  public void destroy() throws Exception {
-resolvers.clear();
-  }
-
-  @Override
-  public List resolve( UrlRewriteContext context, List 
parameters ) throws Exception {
-String parameter = "url";
-if( parameters != null && parameters.size() > 0 ) {
-  String first = parameters.get( 0 );
-  if( first != null ) {
-parameter = first;
-  }
-}
-parameter = parameter.trim().toLowerCase();
-UrlRewriteResolver resolver = resolvers.get( parameter );
-if( resolver == null ) {
-  throw new IllegalArgumentException( 
RES.invalidFrontendFunctionParameter( parameter ) );
-}
-List results = resolver.resolve( context, parameters );
-return results;
-  }
-
-  private static class ParamResolver implements UrlRewriteResolver {
-
-private String paramName;
-
-   

[31/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDeploymentContributorTest.java
--
diff --git 
a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDeploymentContributorTest.java
 
b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDeploymentContributorTest.java
deleted file mode 100644
index f56c398..000
--- 
a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDeploymentContributorTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.securequery;
-
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.deploy.DeploymentContext;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.services.GatewayServices;
-import org.apache.hadoop.gateway.services.ServiceLifecycleException;
-import org.apache.hadoop.gateway.services.security.AliasService;
-import org.apache.hadoop.gateway.services.security.CryptoService;
-import org.apache.hadoop.gateway.services.security.impl.DefaultCryptoService;
-import org.apache.hadoop.gateway.topology.Provider;
-import org.apache.hadoop.gateway.topology.Topology;
-import org.easymock.EasyMock;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class SecureQueryDeploymentContributorTest {
-
-  @Test
-  public void testDeployment() throws IOException {
-WebArchive webArchive = ShrinkWrap.create( WebArchive.class, 
"test-acrhive" );
-
-//UrlRewriteRulesDescriptorImpl rewriteRules = new 
UrlRewriteRulesDescriptorImpl();
-
-Map providerParams = new HashMap<>();
-//providerParams.put( "test-host-external", "test-host-internal" );
-Provider provider = new Provider();
-provider.setEnabled( true );
-provider.setName( "secure-query" );
-provider.setParams(  providerParams );
-
-Topology topology = new Topology();
-topology.setName("Sample");
-
-DeploymentContext context = EasyMock.createNiceMock( 
DeploymentContext.class );
-//EasyMock.expect( context.getDescriptor( "rewrite" ) ).andReturn( 
rewriteRules ).anyTimes();
-EasyMock.expect( context.getWebArchive() ).andReturn( webArchive 
).anyTimes();
-EasyMock.expect( context.getTopology() ).andReturn( topology ).anyTimes();
-EasyMock.replay( context );
-
-AliasService as = EasyMock.createNiceMock( AliasService.class );
-CryptoService cryptoService = new DefaultCryptoService();
-((DefaultCryptoService)cryptoService).setAliasService(as);
-
-GatewayServices gatewayServices = EasyMock.createNiceMock( 
GatewayServices.class );
-EasyMock.expect( gatewayServices.getService( 
GatewayServices.CRYPTO_SERVICE ) ).andReturn( cryptoService ).anyTimes();
-
-UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock( 
UrlRewriteEnvironment.class );
-EasyMock.expect( encEnvironment.getAttribute( 
GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices 
).anyTimes();
-
-SecureQueryDeploymentContributor contributor = new 
SecureQueryDeploymentContributor();
-contributor.setAliasService(as);
-
-assertThat( contributor.getRole(), is( "secure-query" ) );
-assertThat( contributor.getName(), is( "default" ) );
-
-// Just make sure it doesn't blow up.
-contributor.contributeFilter( null, null, null, null, null );
-
-// Just make sure it doesn't blow up.
-contributor.initializeContribution( context );
-
-contributor.contributeProvider( context, provider );
-
-//HostmapFunctionDescriptor funcDesc = rewriteRules.getFunction( "hostmap" 
);
-//assertThat( 

[24/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
new file mode 100644
index 000..bc1dd91
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterGroupDescriptorBase.java
@@ -0,0 +1,52 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl;
+
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UrlRewriteFilterGroupDescriptorBase
+extends UrlRewriteFilterSelectorDescriptorBase
+implements UrlRewriteFilterGroupDescriptor {
+
+  private List selectors = new 
ArrayList();
+
+  @Override
+  public List getSelectors() {
+return selectors;
+  }
+
+  @Override
+  public void addSelector( UrlRewriteFilterPathDescriptor selector ) {
+this.selectors.add( selector );
+  }
+
+  @Override
+  public UrlRewriteFilterApplyDescriptor addApply( String path, String rule ) {
+UrlRewriteFilterApplyDescriptor apply = new 
UrlRewriteFilterApplyDescriptorImpl();
+apply.path( path );
+apply.rule( rule );
+addSelector( apply );
+return apply;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
--
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
new file mode 100644
index 000..b512a8c
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterReader.java
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl;
+
+import java.util.regex.Pattern;
+
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor;
+
+
+public interface UrlRewriteFilterReader {
+
+  public String filterValueString( String name, String value, String rule );
+
+  public static class RegexCompiler implements 
UrlRewriteFilterPathDescriptor.Compiler {
+@Override
+public Pattern compile( String expression, Pattern compiled ) {
+  if( compiled != null ) {
+return compiled;
+  } else {
+return Pattern.compile( expression );
+  }
+}
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteFilterScopeDescriptorImpl.java
--
diff --git 

[52/64] knox git commit: KNOX-1003 - Fix the rewrite rules for Zeppelin 0.7.2 UI

2017-09-01 Thread more
KNOX-1003 - Fix the rewrite rules for Zeppelin 0.7.2 UI


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/bea3974a
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/bea3974a
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/bea3974a

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: bea3974a89bbe2dd83be26f3e94e2c9cea0bba31
Parents: 1159135
Author: Sandeep More 
Authored: Thu Aug 24 16:43:27 2017 -0400
Committer: Sandeep More 
Committed: Thu Aug 24 16:43:27 2017 -0400

--
 .../src/main/resources/services/zeppelinui/0.6.0/rewrite.xml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/bea3974a/gateway-service-definitions/src/main/resources/services/zeppelinui/0.6.0/rewrite.xml
--
diff --git 
a/gateway-service-definitions/src/main/resources/services/zeppelinui/0.6.0/rewrite.xml
 
b/gateway-service-definitions/src/main/resources/services/zeppelinui/0.6.0/rewrite.xml
index 7259aba..db251ad 100644
--- 
a/gateway-service-definitions/src/main/resources/services/zeppelinui/0.6.0/rewrite.xml
+++ 
b/gateway-service-definitions/src/main/resources/services/zeppelinui/0.6.0/rewrite.xml
@@ -119,7 +119,8 @@
   
 
   
-  
+
+  
 
   
   



[07/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java
--
diff --git 
a/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java
 
b/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java
new file mode 100644
index 000..13e023f
--- /dev/null
+++ 
b/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java
@@ -0,0 +1,142 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.preauth.filter;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.Principal;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+
+import javax.security.auth.Subject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.knox.gateway.security.PrimaryPrincipal;
+
+public class PreAuthFederationFilter implements Filter {
+  private static final String CUSTOM_HEADER_PARAM = "preauth.customHeader";
+  private List validators = null;
+  private FilterConfig filterConfig;
+  private String headerName = "SM_USER";
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+String customHeader = filterConfig.getInitParameter(CUSTOM_HEADER_PARAM);
+if (customHeader != null) {
+  headerName = customHeader;
+}
+this.filterConfig = filterConfig;
+validators = PreAuthService.getValidators(filterConfig);
+  }
+
+  @Override
+  public void doFilter(ServletRequest request, ServletResponse response,
+   FilterChain chain) throws IOException, ServletException 
{
+HttpServletRequest httpRequest = (HttpServletRequest) request;
+if (httpRequest.getHeader(headerName) != null) {
+  if (PreAuthService.validate(httpRequest, filterConfig, validators)) {
+// TODO: continue as subject
+chain.doFilter(request, response);
+  } else {
+// TODO: log preauthenticated SSO validation failure
+((HttpServletResponse) 
response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing Required 
Header for SSO Validation");
+  }
+} else {
+  ((HttpServletResponse) 
response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing Required 
Header for PreAuth SSO Federation");
+}
+  }
+
+  /* (non-Javadoc)
+   * @see javax.servlet.Filter#destroy()
+   */
+  @Override
+  public void destroy() {
+// TODO Auto-generated method stub
+
+  }
+
+  /**
+   * Recreate the current Subject based upon the provided mappedPrincipal
+   * and look for the groups that should be associated with the new Subject.
+   * Upon finding groups mapped to the principal - add them to the new Subject.
+   * @param mappedPrincipalName
+   * @throws ServletException
+   * @throws IOException
+   */
+  protected void continueChainAsPrincipal(final ServletRequest request, final 
ServletResponse response,
+  final FilterChain chain, String 
principal) throws IOException, ServletException {
+Subject subject = null;
+Principal primaryPrincipal = null;
+
+// do some check to ensure that the extracted identity matches any 
existing security context
+// if not, there is may be someone tampering with the request - consult 
config to determine
+// how we are to handle it
+
+// TODO: make sure that this makes sense with existing sessions or lack 
thereof
+Subject currentSubject = Subject.getSubject(AccessController.getContext());
+if (currentSubject != null) {
+  primaryPrincipal = (PrimaryPrincipal) 
currentSubject.getPrincipals(PrimaryPrincipal.class).toArray()[0];

[35/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
--
diff --git 
a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
 
b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
deleted file mode 100644
index 7da18c9..000
--- 
a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessorTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.svcregfunc.impl;
-
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import 
org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
-import org.apache.hadoop.gateway.ha.provider.HaProvider;
-import org.apache.hadoop.gateway.ha.provider.HaServletContextListener;
-import org.apache.hadoop.gateway.services.GatewayServices;
-import org.apache.hadoop.gateway.services.hostmap.HostMapper;
-import org.apache.hadoop.gateway.services.hostmap.HostMapperService;
-import org.apache.hadoop.gateway.services.registry.ServiceRegistry;
-import 
org.apache.hadoop.gateway.svcregfunc.api.ServiceMappedAddressFunctionDescriptor;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.fail;
-
-public class ServiceMappedAddressFunctionProcessorTest {
-
-  HostMapperService hms;
-  HostMapper hm;
-  ServiceRegistry reg;
-  GatewayServices svc;
-  UrlRewriteEnvironment env;
-  UrlRewriteContext ctx;
-  ServiceMappedAddressFunctionDescriptor desc;
-
-  @Before
-  public void setUp() {
-hm = EasyMock.createNiceMock( HostMapper.class );
-EasyMock.expect( hm.resolveInboundHostName( "test-host" ) ).andReturn( 
"test-internal-host" ).anyTimes();
-
-hms = EasyMock.createNiceMock( HostMapperService.class );
-EasyMock.expect( hms.getHostMapper( "test-cluster" ) ).andReturn( hm 
).anyTimes();
-
-reg = EasyMock.createNiceMock( ServiceRegistry.class );
-EasyMock.expect( reg.lookupServiceURL( "test-cluster", "test-service" ) 
).andReturn( "test-scheme://test-host:777/test-path" ).anyTimes();
-
-svc = EasyMock.createNiceMock( GatewayServices.class );
-EasyMock.expect( svc.getService( GatewayServices.SERVICE_REGISTRY_SERVICE 
) ).andReturn( reg ).anyTimes();
-EasyMock.expect( svc.getService( GatewayServices.HOST_MAPPING_SERVICE ) 
).andReturn( hms ).anyTimes();
-
-env = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
-EasyMock.expect( env.getAttribute( 
GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( svc ).anyTimes();
-EasyMock.expect( env.getAttribute( 
GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster" 
).anyTimes();
-
-ctx = EasyMock.createNiceMock( UrlRewriteContext.class );
-EasyMock.expect( ctx.getDirection() ).andReturn( UrlRewriter.Direction.IN 
).anyTimes();
-
-desc = EasyMock.createNiceMock( 
ServiceMappedAddressFunctionDescriptor.class );
-
- HaProvider haProvider = EasyMock.createNiceMock( HaProvider.class );
-
- 
EasyMock.expect(env.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
-
- 
EasyMock.expect(haProvider.isHaEnabled(EasyMock.anyObject(String.class))).andReturn(Boolean.FALSE).anyTimes();
-
- EasyMock.replay( hm, hms, reg, svc, env, desc, ctx, haProvider );
-  }
-
-  @Test
-  public void testServiceLoader() 

[38/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
--
diff --git 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
 
b/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
deleted file mode 100644
index eda74c1..000
--- 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ProviderDeploymentContributor
+++ /dev/null
@@ -1,19 +0,0 @@
-##
-# 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.
-##
-
-org.apache.hadoop.gateway.hostmap.impl.HostmapDeploymentContributor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
--
diff --git 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
 
b/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
deleted file mode 100644
index 3e80487..000
--- 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
+++ /dev/null
@@ -1,19 +0,0 @@
-##
-# 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.
-##
-
-org.apache.hadoop.gateway.hostmap.api.HostmapFunctionDescriptor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
--
diff --git 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
 
b/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
deleted file mode 100644
index 7c6619c..000
--- 
a/gateway-provider-rewrite-func-hostmap-static/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
+++ /dev/null
@@ -1,19 +0,0 @@
-##
-# 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
-# 

[57/64] knox git commit: KNOX-998 - Refactoring package after merge

2017-09-01 Thread more
KNOX-998 - Refactoring package after merge


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/a25f8a77
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/a25f8a77
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/a25f8a77

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: a25f8a77bc80b7314b2e7a7983a125592db759fe
Parents: a4ba9bb
Author: Sandeep More 
Authored: Tue Aug 29 10:37:00 2017 -0400
Committer: Sandeep More 
Committed: Tue Aug 29 10:37:00 2017 -0400

--
 .../services/metrics/impl/instr/InstrUtils.java | 54 
 1 file changed, 54 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/a25f8a77/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
--
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
new file mode 100644
index 000..9b6249f
--- /dev/null
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.services.metrics.impl.instr;
+
+import com.google.common.base.Strings;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class InstrUtils {
+
+//This regular expression pattern is used to parse the *first* two elements
+//of a path. For example, if the path is “/webhdfs/v1/d1/d2/d2/d4”, 
this pattern
+//can be used to get the first two ("/webhdfs/v1/"). The "?" in pattern
+//ensures not to be greedy in matching.
+private static Pattern p = Pattern.compile("/.*?/.*?/");
+
+/**
+ * This function parses the pathinfo provided  in any servlet context and
+ * returns the segment that is related to the resource.
+ * For example, if the path is "/webhdfs/v1/d1/d2/d2/d4". it returns 
"/webhdfs/v1"
+ *
+ * @param fullPath
+ * @return
+ */
+public static String getResourcePath(String fullPath) {
+String resourcePath = "";
+if (!Strings.isNullOrEmpty(fullPath)) {
+Matcher m = p.matcher(fullPath);
+if (m.find()) {
+resourcePath = m.group(0);
+} else {
+resourcePath = fullPath;
+}
+}
+return resourcePath;
+}
+
+}



[16/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteStepProcessorStateTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteStepProcessorStateTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteStepProcessorStateTest.java
new file mode 100644
index 000..bf64905
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteStepProcessorStateTest.java
@@ -0,0 +1,255 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl;
+
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepFlow;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor;
+import org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class UrlRewriteStepProcessorStateTest {
+
+  @Test
+  public void testEmpty() {
+List steps = new 
ArrayList();
+UrlRewriteStepProcessorState state = new UrlRewriteStepProcessorState( 
steps.iterator() );
+
+MatcherAssert
+.assertThat( state.status(), CoreMatchers.is( 
UrlRewriteStepStatus.SUCCESS ) );
+assertThat( state.hasNext(), is( false ) );
+assertThat( state.hasNextAction(), is( false ) );
+assertThat( state.hasNextCondition(), is( false ) );
+assertThat( state.nextAction( UrlRewriteStepStatus.SUCCESS ), nullValue() 
);
+assertThat( state.nextCondition( UrlRewriteStepStatus.SUCCESS ), 
nullValue() );
+  }
+
+  @Test
+  public void testNextAction() throws Exception {
+UrlRewriteStepProcessorHolder holder;
+List steps = new 
ArrayList();
+holder = new UrlRewriteStepProcessorHolder();
+holder.initialize( new FakeEnvironment(), new FakeActionDescriptor( "one" 
), new FakeActionProcessor( "one" ) );
+steps.add( holder );
+holder = new UrlRewriteStepProcessorHolder();
+holder.initialize( new FakeEnvironment(), new FakeActionDescriptor( "two" 
), new FakeActionProcessor( "two" ) );
+steps.add( holder );
+UrlRewriteStepProcessorState state = new UrlRewriteStepProcessorState( 
steps.iterator() );
+assertThat( state.hasNext(), is( true ) );
+assertThat( state.hasNextAction(), is( true ) );
+assertThat( state.hasNextCondition(), is( false ) );
+assertThat( state.nextCondition( UrlRewriteStepStatus.SUCCESS ), 
nullValue() );
+
+holder = state.nextAction( UrlRewriteStepStatus.SUCCESS );
+assertThat( ((FakeActionDescriptor)holder.getDescriptor()).name, is( "one" 
) );
+
+assertThat( state.hasNext(), is( true ) );
+assertThat( state.hasNextAction(), is( true ) );
+assertThat( state.hasNextCondition(), is( false ) );
+assertThat( state.nextCondition( UrlRewriteStepStatus.SUCCESS ), 
nullValue() );
+
+holder = state.nextAction( UrlRewriteStepStatus.SUCCESS );
+assertThat( ((FakeActionDescriptor)holder.getDescriptor()).name, is( "two" 
) );
+
+assertThat( state.hasNext(), is( false ) );
+assertThat( state.hasNextAction(), is( false ) );
+assertThat( state.hasNextCondition(), is( false ) );
+assertThat( state.nextAction( UrlRewriteStepStatus.SUCCESS ), nullValue() 
);
+assertThat( state.nextCondition( UrlRewriteStepStatus.SUCCESS ), 
nullValue() );
+  }
+
+  @Test
+  public void testNextCondition() throws Exception {
+

[44/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultHaProviderTest.java
--
diff --git 
a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultHaProviderTest.java
 
b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultHaProviderTest.java
deleted file mode 100644
index 87a63f4..000
--- 
a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultHaProviderTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.ha.provider.impl;
-
-import org.apache.hadoop.gateway.ha.provider.HaDescriptor;
-import org.apache.hadoop.gateway.ha.provider.HaProvider;
-import org.junit.Test;
-
-import java.util.ArrayList;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isIn;
-import static org.junit.Assert.*;
-
-public class DefaultHaProviderTest {
-
-   @Test
-   public void testDescriptor() {
-  try {
- new DefaultHaProvider(null);
- fail("provider construction should have failed with null descriptor");
-  } catch (IllegalArgumentException e) {
-  }
-  HaDescriptor descriptor = new DefaultHaDescriptor();
-  HaProvider provider = new DefaultHaProvider(descriptor);
-  assertNotNull(provider.getHaDescriptor());
-  descriptor.addServiceConfig(new DefaultHaServiceConfig("foo"));
-  assertTrue(provider.isHaEnabled("foo"));
-   }
-
-   @Test
-   public void testAddingService() {
-  HaDescriptor descriptor = new DefaultHaDescriptor();
-  HaProvider provider = new DefaultHaProvider(descriptor);
-  ArrayList urls = new ArrayList();
-  urls.add("http://host1;);
-  urls.add("http://host2;);
-  provider.addHaService("foo", urls);
-  assertNull(provider.getActiveURL("bar"));
-  String url = provider.getActiveURL("foo");
-  assertNotNull(url);
-  assertThat(url, isIn(urls));
-   }
-
-   @Test
-   public void testActiveUrl() {
-  HaDescriptor descriptor = new DefaultHaDescriptor();
-  HaProvider provider = new DefaultHaProvider(descriptor);
-  ArrayList urls = new ArrayList();
-  String url1 = "http://host1;;
-  urls.add(url1);
-  String url2 = "http://host2;;
-  urls.add(url2);
-  String url3 = "http://host3;;
-  urls.add(url3);
-  String serviceName = "foo";
-  provider.addHaService(serviceName, urls);
-  assertEquals(url1, provider.getActiveURL(serviceName));
-  provider.markFailedURL(serviceName, url1);
-  assertEquals(url2, provider.getActiveURL(serviceName));
-  provider.markFailedURL(serviceName, url2);
-  assertEquals(url3, provider.getActiveURL(serviceName));
-  provider.markFailedURL(serviceName, url3);
-  assertEquals(url1, provider.getActiveURL(serviceName));
-  provider.setActiveURL(serviceName, url3);
-  assertEquals(url3, provider.getActiveURL(serviceName));
-  provider.setActiveURL(serviceName, url2);
-  assertEquals(url2, provider.getActiveURL(serviceName));
-   }
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManagerTest.java
--
diff --git 
a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManagerTest.java
 
b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManagerTest.java
deleted file mode 100644
index 6c07d23..000
--- 
a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManagerTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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 

[14/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/noop.xml
--
diff --git 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/noop.xml
 
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/noop.xml
deleted file mode 100644
index a716582..000
--- 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/noop.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/simple.xml
--
diff --git 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/simple.xml
 
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/simple.xml
deleted file mode 100644
index 729a2d4..000
--- 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteRulesDescriptorFactoryTest/simple.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletContextListenerTest/rewrite.xml
--
diff --git 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletContextListenerTest/rewrite.xml
 
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletContextListenerTest/rewrite.xml
deleted file mode 100644
index 2e1d5af..000
--- 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletContextListenerTest/rewrite.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
--
diff --git 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
 
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
deleted file mode 100644
index 3b77eb3..000
--- 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-http://someotherhost/stylesheets/pretty.css"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/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
deleted file mode 100644
index c55eb77..000
--- 
a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest/rewrite.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-  

[64/64] knox git commit: KNOX-998 - Some more refactoring, making sure all the Unit Tests run and build passes !

2017-09-01 Thread more
KNOX-998 - Some more refactoring, making sure all the Unit Tests run and build 
passes !


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/2e6713b6
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/2e6713b6
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/2e6713b6

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 2e6713b6c33b54533e6d81ab575ce292aaa43f0d
Parents: 912c536
Author: Sandeep More 
Authored: Thu Aug 31 16:39:06 2017 -0400
Committer: Sandeep More 
Committed: Thu Aug 31 16:39:06 2017 -0400

--
 .gitignore  |   2 +-
 .../applications/knoxauth/app/redirecting.jsp   |   2 +-
 .../src/main/resources/META-INF/launcher.cfg|   2 +-
 gateway-demo-ldap/pom.xml   |   4 +-
 .../src/main/resources/log4j.properties |   4 +-
 .../ha/dispatch/i18n/HaDispatchMessages.java|   2 +-
 .../ha/provider/impl/i18n/HaMessages.java   |   2 +-
 .../knox/gateway/IdentityAsserterMessages.java  |   2 +-
 .../gateway/ConcatIdentityAsserterMessages.java |   2 +-
 ...adoopGroupProviderDeploymentContributor.java |   2 +-
 .../filter/HadoopGroupProviderMessages.java |   2 +-
 .../knox/gateway/IdentityAsserterMessages.java  |   2 +-
 .../hostmap/impl/HostmapFunctionProcessor.java  |   4 +-
 .../ServiceMappedHostFunctionProcessor.java |   4 +-
 .../gateway/encrypturi/EncryptUriMessages.java  |   2 +-
 .../securequery/SecureQueryMessages.java|   2 +-
 .../filter/rewrite/i18n/UrlRewriteMessages.java |   2 +-
 .../src/test/resources/log4j.properties |   8 +-
 .../AnonymousAuthDeploymentContributor.java |   2 +-
 .../impl/AclsAuthzDeploymentContributor.java|   2 +-
 .../filter/AclsAuthorizationMessages.java   |   2 +-
 .../gateway/hadoopauth/HadoopAuthMessages.java  |   2 +-
 .../provider/federation/jwt/JWTMessages.java|   2 +-
 .../knox/gateway/pac4j/Pac4jMessages.java   |   2 +-
 .../pac4j/filter/Pac4jIdentityAdapter.java  |  12 +-
 .../gateway/picketlink/PicketlinkMessages.java  |   2 +-
 .../knox/gateway/preauth/PreAuthMessages.java   |   2 +-
 .../deploy/HeaderPreAuthContributor.java|   2 +-
 .../HeaderPreAuthFederationFilterTest.java  |   2 +-
 .../provider/federation/PreAuthServiceTest.java |   2 +-
 .../deploy/impl/ShiroDeploymentContributor.java |   6 +-
 .../shirorealm/impl/i18n/KnoxShiroMessages.java |   2 +-
 .../gateway/webappsec/WebAppSecMessages.java|   2 +-
 .../webappsec/deploy/WebAppSecContributor.java  |   5 +-
 .../home/conf/gateway-log4j.properties  |  20 +-
 .../home/conf/knoxcli-log4j.properties  |   4 +-
 .../src/main/resources/META-INF/launcher.cfg|   2 +-
 .../services/metrics/impl/instr/InstrUtils.java |  54 --
 .../apache/knox/gateway/GatewayMessages.java|   2 +-
 .../ServiceDefinitionDeploymentContributor.java |   2 +-
 .../gateway/services/CLIGatewayServices.java|   4 +-
 .../services/DefaultGatewayServices.java|   4 +-
 .../GatewayServicesContextListener.java |   4 +-
 .../hostmap/impl/DefaultHostMapperService.java  |   6 +-
 .../security/impl/DefaultAliasService.java  |   6 +-
 .../impl/DefaultTokenAuthorityService.java  |   8 +-
 .../knox/gateway/trace/AccessHandler.java   |   2 +-
 .../apache/knox/gateway/trace/TraceHandler.java |   2 +-
 .../org/apache/knox/gateway/util/KnoxCLI.java   |   4 +-
 .../websockets/WebsocketLogMessages.java|   2 +-
 .../src/main/resources/conf/log4j.properties|   2 +-
 .../org/apache/knox/gateway/GatewayServer.xml   |   2 +-
 .../org/apache/knox/gateway/GatewayFuncTest.xml |   4 +-
 .../apache/knox/gateway/util/KnoxCLITest.java   |   4 +-
 .../src/test/resources/conf-demo/conf/shiro.ini |   2 +-
 .../conf-demo/conf/topologies/admin.xml |   4 +-
 .../conf-demo/conf/topologies/sandbox.xml   |   4 +-
 .../src/test/resources/log4j.properties |   2 +-
 .../org/apache/knox/gateway/GatewayFuncTest.xml |   2 +-
 .../xml/simple-topology-ambari-format.conf  |   2 +-
 .../xml/simple-topology-knox-format.xml |   2 +-
 gateway-server/src/test/resources/shiro.ini |   2 +-
 .../AdminServiceDeploymentContributor.java  |   2 +-
 .../resources/services/ambari/2.2.0/service.xml |   2 +-
 .../services/ambariui/2.2.0/service.xml |   2 +-
 .../services/atlas-api/0.8.0/service.xml|   2 +-
 .../resources/services/atlas/0.8.0/service.xml  |   2 +-
 .../resources/services/hbase/0.98.0/service.xml |   2 +-
 .../services/hbaseui/1.1.0/service.xml  |   2 +-
 .../resources/services/hdfsui/2.7.0/service.xml |   2 +-
 .../resources/services/hive/0.13.0/service.xml  |   2 +-
 .../resources/services/ranger/0.5.0/service.xml |   2 +-
 .../services/rangerui/0.5.0/service.xml |   2 +-
 .../resources/services/solr/5.5.0/service.xml   |   2 +-
 

[42/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
--
diff --git 
a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
 
b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
deleted file mode 100644
index a54c03b..000
--- 
a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.identityasserter.function;
-
-import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletContextListener;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
-import 
org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
-import 
org.apache.hadoop.gateway.identityasserter.common.function.UsernameFunctionProcessor;
-import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.test.TestUtils;
-import org.apache.hadoop.test.log.NoOpLogger;
-import org.apache.hadoop.test.mock.MockInteraction;
-import org.apache.hadoop.test.mock.MockServlet;
-import org.apache.http.auth.BasicUserPrincipal;
-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.log.Log;
-import org.hamcrest.core.Is;
-import org.junit.After;
-import org.junit.Test;
-
-import javax.security.auth.Subject;
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.fail;
-
-public class UsernameFunctionProcessorTest {
-
-  private ServletTester server;
-  private HttpTester.Request request;
-  private HttpTester.Response response;
-  private ArrayQueue interactions;
-  private MockInteraction interaction;
-
-  private static URL getTestResource( String name ) {
-name = UsernameFunctionProcessorTest.class.getName().replaceAll( "\\.", 
"/" ) + "/" + name;
-URL url = ClassLoader.getSystemResource( name );
-return url;
-  }
-
-  public void setUp( String username, Map initParams ) throws 
Exception {
-String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm();
-
-Log.setLog( new NoOpLogger() );
-
-server = new ServletTester();
-server.setContextPath( "/" );
-server.getContext().addEventListener( new 
UrlRewriteServletContextListener() );
-server.getContext().setInitParameter(
-UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, 
descriptorUrl );
-
-FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", 
EnumSet.of( DispatcherType.REQUEST ) );
-setupFilter.setFilter( new SetupFilter( username ) );
-FilterHolder rewriteFilter = server.addFilter( 

[19/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
deleted file mode 100644
index deed693..000
--- 
a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
+++ /dev/null
@@ -1,765 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter.rewrite.impl.html;
-
-import org.apache.commons.digester3.Digester;
-import org.apache.commons.digester3.ExtendedBaseRules;
-import org.apache.commons.digester3.binder.DigesterLoader;
-import org.apache.commons.io.IOUtils;
-import 
org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteStepFlow;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptorExt;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor;
-import 
org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptorExt;
-import 
org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl;
-import 
org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlRewriteRulesDigester;
-import 
org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteActionDescriptorBase;
-import org.hamcrest.Matchers;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.SAXException;
-import org.xmlmatchers.namespace.SimpleNamespaceContext;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.xmlmatchers.XmlMatchers.hasXPath;
-import static org.xmlmatchers.transform.XmlConverters.the;
-
-public class HtmlFilterReaderBaseTest {
-
-  public static class NoopXmlFilterReader extends HtmlFilterReaderBase {
-public NoopXmlFilterReader( Reader reader ) throws IOException, 
ParserConfigurationException {
-  super( reader );
-}
-
-@Override
-protected String filterText( QName elementName, String text, String 
ruleName ) {
-  return text;
-}
-
-@Override
-protected String filterAttribute( QName elementName, QName attributeName, 
String attributeValue, String ruleName ) {
-  return attributeValue;
-}
-
-@Override
-public String filterValueString( String name, String value, String 
ruleName ) {
-  return value;
-}
-  }
-
-  public static class MapXmlFilterReader extends HtmlFilterReaderBase {
-private Map map;
-
-public MapXmlFilterReader( Reader reader, Map map ) throws 
IOException, ParserConfigurationException {
-  super( reader );
-  this.map = map;
-}
-
-@Override
-protected String filterAttribute( QName elementName, QName attributeName, 
String attributeValue, String ruleName ) {
-  return map.get( 

[47/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/messages/loggers/test/TestMessageRecord.java
--
diff --git 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/messages/loggers/test/TestMessageRecord.java
 
b/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/messages/loggers/test/TestMessageRecord.java
deleted file mode 100644
index 46edf98..000
--- 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/messages/loggers/test/TestMessageRecord.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.i18n.messages.loggers.test;
-
-import org.apache.hadoop.gateway.i18n.messages.MessageLevel;
-
-/**
- *
- */
-public class TestMessageRecord {
-
-  private final TestMessageLogger logger;
-  private final StackTraceElement caller;
-  private final MessageLevel level;
-  private final String id;
-  private final String message;
-  private final Throwable throwable;
-
-  public TestMessageRecord( TestMessageLogger logger, StackTraceElement 
caller, MessageLevel level, String id, String message, Throwable throwable ) {
-this.logger = logger;
-this.caller = caller;
-this.level = level;
-this.id = id;
-this.message = message;
-this.throwable = throwable;
-  }
-  
-  public TestMessageLogger getLogger() {
-return logger;
-  }
-
-  public StackTraceElement getCaller() {
-return caller;
-  }
-
-  public MessageLevel getLevel() {
-return level;
-  }
-
-  public String getId() {
-return id;
-  }
-
-  public String getMessage() {
-return message;
-  }
-
-  public Throwable getThrowable() {
-return throwable;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resource.java
--
diff --git 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resource.java
 
b/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resource.java
deleted file mode 100644
index 727b385..000
--- 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resource.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.i18n.resources;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- *
- */
-@Retention( RetentionPolicy.RUNTIME )
-@Target( ElementType.METHOD )
-public @interface Resource {
-  static final String DEFAULT_TEXT = "{}";
-  String text() default DEFAULT_TEXT;
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resources.java
--
diff --git 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resources.java
 
b/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resources.java
deleted file mode 100644
index 2762dd5..000
--- 
a/gateway-i18n/src/main/java/org/apache/hadoop/gateway/i18n/resources/Resources.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation 

[15/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/rewrite.xml
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/rewrite.xml
 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/rewrite.xml
new file mode 100644
index 000..b5d4f50
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/rewrite.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+rewrite
+url-rewrite
+
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter
+url.rule{rule-name}
+request.filter{filters-name}
+
response.filter{filters-name}
+
+
+
+
+
+
+
+...
+
+
+
+
+
+
+
+
+
+
+...
+
+
+
+
+
+
+
+http://vm:50070/webhdfs/{version}/?{**}"/>
+
+
+http://vm:50070/webhdfs/{version}/{path=**}?{**}"/>
+
+
+
+
+http://{host}:{port}/{path=**}?{**}"/>
+
+
+
+
+
+
+
+http://vm:50111/templeton/{version}/{path=**}?{**}"/>
+
+
+http://vm:11000/oozie/{**}?{**}"/>
+
+
+http://vm:11000/oozie/v1/{**}?{**}"/>
+
+
+
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
--
diff --git 
a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
new file mode 100644
index 000..7ac4626
--- /dev/null
+++ 
b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
@@ -0,0 +1,1003 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.filter.rewrite.impl.xml;
+
+import org.apache.commons.digester3.Digester;
+import org.apache.commons.digester3.ExtendedBaseRules;
+import org.apache.commons.digester3.binder.DigesterLoader;
+import org.apache.commons.io.IOUtils;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
+import 
org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepFlow;
+import org.apache.knox.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptorExt;
+import org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor;
+import org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor;
+import org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptorExt;
+import 
org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteActionDescriptorBase;
+import org.apache.hadoop.test.TestUtils;
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+import org.xmlmatchers.namespace.SimpleNamespaceContext;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;

[06/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/filter/ShiroSubjectIdentityAdapter.java
--
diff --git 
a/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/filter/ShiroSubjectIdentityAdapter.java
 
b/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/filter/ShiroSubjectIdentityAdapter.java
deleted file mode 100644
index b625f34..000
--- 
a/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/filter/ShiroSubjectIdentityAdapter.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.filter;
-
-import java.io.IOException;
-import java.security.Principal;
-import java.security.PrivilegedExceptionAction;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.hadoop.gateway.audit.api.Action;
-import org.apache.hadoop.gateway.audit.api.ActionOutcome;
-import org.apache.hadoop.gateway.audit.api.AuditService;
-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.security.GroupPrincipal;
-import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.subject.Subject;
-
-public class ShiroSubjectIdentityAdapter implements Filter {
-  
-  private static final String SUBJECT_USER_GROUPS = "subject.userGroups";
-  private static AuditService auditService = 
AuditServiceFactory.getAuditService();
-  private static Auditor auditor = auditService.getAuditor(
-  AuditConstants.DEFAULT_AUDITOR_NAME, AuditConstants.KNOX_SERVICE_NAME,
-  AuditConstants.KNOX_COMPONENT_NAME );
-  
-
-  @Override
-  public void init( FilterConfig filterConfig ) throws ServletException {
-  }
-
-  public void destroy() {
-  }
-
-  public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) 
-  throws IOException, ServletException {
-
-Subject subject = SecurityUtils.getSubject();
-
-// trigger call to shiro authorization realm
-// we use shiro authorization realm to look up groups
-subject.hasRole("authenticatedUser");
-
-CallableChain callableChain = new CallableChain(request, response, chain);
-SecurityUtils.getSubject().execute(callableChain);
-  }
-  
-  private static class CallableChain implements Callable {
-private FilterChain chain = null;
-ServletRequest request = null;
-ServletResponse response = null;
-
-CallableChain(ServletRequest request, ServletResponse response, 
FilterChain chain) {
-  this.request = request;
-  this.response = response;
-  this.chain = chain;
-}
-
-@Override
-public Void call() throws Exception {
-  PrivilegedExceptionAction action = new 
PrivilegedExceptionAction() {
-@Override
-public Void run() throws Exception {
-  chain.doFilter( request, response );
-  return null;
-}
-  };
-  Subject shiroSubject = SecurityUtils.getSubject();
-
-  if (shiroSubject == null || shiroSubject.getPrincipal() == null) {
-throw new IllegalStateException("Unable to determine authenticated 
user from Shiro, please check that your Knox Shiro configuration is correct");
-  }
-
-  final String principal = (String) shiroSubject.getPrincipal().toString();
-  HashSet emptySet = new HashSet();
-  Set principals = new HashSet<>();
-  Principal p = new PrimaryPrincipal(principal);
-  principals.add(p);
-  auditService.getContext().setUsername( principal ); //KM: Audit Fix
-  String sourceUri = (String)request.getAttribute( 

[10/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/SSOCookieProviderTest.java
--
diff --git 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/SSOCookieProviderTest.java
 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/SSOCookieProviderTest.java
deleted file mode 100644
index 396aec9..000
--- 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/SSOCookieProviderTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.provider.federation;
-
-import static org.junit.Assert.fail;
-
-import java.security.NoSuchAlgorithmException;
-import java.security.Principal;
-import java.util.Properties;
-import java.util.Date;
-import java.util.Set;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import 
org.apache.hadoop.gateway.provider.federation.jwt.filter.SSOCookieFederationFilter;
-import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.apache.hadoop.gateway.services.security.token.JWTokenAuthority;
-import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.nimbusds.jwt.SignedJWT;
-
-public class SSOCookieProviderTest extends AbstractJWTFilterTest {
-  private static final String SERVICE_URL = "https://localhost:/resource;;
-  private static final String REDIRECT_LOCATION =
-  "https://localhost:8443/authserver?originalUrl=; + SERVICE_URL;
-  
-  @Before
-  public void setup() throws Exception, NoSuchAlgorithmException {
-super.setup();
-handler = new TestSSOCookieFederationProvider();
-((TestSSOCookieFederationProvider) handler).setTokenService(new 
TestJWTokenAuthority());
-  }
-  
-  protected void setTokenOnRequest(HttpServletRequest request, SignedJWT jwt) {
-Cookie cookie = new Cookie("hadoop-jwt", jwt.serialize());
-EasyMock.expect(request.getCookies()).andReturn(new Cookie[] { cookie });
-  }
-  
-  protected void setGarbledTokenOnRequest(HttpServletRequest request, 
SignedJWT jwt) {
-Cookie cookie = new Cookie("hadoop-jwt", "ljm" + jwt.serialize());
-EasyMock.expect(request.getCookies()).andReturn(new Cookie[] { cookie });
-  }
-
-  protected String getAudienceProperty() {
-return TestSSOCookieFederationProvider.SSO_EXPECTED_AUDIENCES;
-  }
-  
-  @Test
-  public void testCustomCookieNameJWT() throws Exception {
-try {
-  Properties props = getProperties();
-  props.put("sso.cookie.name", "jowt");
-  handler.init(new TestFilterConfig(props));
-
-  SignedJWT jwt = getJWT("alice", new Date(new Date().getTime() + 5000),
-  privateKey, props);
-
-  Cookie cookie = new Cookie("jowt", jwt.serialize());
-  HttpServletRequest request = 
EasyMock.createNiceMock(HttpServletRequest.class);
-  EasyMock.expect(request.getCookies()).andReturn(new Cookie[] { cookie });
-  EasyMock.expect(request.getRequestURL()).andReturn(
-  new StringBuffer(SERVICE_URL)).anyTimes();
-  EasyMock.expect(request.getQueryString()).andReturn(null);
-  HttpServletResponse response = 
EasyMock.createNiceMock(HttpServletResponse.class);
-  EasyMock.expect(response.encodeRedirectURL(SERVICE_URL)).andReturn(
-  SERVICE_URL);
-  EasyMock.replay(request);
-
-  TestFilterChain chain = new TestFilterChain();
-  handler.doFilter(request, response, chain);
-  Assert.assertTrue("doFilterCalled should not be false.", 
chain.doFilterCalled == true);
-  Set principals = 
chain.subject.getPrincipals(PrimaryPrincipal.class);
-  Assert.assertTrue("No PrimaryPrincipal returned.", principals.size() > 
0);
-  Assert.assertEquals("Not the expected principal", "alice", 
((Principal)principals.toArray()[0]).getName());
-} catch (ServletException se) {
-  fail("Should NOT have thrown a 

[04/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-security-webappsec/src/main/java/org/apache/knox/gateway/webappsec/deploy/WebAppSecContributor.java
--
diff --git 
a/gateway-provider-security-webappsec/src/main/java/org/apache/knox/gateway/webappsec/deploy/WebAppSecContributor.java
 
b/gateway-provider-security-webappsec/src/main/java/org/apache/knox/gateway/webappsec/deploy/WebAppSecContributor.java
new file mode 100644
index 000..57d76fa
--- /dev/null
+++ 
b/gateway-provider-security-webappsec/src/main/java/org/apache/knox/gateway/webappsec/deploy/WebAppSecContributor.java
@@ -0,0 +1,106 @@
+/**
+ * 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.
+ */
+package org.apache.knox.gateway.webappsec.deploy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.knox.gateway.deploy.DeploymentContext;
+import org.apache.knox.gateway.deploy.ProviderDeploymentContributorBase;
+import org.apache.knox.gateway.descriptor.FilterParamDescriptor;
+import org.apache.knox.gateway.descriptor.ResourceDescriptor;
+import org.apache.knox.gateway.topology.Provider;
+import org.apache.knox.gateway.topology.Service;
+
+public class WebAppSecContributor extends
+ProviderDeploymentContributorBase {
+  private static final String ROLE = "webappsec";
+  private static final String NAME = "WebAppSec";
+  private static final String CSRF_SUFFIX = "_CSRF";
+  private static final String CSRF_FILTER_CLASSNAME = "CSRFPreventionFilter";
+  private static final String CSRF_ENABLED = "csrf.enabled";
+  private static final String CORS_SUFFIX = "_CORS";
+  private static final String CORS_FILTER_CLASSNAME = 
"com.thetransactioncompany.cors.CORSFilter";
+  private static final String CORS_ENABLED = "cors.enabled";
+  private static final String XFRAME_OPTIONS_SUFFIX = "_XFRAMEOPTIONS";
+  private static final String XFRAME_OPTIONS_FILTER_CLASSNAME = 
"XFrameOptionsFilter";
+  private static final String XFRAME_OPTIONS_ENABLED = 
"xframe.options.enabled";
+
+  @Override
+  public String getRole() {
+return ROLE;
+  }
+
+  @Override
+  public String getName() {
+return NAME;
+  }
+
+  @Override
+  public void initializeContribution(DeploymentContext context) {
+super.initializeContribution(context);
+  }
+
+  @Override
+  public void contributeFilter(DeploymentContext context, Provider provider, 
Service service, 
+  ResourceDescriptor resource, List params) {
+
+Provider webappsec = context.getTopology().getProvider(ROLE, NAME);
+if (webappsec != null && webappsec.isEnabled()) {
+  Map map = provider.getParams();
+  if (params == null) {
+params = new ArrayList();
+  }
+
+  Map providerParams = provider.getParams();
+  // CORS support
+  String corsEnabled = map.get(CORS_ENABLED);
+  if ( corsEnabled != null && corsEnabled.equals("true")) {
+provisionConfig(resource, providerParams, params, "cors.");
+resource.addFilter().name( getName() + CORS_SUFFIX ).role( getRole() 
).impl( CORS_FILTER_CLASSNAME ).params( params );
+  }
+
+  // CRSF
+  params = new ArrayList();
+  String csrfEnabled = map.get(CSRF_ENABLED);
+  if ( csrfEnabled != null && csrfEnabled.equals("true")) {
+provisionConfig(resource, providerParams, params, "csrf.");
+resource.addFilter().name( getName() + CSRF_SUFFIX ).role( getRole() 
).impl( CSRF_FILTER_CLASSNAME ).params( params );
+  }
+
+  // X-Frame-Options - clickjacking protection
+  params = new ArrayList();
+  String xframeOptionsEnabled = map.get(XFRAME_OPTIONS_ENABLED);
+  if ( xframeOptionsEnabled != null && 
xframeOptionsEnabled.equals("true")) {
+provisionConfig(resource, providerParams, params, "xframe.");
+resource.addFilter().name( getName() + XFRAME_OPTIONS_SUFFIX ).role( 
getRole() ).impl( XFRAME_OPTIONS_FILTER_CLASSNAME ).params( params );
+  }
+}
+  }
+
+  private void provisionConfig(ResourceDescriptor resource, Map 
providerParams,
+  List params, String prefix) {
+

[33/64] [partial] knox git commit: KNOX-998 - Refactoring save 1

2017-09-01 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
--
diff --git 
a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
 
b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
deleted file mode 100644
index 9a9d0c7..000
--- 
a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.
- */
-package org.apache.hadoop.gateway.encrypturi.impl;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.hadoop.gateway.encrypturi.EncryptStepContextParams;
-import org.apache.hadoop.gateway.encrypturi.api.DecryptUriDescriptor;
-import org.apache.hadoop.gateway.encrypturi.api.EncryptUriDescriptor;
-import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepProcessor;
-import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteStepStatus;
-import org.apache.hadoop.gateway.services.GatewayServices;
-import org.apache.hadoop.gateway.services.security.CryptoService;
-import org.apache.hadoop.gateway.services.security.EncryptionResult;
-import org.apache.hadoop.gateway.util.urltemplate.Expander;
-import org.apache.hadoop.gateway.util.urltemplate.Parser;
-import org.apache.hadoop.gateway.util.urltemplate.Template;
-
-public class DecryptUriProcessor
-implements UrlRewriteStepProcessor {
-
-  private String clusterName;
-  private CryptoService cryptoService;
-  private String param;
-
-  @Override
-  public String getType() {
-return DecryptUriDescriptor.STEP_NAME;
-  }
-
-  @Override
-  public void initialize( UrlRewriteEnvironment environment, 
DecryptUriDescriptor descriptor ) throws Exception {
-clusterName = environment.getAttribute( 
GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE );
-GatewayServices services = 
environment.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
-cryptoService = (CryptoService) 
services.getService(GatewayServices.CRYPTO_SERVICE);
-param = descriptor.getParam();
-  }
-
-  @Override
-  public UrlRewriteStepStatus process( UrlRewriteContext context ) throws 
Exception {
-if( param != null && !param.isEmpty() ) {
-  Template template = Parser.parseTemplate( "{" + param + "}" );
-  String resolvedTemplate = Expander.expandToString( template, 
context.getParameters(), context.getEvaluator() );
-  String url = decode( resolvedTemplate );
-  EncryptStepContextParams params = new EncryptStepContextParams();
-  params.addParam( param, Arrays.asList( url ) );
-  context.addParameters( params );
-  return UrlRewriteStepStatus.SUCCESS;
-}
-return UrlRewriteStepStatus.FAILURE;
-  }
-
-  @Override
-  public void destroy() {
-  }
-
-  private String decode( String string ) throws UnsupportedEncodingException {
-byte[] bytes = Base64.decodeBase64( string );
-EncryptionResult result = EncryptionResult.fromByteArray(bytes);
-byte[] clear = cryptoService.decryptForCluster(clusterName,
-EncryptUriDescriptor.PASSWORD_ALIAS,
-result.cipher,
-result.iv,
-result.salt);
-if (clear != null) {
-  return new String(clear);
-}
-return null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/af9b0c3d/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriDeploymentContributor.java
--
diff --git 
a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriDeploymentContributor.java
 

knox git commit: KNOX-1019 - Remove test-driver "hack" to copy services

2017-09-01 Thread coheigea
Repository: knox
Updated Branches:
  refs/heads/master 202b3dc8b -> f4de85657


KNOX-1019 - Remove test-driver "hack" to copy services


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/f4de8565
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/f4de8565
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/f4de8565

Branch: refs/heads/master
Commit: f4de8565783976a912c87c14382680994f3f9375
Parents: 202b3dc
Author: Colm O hEigeartaigh 
Authored: Fri Sep 1 10:56:24 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Fri Sep 1 10:56:24 2017 +0100

--
 .../hadoop/gateway/GatewayTestConfig.java   | 12 
 .../hadoop/gateway/GatewayTestDriver.java   | 15 --
 gateway-test/pom.xml| 30 
 .../gateway/AmbariServiceDefinitionTest.java| 15 --
 .../deploy/DeploymentFactoryFuncTest.java   | 25 
 5 files changed, 37 insertions(+), 60 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/f4de8565/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
--
diff --git 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index dde5908..09b0d94 100644
--- 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.gateway.config.GatewayConfig;
 
+import java.io.File;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -164,12 +165,12 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
   public void setHadoopKerberosSecured(boolean hadoopKerberosSecured) {
 this.hadoopKerberosSecured = hadoopKerberosSecured;
   }
-  
+
   @Override
   public String getKerberosConfig() {
 return kerberosConfig;
   }
-  
+
   public void setKerberosConfig(String kerberosConfig) {
 this.kerberosConfig = kerberosConfig;
   }
@@ -178,11 +179,11 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
   public boolean isKerberosDebugEnabled() {
 return kerberosDebugEnabled;
   }
-  
+
   public void setKerberosDebugEnabled(boolean kerberosDebugEnabled) {
 this.kerberosDebugEnabled = kerberosDebugEnabled;
   }
-  
+
   @Override
   public String getKerberosLoginConfig() {
 return kerberosLoginConfig;
@@ -309,7 +310,8 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
 if( gatewayServicesDir != null ) {
   return gatewayServicesDir;
 } else {
-  return getGatewayDataDir() + "/services";
+  File targetDir = new File( System.getProperty( "user.dir" ), 
"target/services" );
+  return targetDir.getPath();
 }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f4de8565/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
--
diff --git 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
index 3135123..f3976fd 100644
--- 
a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
+++ 
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestDriver.java
@@ -147,20 +147,6 @@ public class GatewayTestDriver {
 } catch (ServiceLifecycleException e) {
   e.printStackTrace(); // I18N not required.
 }
-File stacksDir = new File( config.getGatewayServicesDir() );
-stacksDir.mkdirs();
-//TODO: [sumit] This is a hack for now, need to find a better way to 
locate the source resources for 'stacks' to be tested
-String pathToStacksSource = 
"gateway-service-definitions/src/main/resources/services";
-File stacksSourceDir = new File( targetDir.getParent(), 
pathToStacksSource);
-if (!stacksSourceDir.exists()) {
-  stacksSourceDir = new File( targetDir.getParentFile().getParent(), 
pathToStacksSource);
-}
-if (!stacksSourceDir.exists()) {
-  stacksSourceDir = new File( 
targetDir.getParentFile().getParentFile().getParent(), pathToStacksSource);
-}
-if (stacksSourceDir.exists()) {
-  FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir);
-}
 
 gateway = 

knox git commit: KNOX-1018 - Remove junit.framework calls

2017-09-01 Thread coheigea
Repository: knox
Updated Branches:
  refs/heads/master f1bbea9b7 -> 202b3dc8b


KNOX-1018 - Remove junit.framework calls


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/202b3dc8
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/202b3dc8
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/202b3dc8

Branch: refs/heads/master
Commit: 202b3dc8b8d955336689ce5c20860d5a69482dd2
Parents: f1bbea9
Author: Colm O hEigeartaigh 
Authored: Fri Sep 1 10:07:44 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Fri Sep 1 10:07:44 2017 +0100

--
 .../apache/hadoop/gateway/provider/federation/JWTTokenTest.java  | 3 +--
 .../org/apache/hadoop/gateway/picketlink/PicketlinkTest.java | 3 +--
 .../hadoop/gateway/provider/federation/DefaultValidatorTest.java | 3 +--
 .../provider/federation/HeaderPreAuthFederationFilterTest.java   | 3 +--
 .../hadoop/gateway/provider/federation/IPValidatorTest.java  | 3 +--
 .../hadoop/gateway/provider/federation/PreAuthSSOTest.java   | 3 +--
 .../hadoop/gateway/provider/federation/PreAuthServiceTest.java   | 3 +--
 .../test/java/org/apache/hadoop/gateway/webappsec/CSRFTest.java  | 3 +--
 .../apache/hadoop/gateway/filter/CompositeEnumerationTest.java   | 2 +-
 .../org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java  | 2 +-
 .../org/apache/hadoop/gateway/util/IpAddressValidatorTest.java   | 3 +--
 .../test/java/org/apache/hadoop/gateway/util/JsonUtilsTest.java  | 3 +--
 .../src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java   | 4 ++--
 .../config/impl/BeanConfigurationAdapterDescriptorTest.java  | 2 +-
 .../org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java | 2 +-
 15 files changed, 16 insertions(+), 26 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/202b3dc8/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTTokenTest.java
--
diff --git 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTTokenTest.java
 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTTokenTest.java
index 8d8bcab..2830a9c 100644
--- 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTTokenTest.java
+++ 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTTokenTest.java
@@ -18,12 +18,11 @@
 package org.apache.hadoop.gateway.provider.federation;
 
 import java.util.ArrayList;
-import junit.framework.TestCase;
 
 import org.apache.hadoop.gateway.services.security.token.impl.JWTToken;
 import org.junit.Test;
 
-public class JWTTokenTest extends TestCase {
+public class JWTTokenTest extends org.junit.Assert {
   private static final String JWT_TOKEN = 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0MTY5MjkxMDksImp0aSI6ImFhN2Y4ZDBhOTVjIiwic2NvcGVzIjpbInJlcG8iLCJwdWJsaWNfcmVwbyJdfQ.XCEwpBGvOLma4TCoh36FU7XhUbcskygS81HE1uHLf0E";
   private static final String HEADER = "{\"alg\":\"RS256\", \"type\":\"JWT\"}";
   private static final String CLAIMS = "{\"iss\": \"gateway\", \"prn\": 
\"john@example.com\", \"aud\": \"https://login.example.com\;, \"exp\": 
\"1363360913\"}";

http://git-wip-us.apache.org/repos/asf/knox/blob/202b3dc8/gateway-provider-security-picketlink/src/test/java/org/apache/hadoop/gateway/picketlink/PicketlinkTest.java
--
diff --git 
a/gateway-provider-security-picketlink/src/test/java/org/apache/hadoop/gateway/picketlink/PicketlinkTest.java
 
b/gateway-provider-security-picketlink/src/test/java/org/apache/hadoop/gateway/picketlink/PicketlinkTest.java
index 4ef3088..0631eeb 100644
--- 
a/gateway-provider-security-picketlink/src/test/java/org/apache/hadoop/gateway/picketlink/PicketlinkTest.java
+++ 
b/gateway-provider-security-picketlink/src/test/java/org/apache/hadoop/gateway/picketlink/PicketlinkTest.java
@@ -18,12 +18,11 @@
  */
 package org.apache.hadoop.gateway.picketlink;
 
-import junit.framework.TestCase;
 
 import org.apache.hadoop.gateway.services.security.token.impl.JWTToken;
 import org.junit.Test;
 
-public class PicketlinkTest extends TestCase {
+public class PicketlinkTest extends org.junit.Assert {
   @Test
   public void testPicketlink() throws Exception {
 assertTrue(true);

http://git-wip-us.apache.org/repos/asf/knox/blob/202b3dc8/gateway-provider-security-preauth/src/test/java/org/apache/hadoop/gateway/provider/federation/DefaultValidatorTest.java
--
diff --git