ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject [4/5] git commit: ARGUS-138: Fixed the bug that caused code to let some of the users with userid below MIN_UNIX_USER_ID_TO_SYNC
Date Fri, 31 Oct 2014 21:02:26 GMT
ARGUS-138: Fixed the bug that caused code to let some of the users with userid below MIN_UNIX_USER_ID_TO_SYNC

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


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

Branch: refs/heads/argus2ranger
Commit: fa2ff5ae72077b5b6f764a6386c15c661570d6b8
Parents: 38c3594
Author: Alok Lal <alal@hortonworks.com>
Authored: Wed Oct 29 10:38:17 2014 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Thu Oct 30 19:07:39 2014 -0700

----------------------------------------------------------------------
 .../process/UnixUserGroupBuilder.java           | 41 ++++++++------------
 1 file changed, 17 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/fa2ff5ae/ugsync/src/main/java/com/xasecure/unixusersync/process/UnixUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/com/xasecure/unixusersync/process/UnixUserGroupBuilder.java
b/ugsync/src/main/java/com/xasecure/unixusersync/process/UnixUserGroupBuilder.java
index b457e7a..8d4af61 100644
--- a/ugsync/src/main/java/com/xasecure/unixusersync/process/UnixUserGroupBuilder.java
+++ b/ugsync/src/main/java/com/xasecure/unixusersync/process/UnixUserGroupBuilder.java
@@ -42,8 +42,8 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 
 	private UserGroupSyncConfig config = UserGroupSyncConfig.getInstance() ;
 	private Map<String,List<String>>  	user2GroupListMap = new HashMap<String,List<String>>();
+	private Map<String,List<String>>  	internalUser2GroupListMap = new HashMap<String,List<String>>();
 	private Map<String,String>			groupId2groupNameMap = new HashMap<String,String>()
;
-	private List<String>				userList = new ArrayList<String>() ;
 	private int 						minimumUserId  = 0 ;
 	
 	private long  passwordFileModiiedAt = 0 ;
@@ -98,7 +98,6 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 	private void buildUserGroupInfo() throws Throwable {
 		user2GroupListMap = new HashMap<String,List<String>>();
 		groupId2groupNameMap = new HashMap<String,String>() ;
-		userList = new ArrayList<String>() ;
 
 		buildUnixGroupList(); 
 		buildUnixUserList();
@@ -107,8 +106,8 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 		}
 	}
 	
-	public void print() {
-		for(String user : userList) {
+	private void print() {
+		for(String user : user2GroupListMap.keySet()) {
 			LOG.debug("USER:" + user) ;
 			List<String> groups = user2GroupListMap.get(user) ;
 			if (groups != null) {
@@ -119,14 +118,6 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 		}
 	}
 	
-	private List<String>  getUserList() {
-		return userList ;
-	}
-	
-	private List<String>  getGroupListForUser(String aUserName) {
-		return user2GroupListMap.get(aUserName) ;
-	}
-	
 	private void buildUnixUserList() throws Throwable {
 		
 		File f = new File(UNIX_USER_PASSWORD_FILE) ;
@@ -168,22 +159,24 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 				}
 									
 				if (numUserId >= minimumUserId ) {
-					userList.add(userName) ;
 					String groupName = groupId2groupNameMap.get(groupId) ;
 					if (groupName != null) {
-						List<String> groupList = user2GroupListMap.get(userName) ;
-						if (groupList == null) {
-							groupList = new ArrayList<String>() ;
-							user2GroupListMap.put(userName, groupList) ;
-						}
-						if (! groupList.contains(groupName)) {
-							groupList.add(groupName) ;
+						List<String> groupList = new ArrayList<String>();
+						groupList.add(groupName);
+						// do we already know about this use's membership to other groups?  If so add those,
too
+						if (internalUser2GroupListMap.containsKey(userName)) {
+							groupList.addAll(internalUser2GroupListMap.get(userName));
 						}
+						user2GroupListMap.put(userName, groupList);
 					}
 					else {
-						LOG.warn("Group Name could not be found for group id: [" + groupId + "]") ;
+						// we are ignoring the possibility that this user was present in /etc/groups.
+						LOG.warn("Group Name could not be found for group id: [" + groupId + "]. Skipping adding
user [" + userName + "] with id [" + userId + "].") ;
 					}
 				}
+				else {
+					LOG.debug("Skipping user [" + userName + "] since its userid [" + userId + "] is less
than minuserid limit [" + minimumUserId + "].");
+				}
 			}
 			
 			reader.close() ;
@@ -234,13 +227,13 @@ public class UnixUserGroupBuilder implements UserGroupSource {
 				}
 				
 				groupId2groupNameMap.put(groupId,groupName) ;
-				
+				// also build an internal map of users to their group list which is consulted by user
list creator
 				if (groupMembers != null && ! groupMembers.trim().isEmpty()) {
 					for(String user : groupMembers.split(",")) {
-						List<String> groupList = user2GroupListMap.get(user) ;
+						List<String> groupList = internalUser2GroupListMap.get(user) ;
 						if (groupList == null) {
 							groupList = new ArrayList<String>() ;
-							user2GroupListMap.put(user, groupList) ;
+							internalUser2GroupListMap.put(user, groupList) ;
 						}
 						if (! groupList.contains(groupName)) {
 							groupList.add(groupName) ;


Mime
View raw message