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/12 22:28:44 UTC

git commit: KNOX-254: use system password set using knoxcli in KnoxLdapContextFactory

Updated Branches:
  refs/heads/master 53f76396a -> c58ee3b03


KNOX-254: use system password set using knoxcli in KnoxLdapContextFactory


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

Branch: refs/heads/master
Commit: c58ee3b039abecb5dc05d4ca83822c87bffe4cb0
Parents: 53f7639
Author: Dilli Dorai Arumugam <da...@hortonworks.com>
Authored: Wed Feb 12 13:23:59 2014 -0800
Committer: Dilli Dorai Arumugam <da...@hortonworks.com>
Committed: Wed Feb 12 13:24:37 2014 -0800

----------------------------------------------------------------------
 .../shirorealm/KnoxLdapContextFactory.java      | 19 +++---
 .../apache/hadoop/gateway/GatewayMessages.java  |  3 +
 .../GatewayLdapDynamicGroupFuncTest.java        | 59 +++++++++++------
 .../gateway/GatewayLdapGroupFuncTest.java       | 69 ++++++++++++++------
 4 files changed, 97 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/c58ee3b0/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 d5b7ea0..0f36466 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
@@ -24,7 +24,9 @@ import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.hadoop.gateway.GatewayMessages;
 import org.apache.hadoop.gateway.GatewayServer;
