ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject incubator-ranger git commit: RANGER-970 Adding ability to transform users and groups when using file source
Date Mon, 09 May 2016 12:20:41 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 96dc7f4b0 -> ec749f09e


RANGER-970 Adding ability to transform users and groups when using file source

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


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

Branch: refs/heads/master
Commit: ec749f09e0b1b88787690476ea1aca92e603bf32
Parents: 96dc7f4
Author: Bryan Bende <bbende@apache.org>
Authored: Thu May 5 13:11:43 2016 -0400
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Mon May 9 08:20:28 2016 -0400

----------------------------------------------------------------------
 .../process/LdapUserGroupBuilder.java           |  47 +-----
 .../process/FileSourceUserGroupBuilder.java     |  23 ++-
 .../usergroupsync/AbstractUserGroupSource.java  |  70 ++++++++
 .../process/FileSourceUserGroupBuilderTest.java | 160 +++++++++++++++++++
 .../ranger/usergroupsync/LdapUserGroupTest.java |  34 +++-
 .../PolicyMgrUserGroupBuilderTest.java          |  18 ++-
 ugsync/src/test/resources/usergroups-dns.csv    |   4 +
 .../test/resources/usergroups-other-delim.csv   |   4 +
 ugsync/src/test/resources/usergroups.csv        |   4 +
 ugsync/src/test/resources/usergroups.json       |   6 +
 10 files changed, 316 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
index b12d209..0b76883 100644
--- a/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/ldapusersync/process/LdapUserGroupBuilder.java
@@ -47,17 +47,14 @@ import javax.naming.ldap.StartTlsResponse;
 
 import org.apache.log4j.Logger;
 import org.apache.ranger.unixusersync.config.UserGroupSyncConfig;
-import org.apache.ranger.usergroupsync.Mapper;
+import org.apache.ranger.usergroupsync.AbstractUserGroupSource;
 import org.apache.ranger.usergroupsync.UserGroupSink;
-import org.apache.ranger.usergroupsync.UserGroupSource;
 
