You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by di...@apache.org on 2014/02/14 21:10:39 UTC

git commit: KNOX-260: gateway-test ldap group tests need to use KnoxCLI/AliasService class to update security stores

Updated Branches:
  refs/heads/master 117af3f0c -> bf3dcd7c9


KNOX-260: gateway-test ldap group tests need to use KnoxCLI/AliasService class to update security stores


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

Branch: refs/heads/master
Commit: bf3dcd7c996f9292c04932656664549bf90c54f6
Parents: 117af3f
Author: Dilli Dorai Arumugam <da...@hortonworks.com>
Authored: Fri Feb 14 12:03:17 2014 -0800
Committer: Dilli Dorai Arumugam <da...@hortonworks.com>
Committed: Fri Feb 14 12:06:54 2014 -0800

----------------------------------------------------------------------
 .../shirorealm/KnoxLdapContextFactory.java      | 12 ++++-
 gateway-test/pom.xml                            |  3 --
 .../GatewayLdapDynamicGroupFuncTest.java        | 48 +++++++++++++++---
 .../gateway/GatewayLdapGroupFuncTest.java       | 53 ++++++++++++++------
 4 files changed, 89 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/bf3dcd7c/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/shirorealm/KnoxLdapContextFactory.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/shirorealm/KnoxLdapContextFactory.java b/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/shirorealm/KnoxLdapContextFactory.java
index 0f36466..7c8c52e 100644
--- a/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/shirorealm/KnoxLdapContextFactory.java
+++ b/gateway-provider-security-shiro/src/main/java/org/apache/hadoop/gateway/shirorealm/KnoxLdapContextFactory.java
@@ -26,9 +26,12 @@ import javax.naming.ldap.LdapContext;
 
 import org.apache.hadoop.gateway.GatewayMessages;
 import org.apache.hadoop.gateway.GatewayServer;
+import org.apache.hadoop.gateway.config.GatewayConfig;
+import org.apache.hadoop.gateway.config.impl.GatewayConfigImpl;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.services.GatewayServices;
 import org.apache.hadoop.gateway.services.security.AliasService;
+import org.apache.hadoop.gateway.util.KnoxCLI;
 import org.apache.shiro.realm.ldap.JndiLdapContextFactory;
 
 /**
@@ -69,7 +72,7 @@ public class KnoxLdapContextFactory extends JndiLdapContextFactory {
     
     @Override
     public void setSystemPassword(String systemPass) {
-      
+     
       if ( systemPass == null ) {
         return;
       }
@@ -91,10 +94,17 @@ public class KnoxLdapContextFactory extends JndiLdapContextFactory {
       AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE);
       
       String clusterName = getClusterName();
+      //System.err.println("FACTORY systempass 30: " + systemPass);
+      //System.err.println("FACTORY clustername 40: " + clusterName);
+      //System.err.println("FACTORY SystemProperty GatewayHome 50: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
       char[] password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
+      //System.err.println("FACTORY password: " + ((password == null) ? "NULL" : new String(password)));
       if ( password != null ) {
+        //System.err.println("FACTORY SUCCESS 20 system password :" + new String(password));
         super.setSystemPassword( new String(password) );
       } else {
+        //System.err.println("FACTORY FORCING system password to blank");
+        super.setSystemPassword("" );
         LOG.aliasValueNotFound(clusterName, aliasName);
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/bf3dcd7c/gateway-test/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-test/pom.xml b/gateway-test/pom.xml
index 4b70a1e..f9c5a4e 100644
--- a/gateway-test/pom.xml
+++ b/gateway-test/pom.xml
@@ -158,9 +158,6 @@
                 <configuration>
                     <forkCount>1</forkCount>
                     <reuseForks>false</reuseForks>
-                    <excludedGroups>
-                        org.apache.hadoop.test.category.SlowTests,org.apache.hadoop.test.category.ManualTests,org.apache.hadoop.test.category.IntegrationTests
-                    </excludedGroups>
                     <systemPropertyVariables>
                         <gateway-version>${gateway-version}</gateway-version>
                     </systemPropertyVariables>

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/bf3dcd7c/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
index 5ac6e58..7878f9d 100755
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
@@ -22,10 +22,12 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.junit.Assert.assertThat;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.net.ServerSocket;
 import java.net.URL;
 import java.util.Enumeration;
@@ -35,11 +37,13 @@ import java.util.UUID;
 
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.hadoop.gateway.config.GatewayConfig;
+import org.apache.hadoop.gateway.config.impl.GatewayConfigImpl;
 import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
 import org.apache.hadoop.gateway.services.DefaultGatewayServices;
 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.util.KnoxCLI;
 import org.apache.http.HttpStatus;
 import org.apache.log4j.Appender;
 import org.hamcrest.MatcherAssert;
@@ -97,7 +101,7 @@ public class GatewayLdapDynamicGroupFuncTest {
     return port;
   }
 
-  public static void setupGateway(int ldapPort) throws IOException {
+  public static void setupGateway(int ldapPort) throws IOException, Exception {
     
     File targetDir = new File( System.getProperty( "user.dir" ), "target" );
     File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() );
@@ -117,7 +121,7 @@ public class GatewayLdapDynamicGroupFuncTest {
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();
-
+    
     DefaultGatewayServices srvcs = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();
     options.put( "persist-master", "false" );
@@ -127,6 +131,28 @@ public class GatewayLdapDynamicGroupFuncTest {
     } catch ( ServiceLifecycleException e ) {
       e.printStackTrace(); // I18N not required.
     }
+    
+    /*
+    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
+    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
+    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+    System.setOut(new PrintStream(outContent));
+    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "testdg-cluster"};
+    KnoxCLI cli = new KnoxCLI();
+    cli.setConf(new GatewayConfigImpl());
+    cli.run(argvals);
+    
+    outContent.reset();
+    String[] args1 = {"list-alias", "--cluster", "testdg-cluster", "--master", "hadoop"};
+    cli = new KnoxCLI();
+    cli.run(args1);
+    System.err.println("ALIAS LIST: " + outContent.toString());
+    
+    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
+    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
+    System.err.println("ALIAS value1: " + new String(passwordChars1));
+    */
+    
     gateway = GatewayServer.startGateway( testConfig, srvcs );
     MatcherAssert.assertThat( "Failed to start gateway.", gateway, notNullValue() );
 