+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.shiro.realm.ldap.JndiLdapContextFactory;
@@ -39,6 +41,8 @@ import org.apache.shiro.realm.ldap.JndiLdapContextFactory;
  */
 public class KnoxLdapContextFactory extends JndiLdapContextFactory {
 
+    private static GatewayMessages LOG = MessagesFactory.get( GatewayMessages.class );
+  
     private String systemAuthenticationMechanism = "simple";
     private String clusterName = "";
 
@@ -87,19 +91,12 @@ public class KnoxLdapContextFactory extends JndiLdapContextFactory {
       AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE);
       
       String clusterName = getClusterName();
-      String systemPassword = System.getProperty(clusterName + "." + aliasName);
-      if (systemPassword != null) {
-        super.setSystemPassword( systemPassword );
-        aliasService.addAliasForCluster(clusterName, aliasName, systemPassword);
+      char[] password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
+      if ( password != null ) {
+        super.setSystemPassword( new String(password) );
       } else {
-        char[] password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
-        if ( password != null ) {
-          super.setSystemPassword( new String(password) );
-        } else {
-          super.setSystemPassword( new String(systemPass) );
-        }
+        LOG.aliasValueNotFound(clusterName, aliasName);
       }
-      
     }
     
     public String getClusterName() {

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/c58ee3b0/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 34d191d..de87aa9 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -300,4 +300,7 @@ public interface GatewayMessages {
   
   @Message( level = MessageLevel.ERROR, text = "Failed to get system ldap connection: {0}" )
   void failedToGetSystemLdapConnection( @StackTrace( level = MessageLevel.DEBUG ) Exception e );
+  
+  @Message( level = MessageLevel.WARN, text = "Value not found for cluster:{0}, alias: {1}" )
+  void aliasValueNotFound( String cluster, String alias );
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/c58ee3b0/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 b4f0dc4..5ac6e58 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
@@ -17,13 +17,29 @@
  */
 package org.apache.hadoop.gateway;
 
-import com.mycila.xmltool.XMLDoc;
-import com.mycila.xmltool.XMLTag;
+import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+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.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.http.HttpStatus;
 import org.apache.log4j.Appender;
 import org.hamcrest.MatcherAssert;
@@ -35,21 +51,8 @@ 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.ServerSocket;
-import java.net.URL;
-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.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
+import com.mycila.xmltool.XMLDoc;
+import com.mycila.xmltool.XMLTag;
 
 /**
  * Functional test to verify : looking up ldap groups from directory 
@@ -95,8 +98,6 @@ public class GatewayLdapDynamicGroupFuncTest {
   }
 
   public static void setupGateway(int ldapPort) throws IOException {
-
-    System.setProperty("test-cluster.ldcSystemPassword", "guest-password");
     
     File targetDir = new File( System.getProperty( "user.dir" ), "target" );
     File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() );
@@ -112,7 +113,7 @@ public class GatewayLdapDynamicGroupFuncTest {
     File deployDir = new File( testConfig.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( topoDir, "test-cluster.xml" );
+    File descriptor = new File( topoDir, "testdg-cluster.xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();
@@ -132,7 +133,22 @@ public class GatewayLdapDynamicGroupFuncTest {
     LOG.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() );
 
     gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
-    clusterUrl = gatewayUrl + "/test-cluster";
+    clusterUrl = gatewayUrl + "/testdg-cluster";
+    
+    GatewayServices services = GatewayServer.getGatewayServices();
+    AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE);
+    aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
+  
+    descriptor = new File( topoDir, "testdg-cluster.xml" );
+    stream = new FileOutputStream( descriptor );
+    createTopology(ldapPort).toStream( stream );
+    stream.close();
+    
+    try {
+      Thread.sleep(3000);
+    } catch (Exception e) {
+      
+    }
   }
 
   private static XMLTag createTopology(int ldapPort) {
@@ -186,6 +202,7 @@ public class GatewayLdapDynamicGroupFuncTest {
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemPassword" )
         .addTag( "value" ).addText( "${ALIAS=ldcSystemPassword}" )
+        // .addTag( "value" ).addText( "guest-password" )
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "urls./**" )
         .addTag( "value" ).addText( "authcBasic" )

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/c58ee3b0/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 98a5c12..14c43fa 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
@@ -17,13 +17,30 @@
  */
 package org.apache.hadoop.gateway;
 
-import com.mycila.xmltool.XMLDoc;
-import com.mycila.xmltool.XMLTag;
+import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+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.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;
@@ -35,21 +52,8 @@ 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.ServerSocket;
-import java.net.URL;
-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.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
+import com.mycila.xmltool.XMLDoc;
+import com.mycila.xmltool.XMLTag;
 
 /**
  * Functional test to verify : looking up ldap groups from directory 
@@ -94,9 +98,7 @@ public class GatewayLdapGroupFuncTest {
     return port;
   }
 
-  public static void setupGateway(int ldapPort) throws IOException {
-
-    System.setProperty("test-cluster.ldcSystemPassword", "guest-password");
+  public static void setupGateway(int ldapPort) throws Exception {
     
     File targetDir = new File( System.getProperty( "user.dir" ), "target" );
     File gatewayDir = new File( targetDir, "gateway-home-" + UUID.randomUUID() );
@@ -126,6 +128,11 @@ public class GatewayLdapGroupFuncTest {
     } catch ( ServiceLifecycleException e ) {
       e.printStackTrace(); // I18N not required.
     }
+    
+    //String[] argvals = {"create-alias",  "aliasname", "--value",  "hadoop", 
+    //    "--cluster", "test-cluster"};
+    //KnoxCLI.runCommand(argvals);
+    
     gateway = GatewayServer.startGateway( testConfig, srvcs );
     MatcherAssert.assertThat( "Failed to start gateway.", gateway, notNullValue() );
 
@@ -133,6 +140,21 @@ 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");
+  
+    descriptor = new File( topoDir, "test-cluster.xml" );
+    stream = new FileOutputStream( descriptor );
+    createTopology(ldapPort).toStream( stream );
+    stream.close();
+    
+    try {
+      Thread.sleep(3000);
+    } catch (Exception e) {
+      
+    }
   }
 
   private static XMLTag createTopology(int ldapPort) {
@@ -185,7 +207,8 @@ public class GatewayLdapGroupFuncTest {
         .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( "${ALIAS=ldcSystemPassword}" )
+         .addTag( "value" ).addText( "guest-password" )
         .gotoParent().addTag( "param" )
         .addTag( "name" ).addText( "urls./**" )
         .addTag( "value" ).addText( "authcBasic" )
@@ -273,5 +296,9 @@ public class GatewayLdapGroupFuncTest {
         .statusCode( HttpStatus.SC_UNAUTHORIZED )
         .when().get( serviceUrl );
   }
+  
+  @Test
+  public void dummyTest() {
+  }
 
 }