-public class LdapUserGroupBuilder implements UserGroupSource {
+public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 	
 	private static final Logger LOG = Logger.getLogger(LdapUserGroupBuilder.class);
 	
 	private static final int PAGE_SIZE = 500;
-	
-	private UserGroupSyncConfig config = UserGroupSyncConfig.getInstance();
 
   private String ldapUrl;
   private String ldapBindDn;
@@ -100,9 +97,7 @@ public class LdapUserGroupBuilder implements UserGroupSource {
 	private boolean groupNameLowerCaseFlag = false ;
 
   private boolean  groupUserMapSyncEnabled = false;
-  
-  Mapper userNameRegExInst = null;
-  Mapper groupNameRegExInst = null;
+
   private Map<String, UserInfo> userGroupMap;
   
 	public static void main(String[] args) throws Throwable {
@@ -111,6 +106,7 @@ public class LdapUserGroupBuilder implements UserGroupSource {
 	}
 	
 	public LdapUserGroupBuilder() {
+		super();
 		LOG.info("LdapUserGroupBuilder created") ;
 		
 		String userNameCaseConversion = config.getUserNameCaseConversion() ;
@@ -132,41 +128,6 @@ public class LdapUserGroupBuilder implements UserGroupSource {
 		    groupNameCaseConversionFlag = true ;
 		    groupNameLowerCaseFlag = UserGroupSyncConfig.UGSYNC_LOWER_CASE_CONVERSION_VALUE.equalsIgnoreCase(groupNameCaseConversion)
;
 		}
-		
-		String mappingUserNameHandler = config.getUserSyncMappingUserNameHandler();
-		try {
-			if (mappingUserNameHandler != null) {
-				Class<Mapper> regExClass = (Class<Mapper>)Class.forName(mappingUserNameHandler);
-				userNameRegExInst = regExClass.newInstance();
-				if (userNameRegExInst != null) {
-					userNameRegExInst.init(UserGroupSyncConfig.SYNC_MAPPING_USERNAME);
-				} else {
-					LOG.error("RegEx handler instance for username is null!");
-				}
-			}
-		} catch (ClassNotFoundException cne) {
-			LOG.error("Failed to load " + mappingUserNameHandler + " " + cne);
-		} catch (Throwable te) {
-			LOG.error("Failed to instantiate " + mappingUserNameHandler + " " + te);
-		}
-
-		String mappingGroupNameHandler = config.getUserSyncMappingGroupNameHandler();
-		try {
-			if (mappingGroupNameHandler != null) {
-				Class<Mapper> regExClass = (Class<Mapper>)Class.forName(mappingGroupNameHandler);
-				groupNameRegExInst = regExClass.newInstance();
-				if (groupNameRegExInst != null) {
-					groupNameRegExInst.init(UserGroupSyncConfig.SYNC_MAPPING_GROUPNAME);
-				} else {
-					LOG.error("RegEx handler instance for groupname is null!");
-				}
-			}
-		} catch (ClassNotFoundException cne) {
-			LOG.error("Failed to load " + mappingGroupNameHandler + " " + cne);
-		} catch (Throwable te) {
-			LOG.error("Failed to instantiate " + mappingGroupNameHandler + " " + te);
-		}
-		
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/main/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilder.java
b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilder.java
index 312f383..54e47f6 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilder.java
@@ -32,6 +32,7 @@ import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.log4j.Logger;
 import org.apache.ranger.unixusersync.config.UserGroupSyncConfig;
+import org.apache.ranger.usergroupsync.AbstractUserGroupSource;
 import org.apache.ranger.usergroupsync.UserGroupSink;
 import org.apache.ranger.usergroupsync.UserGroupSource;
 
@@ -39,11 +40,10 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.stream.JsonReader;
 
-public class FileSourceUserGroupBuilder  implements UserGroupSource {
+public class FileSourceUserGroupBuilder extends AbstractUserGroupSource {
 	private static final Logger LOG = Logger.getLogger(FileSourceUserGroupBuilder.class) ;
 
 	private Map<String,List<String>> user2GroupListMap     = new HashMap<String,List<String>>();
-	private UserGroupSyncConfig      config                = UserGroupSyncConfig.getInstance();
 	private String                   userGroupFilename     = null;
 	private long                     usergroupFileModified = 0 ;
 
@@ -67,6 +67,10 @@ public class FileSourceUserGroupBuilder  implements UserGroupSource {
 			filesourceUGBuilder.print(); 
 		}
 	}
+
+	public FileSourceUserGroupBuilder() {
+		super();
+	}
 	
 	@Override
 	public void init() throws Throwable {
@@ -91,9 +95,22 @@ public class FileSourceUserGroupBuilder  implements UserGroupSource {
 		buildUserGroupInfo();
 
 		for (Map.Entry<String, List<String>> entry : user2GroupListMap.entrySet())
{
-		    String       user   = entry.getKey();
+		    String user = entry.getKey();
+
+			if (userNameRegExInst != null) {
+				user = userNameRegExInst.transform(user);
+			}
+
 		    List<String> groups = entry.getValue();
 
+			if (groupNameRegExInst != null) {
+				List<String> mappedGroups = new ArrayList<>();
+				for (String group : groups) {
+					mappedGroups.add(groupNameRegExInst.transform(group));
+				}
+				groups = mappedGroups;
+			}
+
 		    sink.addOrUpdateUser(user, groups);
 		}
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/main/java/org/apache/ranger/usergroupsync/AbstractUserGroupSource.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/usergroupsync/AbstractUserGroupSource.java
b/ugsync/src/main/java/org/apache/ranger/usergroupsync/AbstractUserGroupSource.java
new file mode 100644
index 0000000..4a54e57
--- /dev/null
+++ b/ugsync/src/main/java/org/apache/ranger/usergroupsync/AbstractUserGroupSource.java
@@ -0,0 +1,70 @@
+/*
+ * 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.ranger.usergroupsync;
+
+import org.apache.log4j.Logger;
+import org.apache.ranger.unixusersync.config.UserGroupSyncConfig;
+
+public abstract class AbstractUserGroupSource implements UserGroupSource {
+
+    private static final Logger LOG = Logger.getLogger(AbstractUserGroupSource.class);
+
+    protected UserGroupSyncConfig config = UserGroupSyncConfig.getInstance();
+
+    protected Mapper userNameRegExInst = null;
+    protected Mapper groupNameRegExInst = null;
+
+
+    public AbstractUserGroupSource() {
+        String mappingUserNameHandler = config.getUserSyncMappingUserNameHandler();
+        try {
+            if (mappingUserNameHandler != null) {
+                Class<Mapper> regExClass = (Class<Mapper>)Class.forName(mappingUserNameHandler);
+                userNameRegExInst = regExClass.newInstance();
+                if (userNameRegExInst != null) {
+                    userNameRegExInst.init(UserGroupSyncConfig.SYNC_MAPPING_USERNAME);
+                } else {
+                    LOG.error("RegEx handler instance for username is null!");
+                }
+            }
+        } catch (ClassNotFoundException cne) {
+            LOG.error("Failed to load " + mappingUserNameHandler + " " + cne);
+        } catch (Throwable te) {
+            LOG.error("Failed to instantiate " + mappingUserNameHandler + " " + te);
+        }
+
+        String mappingGroupNameHandler = config.getUserSyncMappingGroupNameHandler();
+        try {
+            if (mappingGroupNameHandler != null) {
+                Class<Mapper> regExClass = (Class<Mapper>)Class.forName(mappingGroupNameHandler);
+                groupNameRegExInst = regExClass.newInstance();
+                if (groupNameRegExInst != null) {
+                    groupNameRegExInst.init(UserGroupSyncConfig.SYNC_MAPPING_GROUPNAME);
+                } else {
+                    LOG.error("RegEx handler instance for groupname is null!");
+                }
+            }
+        } catch (ClassNotFoundException cne) {
+            LOG.error("Failed to load " + mappingGroupNameHandler + " " + cne);
+        } catch (Throwable te) {
+            LOG.error("Failed to instantiate " + mappingGroupNameHandler + " " + te);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilderTest.java
----------------------------------------------------------------------
diff --git a/ugsync/src/test/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilderTest.java
b/ugsync/src/test/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilderTest.java
new file mode 100644
index 0000000..65a339c
--- /dev/null
+++ b/ugsync/src/test/java/org/apache/ranger/unixusersync/process/FileSourceUserGroupBuilderTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.ranger.unixusersync.process;
+
+import static org.junit.Assert.*;
+
+import org.apache.ranger.unixusersync.config.UserGroupSyncConfig;
+import org.apache.ranger.usergroupsync.PolicyMgrUserGroupBuilderTest;
+import org.junit.Test;
+
+public class FileSourceUserGroupBuilderTest {
+
+    private UserGroupSyncConfig config = UserGroupSyncConfig.getInstance();
+
+    @Test
+    public void testUpdateSinkFromCsvFile() throws Throwable {
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_PROC, "src/test/resources/usergroups.csv");
+
+        FileSourceUserGroupBuilder fileBuilder = new FileSourceUserGroupBuilder();
+        fileBuilder.init();
+
+        PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+        sink.init();
+        fileBuilder.updateSink(sink);
+
+        assertEquals(4, sink.getTotalUsers());
+        assertEquals(2, sink.getTotalGroups());
+
+        assertTrue(sink.getAllUsers().contains("user1"));
+        assertTrue(sink.getAllUsers().contains("user2"));
+        assertTrue(sink.getAllUsers().contains("user3"));
+        assertTrue(sink.getAllUsers().contains("user4"));
+
+        assertTrue(sink.getAllGroups().contains("group1"));
+        assertTrue(sink.getAllGroups().contains("group2"));
+    }
+
+    @Test
+    public void testUpdateSinkFromCsvFileWithCustomDelimiter() throws Throwable {
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_PROC,
+                "src/test/resources/usergroups-other-delim.csv");
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_DELIMITER, "|");
+
+        FileSourceUserGroupBuilder fileBuilder = new FileSourceUserGroupBuilder();
+        fileBuilder.init();
+
+        PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+        sink.init();
+        fileBuilder.updateSink(sink);
+
+        assertEquals(4, sink.getTotalUsers());
+        assertEquals(2, sink.getTotalGroups());
+
+        assertTrue(sink.getAllUsers().contains("user1"));
+        assertTrue(sink.getAllUsers().contains("user2"));
+        assertTrue(sink.getAllUsers().contains("user3"));
+        assertTrue(sink.getAllUsers().contains("user4"));
+
+        assertTrue(sink.getAllGroups().contains("group1"));
+        assertTrue(sink.getAllGroups().contains("group2"));
+    }
+
+    @Test
+    public void testUpdateSinkFromCsvFileMisSpelledDelimiterProperty() throws Throwable {
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_PROC,
+                "src/test/resources/usergroups-other-delim.csv");
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_DELIMITERER, "|");
+
+        FileSourceUserGroupBuilder fileBuilder = new FileSourceUserGroupBuilder();
+        fileBuilder.init();
+
+        PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+        sink.init();
+        fileBuilder.updateSink(sink);
+
+        assertEquals(4, sink.getTotalUsers());
+        assertEquals(2, sink.getTotalGroups());
+
+        assertTrue(sink.getAllUsers().contains("user1"));
+        assertTrue(sink.getAllUsers().contains("user2"));
+        assertTrue(sink.getAllUsers().contains("user3"));
+        assertTrue(sink.getAllUsers().contains("user4"));
+
+        assertTrue(sink.getAllGroups().contains("group1"));
+        assertTrue(sink.getAllGroups().contains("group2"));
+    }
+
+    @Test
+    public void testUpdateSinkFromJsonFile() throws Throwable {
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_PROC, "src/test/resources/usergroups.json");
+
+        FileSourceUserGroupBuilder fileBuilder = new FileSourceUserGroupBuilder();
+        fileBuilder.init();
+
+        PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+        sink.init();
+        fileBuilder.updateSink(sink);
+
+        assertEquals(4, sink.getTotalUsers());
+        assertEquals(7, sink.getTotalGroups());
+
+        assertTrue(sink.getAllUsers().contains("user1"));
+        assertTrue(sink.getAllUsers().contains("user2"));
+        assertTrue(sink.getAllUsers().contains("user3"));
+        assertTrue(sink.getAllUsers().contains("user4"));
+
+        assertTrue(sink.getAllGroups().contains("group1"));
+        assertTrue(sink.getAllGroups().contains("group2"));
+        assertTrue(sink.getAllGroups().contains("group3"));
+        assertTrue(sink.getAllGroups().contains("group4"));
+        assertTrue(sink.getAllGroups().contains("group5"));
+        assertTrue(sink.getAllGroups().contains("group6"));
+        assertTrue(sink.getAllGroups().contains("group7"));
+    }
+
+    @Test
+    public void testUpdateSinkWithUserAndGroupMapping() throws Throwable {
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_PROC, "src/test/resources/usergroups-dns.csv");
+        config.setProperty(UserGroupSyncConfig.UGSYNC_SOURCE_FILE_DELIMITERER, "|");
+
+        config.setProperty(UserGroupSyncConfig.SYNC_MAPPING_USERNAME, "s/[=]/_/g");
+        config.setProperty(UserGroupSyncConfig.SYNC_MAPPING_USERNAME + ".1", "s/[,]//g");
+
+        config.setProperty(UserGroupSyncConfig.SYNC_MAPPING_GROUPNAME, "s/[=]//g");
+
+        FileSourceUserGroupBuilder fileBuilder = new FileSourceUserGroupBuilder();
+        fileBuilder.init();
+
+        PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+        sink.init();
+        fileBuilder.updateSink(sink);
+
+        assertEquals(4, sink.getTotalUsers());
+        assertEquals(2, sink.getTotalGroups());
+
+        assertTrue(sink.getAllUsers().contains("CN_User1 OU_Org1 O_Apache L_Santa Monica
ST_CA C_US"));
+        assertTrue(sink.getAllUsers().contains("CN_User2 OU_Org1 O_Apache L_Santa Monica
ST_CA C_US"));
+        assertTrue(sink.getAllUsers().contains("CN_User3 OU_Org1 O_Apache L_Santa Monica
ST_CA C_US"));
+        assertTrue(sink.getAllUsers().contains("CN_User4 OU_Org1 O_Apache L_Santa Monica
ST_CA C_US"));
+
+        assertTrue(sink.getAllGroups().contains("group1"));
+        assertTrue(sink.getAllGroups().contains("group2"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/java/org/apache/ranger/usergroupsync/LdapUserGroupTest.java
----------------------------------------------------------------------
diff --git a/ugsync/src/test/java/org/apache/ranger/usergroupsync/LdapUserGroupTest.java b/ugsync/src/test/java/org/apache/ranger/usergroupsync/LdapUserGroupTest.java
index b285e78..4355c4d 100644
--- a/ugsync/src/test/java/org/apache/ranger/usergroupsync/LdapUserGroupTest.java
+++ b/ugsync/src/test/java/org/apache/ranger/usergroupsync/LdapUserGroupTest.java
@@ -20,6 +20,7 @@
 package org.apache.ranger.usergroupsync;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 import org.apache.directory.server.annotations.CreateLdapConnectionPool;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
@@ -39,7 +40,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import org.apache.directory.server.core.annotations.CreateIndex;
-import org.apache.ranger.usergroupsync.PolicyMgrUserGroupBuilderTest;
 
 @RunWith(FrameworkRunner.class)
 @CreateDS(name = "classDS",
@@ -484,6 +484,38 @@ public class LdapUserGroupTest extends AbstractLdapTestUnit{
 		assertEquals(3, sink.getTotalGroups());
 	}
 
+	@Test
+	public void testUpdateSinkWithUserGroupMapping() throws Throwable {
+		config.setUserSearchBase("cn=users,DC=ranger,DC=qe,DC=hortonworks,DC=com");
+		config.setUserSearchFilter("");
+		config.setGroupSearchBase("OU=Groups,DC=ranger,DC=qe,DC=hortonworks,DC=com");
+		config.setGroupSearchFilter("");
+		config.setUserGroupMemberAttributeName("member");
+		config.setUserObjectClass("organizationalPerson");
+		config.setGroupObjectClass("groupOfNames");
+		config.setGroupSearchEnabled(true);
+		config.setGroupSearchFirstEnabled(false);
+
+		config.setProperty(UserGroupSyncConfig.SYNC_MAPPING_USERNAME, "s/[=]/_/g");
+		config.setProperty(UserGroupSyncConfig.SYNC_MAPPING_GROUPNAME, "s/[=]/_/g");
+
+		ldapBuilder.init();
+		PolicyMgrUserGroupBuilderTest sink = new PolicyMgrUserGroupBuilderTest();
+		sink.init();
+		ldapBuilder.updateSink(sink);
+		assertEquals(10, sink.getTotalGroups());
+
+		// no user should have an = character because of the mapping
+		for (String user : sink.getAllUsers()) {
+			assertFalse(user.contains("="));
+		}
+
+		// no group should have an = character because of the mapping
+		for (String group : sink.getAllGroups()) {
+			assertFalse(group.contains("="));
+		}
+	}
+
 	@After
 	public void shutdown() throws Exception {
 		if (getService().isStarted()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/java/org/apache/ranger/usergroupsync/PolicyMgrUserGroupBuilderTest.java
----------------------------------------------------------------------
diff --git a/ugsync/src/test/java/org/apache/ranger/usergroupsync/PolicyMgrUserGroupBuilderTest.java
b/ugsync/src/test/java/org/apache/ranger/usergroupsync/PolicyMgrUserGroupBuilderTest.java
index 0d817f6..2880bcb 100644
--- a/ugsync/src/test/java/org/apache/ranger/usergroupsync/PolicyMgrUserGroupBuilderTest.java
+++ b/ugsync/src/test/java/org/apache/ranger/usergroupsync/PolicyMgrUserGroupBuilderTest.java
@@ -26,32 +26,29 @@ import java.util.Set;
 import org.apache.ranger.unixusersync.process.PolicyMgrUserGroupBuilder;
 
 public class PolicyMgrUserGroupBuilderTest extends PolicyMgrUserGroupBuilder {
-        private static int totalUsers = 0;
-        //private static int totalGroups = 0;
         private Set<String> allGroups;
+        private Set<String> allUsers;
 
         @Override
         public void init() throws Throwable {
-                // TODO Auto-generated method stub
-                totalUsers = 0;
                 allGroups = new HashSet<>();
+                allUsers = new HashSet<>();
         }
 
         @Override
         public void addOrUpdateUser(String user, List<String> groups) {
-                totalUsers++;
                 allGroups.addAll(groups);
+                allUsers.add(user);
                 //System.out.println("Username: " + user + " and associated groups: " + groups);
         }
         
         @Override
         public void addOrUpdateGroup(String group) {
-                //totalGroups++;
                 allGroups.add(group);
         }
 
         public int getTotalUsers() {
-                return totalUsers;
+                return allUsers.size();
         }
 
         public int getTotalGroups() {
@@ -59,4 +56,11 @@ public class PolicyMgrUserGroupBuilderTest extends PolicyMgrUserGroupBuilder
{
                 return allGroups.size();
         }
 
+        public Set<String> getAllGroups() {
+                return allGroups;
+        }
+
+        public Set<String> getAllUsers() {
+                return allUsers;
+        }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/resources/usergroups-dns.csv
----------------------------------------------------------------------
diff --git a/ugsync/src/test/resources/usergroups-dns.csv b/ugsync/src/test/resources/usergroups-dns.csv
new file mode 100644
index 0000000..d6fc5a8
--- /dev/null
+++ b/ugsync/src/test/resources/usergroups-dns.csv
@@ -0,0 +1,4 @@
+CN=User1, OU=Org1, O=Apache, L=Santa Monica, ST=CA, C=US|group=1
+CN=User2, OU=Org1, O=Apache, L=Santa Monica, ST=CA, C=US|group=2
+CN=User3, OU=Org1, O=Apache, L=Santa Monica, ST=CA, C=US|group=1|group=2
+CN=User4, OU=Org1, O=Apache, L=Santa Monica, ST=CA, C=US|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/resources/usergroups-other-delim.csv
----------------------------------------------------------------------
diff --git a/ugsync/src/test/resources/usergroups-other-delim.csv b/ugsync/src/test/resources/usergroups-other-delim.csv
new file mode 100644
index 0000000..6a00ebf
--- /dev/null
+++ b/ugsync/src/test/resources/usergroups-other-delim.csv
@@ -0,0 +1,4 @@
+user1|group1
+user2|group2
+user3|group1|group2
+user4|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/resources/usergroups.csv
----------------------------------------------------------------------
diff --git a/ugsync/src/test/resources/usergroups.csv b/ugsync/src/test/resources/usergroups.csv
new file mode 100644
index 0000000..27770cd
--- /dev/null
+++ b/ugsync/src/test/resources/usergroups.csv
@@ -0,0 +1,4 @@
+user1,group1
+user2,group2
+user3,group1,group2
+user4,
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ec749f09/ugsync/src/test/resources/usergroups.json
----------------------------------------------------------------------
diff --git a/ugsync/src/test/resources/usergroups.json b/ugsync/src/test/resources/usergroups.json
new file mode 100644
index 0000000..100b97a
--- /dev/null
+++ b/ugsync/src/test/resources/usergroups.json
@@ -0,0 +1,6 @@
+{
+  "user1":["group1","group2","group3","group4"],
+  "user2":["group5","group6","group7"],
+  "user3":[],
+  "user4":["group1","group6"]
+}
\ No newline at end of file


Mime
View raw message