@@ -135,20 +161,25 @@ public class GatewayLdapDynamicGroupFuncTest {
     gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
     clusterUrl = gatewayUrl + "/testdg-cluster";
     
+    ///*
     GatewayServices services = GatewayServer.getGatewayServices();
     AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE);
     aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
   
+    char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword");
+    //System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
+    
     descriptor = new File( topoDir, "testdg-cluster.xml" );
     stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();
     
     try {
-      Thread.sleep(3000);
+      Thread.sleep(5000);
     } catch (Exception e) {
       
     }
+    //*/
   }
 
   private static XMLTag createTopology(int ldapPort) {
@@ -200,8 +231,11 @@ public class GatewayLdapDynamicGroupFuncTest {
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemUsername" )
         .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" )
         .gotoParent().addTag( "param" )
+        .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" )
+        .addTag( "value" ).addText( "testdg-cluster" )
+        .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemPassword" )
-        .addTag( "value" ).addText( "${ALIAS=ldcSystemPassword}" )
+        .addTag( "value" ).addText( "S{ALIAS=ldcSystemPassword}" )
         // .addTag( "value" ).addText( "guest-password" )
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "urls./**" )
@@ -260,8 +294,7 @@ public class GatewayLdapDynamicGroupFuncTest {
   }
 
   @Test
-  public void testGroupMember() throws ClassNotFoundException {
-
+  public void testGroupMember() throws ClassNotFoundException, Exception {
     String username = "bob";
     String password = "bob-password";
     String serviceUrl =  clusterUrl + "/test-service-path/test-service-resource";
@@ -278,7 +311,6 @@ public class GatewayLdapDynamicGroupFuncTest {
   
   @Test
   public void testNonGroupMember() throws ClassNotFoundException {
-
     String username = "guest";
     String password = "guest-password";
     String serviceUrl =  clusterUrl + "/test-service-path/test-service-resource";
@@ -290,5 +322,5 @@ public class GatewayLdapDynamicGroupFuncTest {
         .statusCode( HttpStatus.SC_UNAUTHORIZED )
         .when().get( serviceUrl );
   }
-
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/bf3dcd7c/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
index 14c43fa..f3217d0 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
@@ -22,10 +22,12 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.junit.Assert.assertThat;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.net.ServerSocket;
 import java.net.URL;
 import java.util.Enumeration;
@@ -35,6 +37,7 @@ import java.util.UUID;
 
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.hadoop.gateway.config.GatewayConfig;
+import org.apache.hadoop.gateway.config.impl.GatewayConfigImpl;
 import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
 import org.apache.hadoop.gateway.services.DefaultGatewayServices;
 import org.apache.hadoop.gateway.services.GatewayServices;
@@ -118,20 +121,38 @@ public class GatewayLdapGroupFuncTest {
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();
-
+    
     DefaultGatewayServices srvcs = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();
-    options.put( "persist-master", "false" );
-    options.put( "master", "password" );
+    options.put( "persist-master", "true" );
+    options.put( "master", "hadoop" );
+    
     try {
       srvcs.init( testConfig, options );
     } catch ( ServiceLifecycleException e ) {
       e.printStackTrace(); // I18N not required.
     }
     
-    //String[] argvals = {"create-alias",  "aliasname", "--value",  "hadoop", 
-    //    "--cluster", "test-cluster"};
-    //KnoxCLI.runCommand(argvals);
+    /*
+    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
+    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
+    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+    System.setOut(new PrintStream(outContent));
+    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "test-cluster"};
+    KnoxCLI cli = new KnoxCLI();
+    cli.setConf(new GatewayConfigImpl());
+    cli.run(argvals);
+    
+    outContent.reset();
+    String[] args1 = {"list-alias", "--cluster", "test-cluster", "--master", "hadoop"};
+    cli = new KnoxCLI();
+    cli.run(args1);
+    System.err.println("ALIAS LIST: " + outContent.toString());
+    
+    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
+    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
+    System.err.println("ALIAS value1: " + new String(passwordChars1));
+    */
     
     gateway = GatewayServer.startGateway( testConfig, srvcs );
     MatcherAssert.assertThat( "Failed to start gateway.", gateway, notNullValue() );
@@ -141,20 +162,25 @@ public class GatewayLdapGroupFuncTest {
     gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
     clusterUrl = gatewayUrl + "/test-cluster";
     
+    ///*
     GatewayServices services = GatewayServer.getGatewayServices();
     AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE);
     aliasService.addAliasForCluster("test-cluster", "ldcSystemPassword", "guest-password");
   
+    char[] password1 = aliasService.getPasswordFromAliasForCluster( "test-cluster", "ldcSystemPassword");
+    //System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
+    
     descriptor = new File( topoDir, "test-cluster.xml" );
     stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();
     
     try {
-      Thread.sleep(3000);
+      Thread.sleep(5000);
     } catch (Exception e) {
       
     }
+    //*/
   }
 
   private static XMLTag createTopology(int ldapPort) {
@@ -203,12 +229,14 @@ public class GatewayLdapGroupFuncTest {
         .addTag( "name" ).addText( "main.ldapRealm.memberAttributeValueTemplate" )
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" )
         .gotoParent().addTag( "param" )
+        .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" )
+        .addTag( "value" ).addText( "test-cluster" )
+        .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemUsername" )
         .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" )
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemPassword" )
-        //.addTag( "value" ).addText( "${ALIAS=ldcSystemPassword}" )
-         .addTag( "value" ).addText( "guest-password" )
+        .addTag( "value" ).addText( "S{ALIAS=ldcSystemPassword}" )
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "urls./**" )
         .addTag( "value" ).addText( "authcBasic" )
@@ -266,8 +294,7 @@ public class GatewayLdapGroupFuncTest {
   }
 
   @Test
-  public void testGroupMember() throws ClassNotFoundException {
-
+  public void testGroupMember() throws ClassNotFoundException, Exception {
     String username = "sam";
     String password = "sam-password";
     String serviceUrl =  clusterUrl + "/test-service-path/test-service-resource";
@@ -296,9 +323,5 @@ public class GatewayLdapGroupFuncTest {
         .statusCode( HttpStatus.SC_UNAUTHORIZED )
         .when().get( serviceUrl );
   }
-  
-  @Test
-  public void dummyTest() {
-  }
 
 }