knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-529 - second attempt to get all usecases - missed wildcard plus explicit mappings before
Date Wed, 15 Apr 2015 12:55:17 GMT
Repository: knox
Updated Branches:
  refs/heads/master cc27d465e -> 7a122bfb7


KNOX-529 - second attempt to get all usecases - missed wildcard plus explicit mappings before

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

Branch: refs/heads/master
Commit: 7a122bfb7dc324ab54c97aebb7b55ef1e8ce36b1
Parents: cc27d46
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Wed Apr 15 08:55:05 2015 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Wed Apr 15 08:55:05 2015 -0400

----------------------------------------------------------------------
 .../principal/SimplePrincipalMapper.java        | 21 ++++++++++++++++++--
 .../security/principal/PrincipalMapperTest.java | 20 +++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/7a122bfb/gateway-spi/src/main/java/org/apache/hadoop/gateway/security/principal/SimplePrincipalMapper.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/security/principal/SimplePrincipalMapper.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/security/principal/SimplePrincipalMapper.java
index e1623e7..802166b 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/security/principal/SimplePrincipalMapper.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/security/principal/SimplePrincipalMapper.java
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.gateway.security.principal;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.StringTokenizer;
 
@@ -94,14 +95,30 @@ public class SimplePrincipalMapper implements PrincipalMapper {
   @Override
   public String[] mapGroupPrincipal(String principalName) {
     String[] groups = null;
+    String[] wildCardGroups = null;
     
     if (groupMappings != null) {
       groups = groupMappings.get(principalName);
-      if (groups == null) {
-        groups = groupMappings.get("*");
+      wildCardGroups = groupMappings.get("*");
+      if (groups != null && wildCardGroups != null) {
+        groups = concat(groups, wildCardGroups); 
+      }
+      else if (wildCardGroups != null) {
+        return wildCardGroups;
       }
     }
     
     return groups;
   }
+
+  /**
+   * @param groups
+   * @param wildCardGroups
+   * @return
+   */
+  public static <T> T[] concat(T[] first, T[] second) {
+    T[] result = Arrays.copyOf(first, first.length + second.length);
+    System.arraycopy(second, 0, result, first.length, second.length);
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/7a122bfb/gateway-spi/src/test/java/org/apache/hadoop/gateway/security/principal/PrincipalMapperTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/hadoop/gateway/security/principal/PrincipalMapperTest.java
b/gateway-spi/src/test/java/org/apache/hadoop/gateway/security/principal/PrincipalMapperTest.java
index 890a46f..16e972e 100644
--- a/gateway-spi/src/test/java/org/apache/hadoop/gateway/security/principal/PrincipalMapperTest.java
+++ b/gateway-spi/src/test/java/org/apache/hadoop/gateway/security/principal/PrincipalMapperTest.java
@@ -56,6 +56,26 @@ public class PrincipalMapperTest {
   }
   
   @Test
+  public void testSimplePrincipalMappingWithWildcardAndExplicitGroups() {
+    String principalMapping = "";
+    String groupMapping = "*=users;lmccay=mrgroup";
+    try {
+      mapper.loadMappingTable(principalMapping, groupMapping);
+    }
+    catch (PrincipalMappingException pme) {
+      pme.printStackTrace();
+      fail();
+    }
+    
+    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
+    assertTrue(mapper.mapGroupPrincipal("hdfs")[0].equals("users"));
+    String group = mapper.mapGroupPrincipal("lmccay")[0];
+    assertTrue(group.equals("users") || group.equals("mrgroup"));
+    group = mapper.mapGroupPrincipal("lmccay")[1];
+    assertTrue(group.equals("users") || group.equals("mrgroup"));
+  }
+
+  @Test
   public void testNonNullSimplePrincipalMappingWithGroups() {
     String principalMapping = "lmccay,kminder=hdfs;newuser=mapred";
     String groupMapping = "hdfs=group1;mapred=mrgroup,mrducks";


Mime
View raw message