ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject ranger git commit: RANGER-1971 - Switch to use for-each loops
Date Mon, 05 Feb 2018 14:57:36 GMT
Repository: ranger
Updated Branches:
  refs/heads/master dab9ed6e0 -> 75b8a422c


RANGER-1971 - Switch to use for-each loops


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

Branch: refs/heads/master
Commit: 75b8a422cfe8ab8f9896720a98ac8bd739c065a1
Parents: dab9ed6
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon Feb 5 14:57:20 2018 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Mon Feb 5 14:57:20 2018 +0000

----------------------------------------------------------------------
 .../audit/provider/hdfs/HdfsLogDestination.java |   8 +-
 .../ranger/audit/queue/AuditFileSpool.java      |   3 +-
 .../ranger/plugin/geo/GeolocationMetadata.java  |   4 +-
 .../plugin/geo/RangerGeolocationData.java       |   4 +-
 .../plugin/policyengine/TestCacheMap.java       |  12 +-
 .../apache/ranger/credentialapi/buildks.java    |   4 +-
 .../hbase/RangerAuthorizationCoprocessor.java   |   6 +-
 .../hive/authorizer/RangerHiveAuthorizer.java   |   4 +-
 .../main/java/org/apache/util/sql/Jisql.java    |  18 +-
 .../crypto/key/kms/server/KMSMetricUtil.java    |   4 +-
 .../services/solr/client/ServiceSolrClient.java |   6 +-
 .../java/org/apache/ranger/biz/AssetMgr.java    |  36 +-
 .../java/org/apache/ranger/biz/UserMgr.java     |   8 +-
 .../org/apache/ranger/common/RESTErrorUtil.java |   4 +-
 .../org/apache/ranger/common/StringUtil.java    |   4 +-
 .../apache/ranger/patch/cliutil/MetricUtil.java |  18 +-
 .../org/apache/ranger/service/UserService.java  |   6 +-
 .../service/filter/RangerRESTAPIFilter.java     |  14 +-
 .../org/apache/ranger/util/RangerRestUtil.java  |  10 +-
 .../process/LdapUserGroupBuilder.java           |  35 +-
 .../process/PolicyMgrUserGroupBuilder.java      | 359 ++++++++++---------
 21 files changed, 278 insertions(+), 289 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/agents-audit/src/main/java/org/apache/ranger/audit/provider/hdfs/HdfsLogDestination.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/provider/hdfs/HdfsLogDestination.java b/agents-audit/src/main/java/org/apache/ranger/audit/provider/hdfs/HdfsLogDestination.java
index 065e8b0..be31a9a 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/provider/hdfs/HdfsLogDestination.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/provider/hdfs/HdfsLogDestination.java
@@ -168,8 +168,8 @@ public class HdfsLogDestination<T> implements LogDestination<T> {
 	
 	@Override
 	public boolean send(AuditEventBase[] logs) {
-		for(int i = 0; i < logs.length; i++) {
-			boolean ret = send(logs[i]);
+		for (AuditEventBase log : logs) {
+			boolean ret = send(log);
 			if(!ret) {
 				return ret;
 			}
@@ -202,8 +202,8 @@ public class HdfsLogDestination<T> implements LogDestination<T> {
 
 	@Override
 	public boolean sendStringified(String[] logs) {
-		for(int i = 0; i < logs.length; i++) {
-			boolean ret = sendStringified(logs[i]);
+		for (String log : logs) {
+			boolean ret = sendStringified(log);
 			if(!ret) {
 				return ret;
 			}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
index 9abd99f..cbd819d 100644
--- a/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
+++ b/agents-audit/src/main/java/org/apache/ranger/audit/queue/AuditFileSpool.java
@@ -269,8 +269,7 @@ public class AuditFileSpool implements Runnable {
 				}
 			}
 			printIndex();
-			for (int i = 0; i < indexRecords.size(); i++) {
-				AuditIndexRecord auditIndexRecord = indexRecords.get(i);
+			for (AuditIndexRecord auditIndexRecord : indexRecords) {
 				if (auditIndexRecord.status.equals(SPOOL_FILE_STATUS.pending)) {
 					File consumerFile = new File(auditIndexRecord.filePath);
 					if (!consumerFile.exists()) {

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/agents-common/src/main/java/org/apache/ranger/plugin/geo/GeolocationMetadata.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/geo/GeolocationMetadata.java b/agents-common/src/main/java/org/apache/ranger/plugin/geo/GeolocationMetadata.java
index d27a030..1142dcc 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/geo/GeolocationMetadata.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/geo/GeolocationMetadata.java
@@ -82,8 +82,8 @@ public class GeolocationMetadata {
 	private StringBuilder toStringDump(StringBuilder sb) {
 		sb.append("FROM_IP,TO_IP,");
 
-		for (int i = 0; i < locationDataItemNames.length; i++) {
-			sb.append(locationDataItemNames[i]).append(", ");
+		for (String locationDataItemName : locationDataItemNames) {
+			sb.append(locationDataItemName).append(", ");
 		}
 
 		return sb;

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/agents-common/src/main/java/org/apache/ranger/plugin/geo/RangerGeolocationData.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/geo/RangerGeolocationData.java b/agents-common/src/main/java/org/apache/ranger/plugin/geo/RangerGeolocationData.java
index 99d6027..869d316 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/geo/RangerGeolocationData.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/geo/RangerGeolocationData.java
@@ -212,8 +212,8 @@ public class RangerGeolocationData implements Comparable<RangerGeolocationData>,
 				.append(", to=")
 				.append(RangerGeolocationData.unsignedIntToIPAddress(toIPAddress))
 				.append(", location={");
-			for (int i = 0; i < locationData.length; i++) {
-				sb.append(locationData[i]).append(", ");
+			for (String data : locationData) {
+				sb.append(data).append(", ");
 			}
 				sb.append("}");
 		sb.append("}");

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java
----------------------------------------------------------------------
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java
index 5f39b22..db8b813 100644
--- a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java
+++ b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java
@@ -25,7 +25,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.util.Iterator;
 import java.util.Set;
 
 public class TestCacheMap {
@@ -100,21 +99,16 @@ public class TestCacheMap {
 
 		Set<String> keySet = testCacheMap.keySet();
 
-		int i = 0;
-
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("TestCacheMap.runTests(), KeySet Size:" + keySet.size());
 			LOG.debug("TestCacheMap.runTests(), printing keys..");
-		}
 
-		for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
-			String key = iterator.next();
-			if (LOG.isDebugEnabled()) {
+		    int i = 0;
+
+		    for (String key : keySet) {
 				LOG.debug("TestCacheMap.runTests(), index:" + i++ + ", key:" + key);
 			}
-		}
 
-		if(LOG.isDebugEnabled()) {
 			LOG.debug("<== TestCacheMap.runTests()");
 		}
 

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
----------------------------------------------------------------------
diff --git a/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java b/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
index b8bdb6f..cb391cc 100644
--- a/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
+++ b/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
@@ -399,8 +399,8 @@ public class buildks {
 		if (debugOption != null && "TRUE".equalsIgnoreCase(debugOption)) {
 			StringBuilder tempBuffer=new StringBuilder("");
 			if(args!=null && args.length>0){
-				for(int index=0;index<args.length;index++){
-					tempBuffer.append(args[index]+" ");
+				for (String arg : args) {
+					tempBuffer.append(arg).append(" ");
 				}
 				System.out.println("Command to execute:["+tempBuffer+"]");
 			}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
index e30f795..058168f 100644
--- a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
+++ b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
@@ -1339,8 +1339,8 @@ public class RangerAuthorizationCoprocessor extends RangerAuthorizationCoprocess
 			ret.getUsers().add(userName);
 		}
 
-		for (int i = 0; i < actions.length; i++) {
-			switch(actions[i].code()) {
+		for (Permission.Action action : actions) {
+			switch(action.code()) {
 				case 'R':
 					ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_READ);
 				break;
@@ -1359,7 +1359,7 @@ public class RangerAuthorizationCoprocessor extends RangerAuthorizationCoprocess
 				break;
 
 				default:
-					LOG.warn("grant(): ignoring action '" + actions[i].name() + "' for user '" + userName + "'");
+					LOG.warn("grant(): ignoring action '" + action.name() + "' for user '" + userName + "'");
 			}
 		}
 

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizer.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizer.java b/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizer.java
index fa84b13..2c2a518 100644
--- a/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizer.java
+++ b/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizer.java
@@ -1290,8 +1290,8 @@ public class RangerHiveAuthorizer extends RangerHiveAuthorizerBase {
 		boolean ret = false;
 		String[] fsScheme = hivePlugin.getFSScheme();
 		if (fsScheme != null) {
-			for (int i = 0; i < fsScheme.length; i++) {
-				if (!uri.isEmpty() && uri.startsWith(fsScheme[i])) {
+			for (String scheme : fsScheme) {
+				if (!uri.isEmpty() && uri.startsWith(scheme)) {
 					ret = true;
 					break;
 				}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/jisql/src/main/java/org/apache/util/sql/Jisql.java
----------------------------------------------------------------------
diff --git a/jisql/src/main/java/org/apache/util/sql/Jisql.java b/jisql/src/main/java/org/apache/util/sql/Jisql.java
index 53a6ca4..9746a9a 100644
--- a/jisql/src/main/java/org/apache/util/sql/Jisql.java
+++ b/jisql/src/main/java/org/apache/util/sql/Jisql.java
@@ -555,18 +555,18 @@ public class Jisql {
         System.out.println("driver.getMinorVersion() is " + driver.getMinorVersion());
         System.out.println("driver is " + (driver.jdbcCompliant() ? "" : "not ") + "JDBC compliant");
 
-        DriverPropertyInfo info[] = driver.getPropertyInfo(connectString, props);
+        DriverPropertyInfo[] infos = driver.getPropertyInfo(connectString, props);
 
-        for (int i = 0; i < info.length; i++) {
-            System.out.println("driver property named \"" + info[i].name + "\"");
-            if (info[i].choices != null) {
+        for (DriverPropertyInfo info : infos) {
+            System.out.println("driver property named \"" + info.name + "\"");
+            if (info.choices != null) {
                 System.out.println("choices:");
-                for (int j = 0; j < info[i].choices.length; j++)
-                    System.out.println("\tchoice " + j + ": \"" + info[i].choices[j] + "\"");
+                for (int j = 0; j < info.choices.length; j++)
+                    System.out.println("\tchoice " + j + ": \"" + info.choices[j] + "\"");
             }
-            System.out.println("description: \"" + info[i].description + "\"");
-            System.out.println("required parameter?: \"" + info[i].required + "\"");
-            System.out.println("current value: \"" + info[i].value + "\"\n");
+            System.out.println("description: \"" + info.description + "\"");
+            System.out.println("required parameter?: \"" + info.required + "\"");
+            System.out.println("current value: \"" + info.value + "\"\n");
         }
 
         DatabaseMetaData metaData = connection.getMetaData();

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMetricUtil.java
----------------------------------------------------------------------
diff --git a/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMetricUtil.java b/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMetricUtil.java
index 1527681..925d2c7 100644
--- a/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMetricUtil.java
+++ b/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSMetricUtil.java
@@ -121,8 +121,8 @@ public class KMSMetricUtil {
 							List<String> keyList = new ArrayList<String>();
 							keyList.addAll(keyProvider.getKeys());
 							if (keyList != null) {								
-								for (int i = 0; i < keyList.size(); i++) {
-									String algorithmName = keyProvider.getMetadata(keyList.get(i)).getCipher();
+								for (String key : keyList) {
+									String algorithmName = keyProvider.getMetadata(key).getCipher();
 									if (encryptedKeyByAlgorithmCountMap.containsKey(algorithmName)) {
 										count = encryptedKeyByAlgorithmCountMap.get(algorithmName);
 										count += 1;

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java
----------------------------------------------------------------------
diff --git a/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java b/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java
index 5875a29..d2f9055 100644
--- a/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java
+++ b/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java
@@ -115,10 +115,10 @@ public class ServiceSolrClient {
 		if(CollectionUtils.isEmpty(responseCollectionList)) {
 			return list;
 		}
-		for (int i = 0; i < responseCollectionList.size(); i++) {
+		for (String responseCollection : responseCollectionList) {
 			if (ignoreCollectionList == null
-					|| !ignoreCollectionList.contains(responseCollectionList.get(i))) {
-				list.add(responseCollectionList.get(i));
+					|| !ignoreCollectionList.contains(responseCollection)) {
+				list.add(responseCollection);
 			}
 		}
 		return list;

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java
index a53d46a..034053d 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java
@@ -1020,18 +1020,18 @@ public class AssetMgr extends AssetMgrBase {
 				if(vXTrxLog.getPreviousValue() != null && vXTrxLog.getPreviousValue().contains("password")) {
 					String tempPreviousStr = vXTrxLog.getPreviousValue();
 					String tempPreviousArr[] = vXTrxLog.getPreviousValue().split(",");
-					for(int i = 0; i < tempPreviousArr.length; i++) {
-						if(tempPreviousArr[i].contains("{\"password") && tempPreviousArr[i].contains("}")) {
-							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPreviousArr[i],"{\"password\":\"*****\"}"));
+					for (String tempPrevious : tempPreviousArr) {
+						if(tempPrevious.contains("{\"password") && tempPrevious.contains("}")) {
+							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPrevious,"{\"password\":\"*****\"}"));
 							break;
-						} else if(tempPreviousArr[i].contains("{\"password")) {
-							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPreviousArr[i], "{\"password\":\"*****\""));
+						} else if(tempPrevious.contains("{\"password")) {
+							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPrevious, "{\"password\":\"*****\""));
 							break;
-						} else if(tempPreviousArr[i].contains("\"password") && tempPreviousArr[i].contains("}")) {
-							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPreviousArr[i], "\"password\":\"******\"}"));
+						} else if(tempPrevious.contains("\"password") && tempPrevious.contains("}")) {
+							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPrevious, "\"password\":\"******\"}"));
 							break;
-						} else if(tempPreviousArr[i].contains("\"password")) {
-							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPreviousArr[i], "\"password\":\"******\""));
+						} else if(tempPrevious.contains("\"password")) {
+							vXTrxLog.setPreviousValue(tempPreviousStr.replace(tempPrevious, "\"password\":\"******\""));
 							break;
 						}
 					}			
@@ -1039,18 +1039,18 @@ public class AssetMgr extends AssetMgrBase {
 				if(vXTrxLog.getNewValue() != null && vXTrxLog.getNewValue().contains("password")) {
 					String tempNewStr = vXTrxLog.getNewValue();
 					String tempNewArr[] = vXTrxLog.getNewValue().split(",");
-					for(int i = 0; i < tempNewArr.length; i++) {
-						if(tempNewArr[i].contains("{\"password") && tempNewArr[i].contains("}")) {
-							vXTrxLog.setNewValue(tempNewStr.replace(tempNewArr[i], "{\"password\":\"*****\"}"));
+					for (String tempNew : tempNewArr) {
+						if(tempNew.contains("{\"password") && tempNew.contains("}")) {
+							vXTrxLog.setNewValue(tempNewStr.replace(tempNew, "{\"password\":\"*****\"}"));
 							break;
-						} else if(tempNewArr[i].contains("{\"password")) {
-							vXTrxLog.setNewValue(tempNewStr.replace(tempNewArr[i], "{\"password\":\"*****\""));
+						} else if(tempNew.contains("{\"password")) {
+							vXTrxLog.setNewValue(tempNewStr.replace(tempNew, "{\"password\":\"*****\""));
 							break;
-						} else if(tempNewArr[i].contains("\"password") && tempNewArr[i].contains("}")) {
-							vXTrxLog.setNewValue(tempNewStr.replace(tempNewArr[i], "\"password\":\"******\"}"));
+						} else if(tempNew.contains("\"password") && tempNew.contains("}")) {
+							vXTrxLog.setNewValue(tempNewStr.replace(tempNew, "\"password\":\"******\"}"));
 							break;
-						} else if(tempNewArr[i].contains("\"password")) {
-							vXTrxLog.setNewValue(tempNewStr.replace(tempNewArr[i], "\"password\":\"******\""));
+						} else if(tempNew.contains("\"password")) {
+							vXTrxLog.setNewValue(tempNewStr.replace(tempNew, "\"password\":\"******\""));
 							break;
 						}
 					}	

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
index 272dec4..a110035 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/UserMgr.java
@@ -951,8 +951,8 @@ public class UserMgr {
 		 * return false; }
 		 */
 		boolean publicRole = false;
-		for (int i = 0; i < publicRoles.length; i++) {
-			if (publicRoles[i].equalsIgnoreCase(gjUserRole.getUserRole())) {
+		for (String publicRoleStr : publicRoles) {
+			if (publicRoleStr.equalsIgnoreCase(gjUserRole.getUserRole())) {
 				publicRole = true;
 				break;
 			}
@@ -972,8 +972,8 @@ public class UserMgr {
 		List<XXPortalUserRole> roleList = daoManager.getXXPortalUserRole()
 				.findByUserId(userId);
 		boolean publicRole = false;
-		for (int i = 0; i < publicRoles.length; i++) {
-			if (publicRoles[i].equalsIgnoreCase(userRole)) {
+		for (String publicRoleStr : publicRoles) {
+			if (publicRoleStr.equalsIgnoreCase(userRole)) {
 				publicRole = true;
 				break;
 			}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
index 967804a..d3fc80c 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
@@ -265,8 +265,8 @@ public class RESTErrorUtil {
 
 	public void validateStringList(String value, String[] validValues,
 			String errorMessage, Long objectId, String fieldName) {
-		for (int i = 0; i < validValues.length; i++) {
-			if (validValues[i].equals(value)) {
+		for (String validValue : validValues) {
+			if (validValue.equals(value)) {
 				return;
 			}
 		}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/common/StringUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/common/StringUtil.java b/security-admin/src/main/java/org/apache/ranger/common/StringUtil.java
index 045e07c..82afa27 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/StringUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/StringUtil.java
@@ -198,8 +198,8 @@ public class StringUtil implements Serializable {
 			String[] splitValues = value.split(delimiter);
 			String[] returnValues = new String[splitValues.length];
 			int c = -1;
-			for (int i = 0; i < splitValues.length; i++) {
-				String str = splitValues[i].trim();
+			for (String splitValue : splitValues) {
+				String str = splitValue.trim();
 				if (str.length() > 0) {
 					c++;
 					returnValues[c] = str;

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/patch/cliutil/MetricUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/patch/cliutil/MetricUtil.java b/security-admin/src/main/java/org/apache/ranger/patch/cliutil/MetricUtil.java
index d1ab0d0..f1e18e5 100644
--- a/security-admin/src/main/java/org/apache/ranger/patch/cliutil/MetricUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/patch/cliutil/MetricUtil.java
@@ -364,11 +364,11 @@ public class MetricUtil extends BaseLoader  {
 						Map<String, Integer> denyconditionsonMap = new HashMap<String, Integer>();
 						PList<RangerServiceDef> paginatedSvcDefs = svcStore.getPaginatedServiceDefs(policyFilter1);
 						if (paginatedSvcDefs != null) {
-							List<RangerServiceDef> rangerServiceDef = paginatedSvcDefs.getList();
-							if (rangerServiceDef != null && !rangerServiceDef.isEmpty()) {
-								for (int i = 0; i < rangerServiceDef.size(); i++) {
-									if (rangerServiceDef.get(i) != null) {
-										String serviceDef = rangerServiceDef.get(i).getName();
+							List<RangerServiceDef> rangerServiceDefs = paginatedSvcDefs.getList();
+							if (rangerServiceDefs != null && !rangerServiceDefs.isEmpty()) {
+								for (RangerServiceDef rangerServiceDef : rangerServiceDefs) {
+									if (rangerServiceDef != null) {
+										String serviceDef = rangerServiceDef.getName();
 										if (!StringUtils.isEmpty(serviceDef)) {
 											policyFilter1.setParam("serviceType", serviceDef);
 											PList<RangerPolicy> policiesList = svcStore.getPaginatedPolicies(policyFilter1);
@@ -376,9 +376,9 @@ public class MetricUtil extends BaseLoader  {
 												int policyListCount = policiesList.getListSize();
 												if (policyListCount > 0 && policiesList.getList() != null) {
 													List<RangerPolicy> policies = policiesList.getList();
-													for (int j = 0; j < policies.size(); j++) {
-														if (policies.get(j) != null) {
-															List<RangerPolicyItem> policyItem = policies.get(j).getDenyPolicyItems();
+													for (RangerPolicy policy : policies) {
+														if (policy != null) {
+															List<RangerPolicyItem> policyItem = policy.getDenyPolicyItems();
 															if (policyItem != null && !policyItem.isEmpty()) {
 																if (denyconditionsonMap.get(serviceDef) != null) {
 																	denyCount = denyconditionsonMap.get(serviceDef) + denyCount + policyItem.size();
@@ -386,7 +386,7 @@ public class MetricUtil extends BaseLoader  {
 																	denyCount = denyCount + policyItem.size();
 																}
 															}
-															List<RangerPolicyItem> policyItemExclude = policies.get(j).getDenyExceptions();
+															List<RangerPolicyItem> policyItemExclude = policy.getDenyExceptions();
 															if (policyItemExclude != null && !policyItemExclude.isEmpty()) {
 																if (denyconditionsonMap.get(serviceDef) != null) {
 																	denyCount = denyconditionsonMap.get(serviceDef) + denyCount + policyItemExclude.size();

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/service/UserService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/UserService.java b/security-admin/src/main/java/org/apache/ranger/service/UserService.java
index 3fb279e..9ca6a4f 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/UserService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/UserService.java
@@ -20,6 +20,7 @@
  package org.apache.ranger.service;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -248,10 +249,7 @@ public class UserService extends UserServiceBase<XXPortalUser, VXPortalUser> {
 		Collection<String> newCollection = new ArrayList<String>();
 		for (String role : collection) {
 			String roles[] = role.split(",");
-			for (int i = 0; i < roles.length; i++) {
-				String str = roles[i];
-				newCollection.add(str);
-			}
+            newCollection.addAll(Arrays.asList(roles));
 		}
 		collection.clear();
 		collection.addAll(newCollection);

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java b/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
index 551f824..69a6500 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
@@ -155,17 +155,17 @@ public class RangerRESTAPIFilter extends LoggingFilter {
 					Annotation[] methodAnnotations = m.getAnnotations();
 					String httpMethod = null;
 					String servicePath = null;
-					for (int ma = 0; ma < methodAnnotations.length; ma++) {
-						if (methodAnnotations[ma] instanceof GET) {
+					for (Annotation methodAnnotation : methodAnnotations) {
+						if (methodAnnotation instanceof GET) {
 							httpMethod = "GET";
-						} else if (methodAnnotations[ma] instanceof PUT) {
+						} else if (methodAnnotation instanceof PUT) {
 							httpMethod = "PUT";
-						} else if (methodAnnotations[ma] instanceof POST) {
+						} else if (methodAnnotation instanceof POST) {
 							httpMethod = "POST";
-						} else if (methodAnnotations[ma] instanceof DELETE) {
+						} else if (methodAnnotation instanceof DELETE) {
 							httpMethod = "DELETE";
-						} else if (methodAnnotations[ma] instanceof Path) {
-							servicePath = ((Path) methodAnnotations[ma])
+						} else if (methodAnnotation instanceof Path) {
+							servicePath = ((Path) methodAnnotation)
 									.value();
 						}
 					}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/security-admin/src/main/java/org/apache/ranger/util/RangerRestUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/util/RangerRestUtil.java b/security-admin/src/main/java/org/apache/ranger/util/RangerRestUtil.java
index fe7a53e..82b0e47 100644
--- a/security-admin/src/main/java/org/apache/ranger/util/RangerRestUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/util/RangerRestUtil.java
@@ -20,6 +20,7 @@
  package org.apache.ranger.util;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -51,11 +52,8 @@ public class RangerRestUtil {
 	void splitUserRoleList(Collection<String> collection) {
 		Collection<String> newCollection = new ArrayList<String>();
 		for (String role : collection) {
-			String roles[] = role.split(",");
-			for (int i = 0; i < roles.length; i++) {
-				String str = roles[i];
-				newCollection.add(str);
-			}
+			String[] roles = role.split(",");
+            newCollection.addAll(Arrays.asList(roles));
 		}
 		collection.clear();
 		collection.addAll(newCollection);
@@ -143,4 +141,4 @@ public class RangerRestUtil {
 
 	}
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/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 8dc147c..6b2648d 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
@@ -399,15 +399,14 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 			}
 
 			// When multiple OUs are configured, go through each OU as the user search base to search for users.
-			for (int ou=0; ou<userSearchBase.length; ou++) {
+			for (String ou : userSearchBase) {
 				byte[] cookie = null;
 				int counter = 0;
 				try {
 					int paged = 0;
 					do {
 						userSearchResultEnum = ldapContext
-								.search(userSearchBase[ou], extendedUserSearchFilter,
-										userSearchControls);
+								.search(ou, extendedUserSearchFilter, userSearchControls);
 
 						while (userSearchResultEnum.hasMore()) {
 							// searchResults contains all the user entries
@@ -420,7 +419,7 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 								continue;
 							}
 
-							Attributes attributes =   userEntry.getAttributes();
+							Attributes attributes = userEntry.getAttributes();
 							if (attributes == null)  {
 								if (LOG.isInfoEnabled())  {
 									LOG.info("attributes  missing for entry " + userEntry.getNameInNamespace() +
@@ -556,10 +555,10 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 						// Examine the paged results control response
 						Control[] controls = ldapContext.getResponseControls();
 						if (controls != null) {
-							for (int i = 0; i < controls.length; i++) {
-								if (controls[i] instanceof PagedResultsResponseControl) {
+							for (Control control : controls) {
+								if (control instanceof PagedResultsResponseControl) {
 									PagedResultsResponseControl prrc =
-											(PagedResultsResponseControl)controls[i];
+											(PagedResultsResponseControl)control;
 									total = prrc.getResultSize();
 									if (total != 0) {
 										LOG.debug("END-OF-PAGE total : " + total);
@@ -610,7 +609,7 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 				ldapContext.setRequestControls(new Control[]{
 						new PagedResultsControl(pagedResultsSize, Control.NONCRITICAL) });
 			}
-			for (int ou=0; ou<groupSearchBase.length; ou++) {
+            for (String ou : groupSearchBase) {
 				byte[] cookie = null;
 				int counter = 0;
 				try {
@@ -628,13 +627,13 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 												userInfo.getUserName()));
 							}
 							groupSearchResultEnum = ldapContext
-									.search(groupSearchBase[ou], extendedGroupSearchFilter,
+									.search(ou, extendedGroupSearchFilter,
 											new Object[]{userInfo.getUserFullName(), userInfo.getUserName()},
 											groupSearchControls);
 						} else {
 							// If group based search is enabled, then first retrieve all the groups based on the group configuration.
 							groupSearchResultEnum = ldapContext
-									.search(groupSearchBase[ou], extendedAllGroupsSearchFilter,
+									.search(ou, extendedAllGroupsSearchFilter,
 											groupSearchControls);
 						}
 						while (groupSearchResultEnum.hasMore()) {
@@ -707,10 +706,10 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 						// Examine the paged results control response
 						Control[] controls = ldapContext.getResponseControls();
 						if (controls != null) {
-							for (int i = 0; i < controls.length; i++) {
-								if (controls[i] instanceof PagedResultsResponseControl) {
+							for (Control control : controls) {
+								if (control instanceof PagedResultsResponseControl) {
 									PagedResultsResponseControl prrc =
-											(PagedResultsResponseControl)controls[i];
+											(PagedResultsResponseControl)control;
 									total = prrc.getResultSize();
 									if (total != 0) {
 										LOG.debug("END-OF-PAGE total : " + total);
@@ -814,13 +813,13 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
             groupFilter += filter;
 
 			LOG.debug("extendedAllGroupsSearchFilter = " + groupFilter);
-			for (int ou=0; ou<groupSearchBase.length; ou++) {
+			for (String ou : groupSearchBase) {
 				byte[] cookie = null;
 				int counter = 0;
 				try {
 					do {
 						groupSearchResultEnum = ldapContext
-									.search(groupSearchBase[ou], groupFilter,
+									.search(ou, groupFilter,
 											groupSearchControls);
                         //System.out.println("goUpGroupHierarchyLdap(): Going through the sub groups");
 						while (groupSearchResultEnum.hasMore()) {
@@ -859,10 +858,10 @@ public class LdapUserGroupBuilder extends AbstractUserGroupSource {
 						// Examine the paged results control response
 						Control[] controls = ldapContext.getResponseControls();
 						if (controls != null) {
-							for (int i = 0; i < controls.length; i++) {
-								if (controls[i] instanceof PagedResultsResponseControl) {
+							for (Control control : controls) {
+								if (control instanceof PagedResultsResponseControl) {
 									PagedResultsResponseControl prrc =
-											(PagedResultsResponseControl)controls[i];
+											(PagedResultsResponseControl)control;
 									total = prrc.getResultSize();
 									if (total != 0) {
 										LOG.debug("END-OF-PAGE total : " + total);

http://git-wip-us.apache.org/repos/asf/ranger/blob/75b8a422/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
index ade2ee7..864d884 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
@@ -73,34 +73,34 @@ import org.apache.ranger.usergroupsync.UserGroupSink;
 import org.apache.ranger.usersync.util.UserSyncUtil;
 
 public class PolicyMgrUserGroupBuilder implements UserGroupSink {
-	
+
 	private static final Logger LOG = Logger.getLogger(PolicyMgrUserGroupBuilder.class);
-	
-	private static final String AUTHENTICATION_TYPE = "hadoop.security.authentication";	
+
+	private static final String AUTHENTICATION_TYPE = "hadoop.security.authentication";
 	private String AUTH_KERBEROS = "kerberos";
 	private static final String PRINCIPAL = "ranger.usersync.kerberos.principal";
 	private static final String KEYTAB = "ranger.usersync.kerberos.keytab";
 	private static final String NAME_RULE = "hadoop.security.auth_to_local";
-	
+
 	public static final String PM_USER_LIST_URI  = "/service/xusers/users/";				// GET
 	private static final String PM_ADD_USER_GROUP_INFO_URI = "/service/xusers/users/userinfo";	// POST
-	
+
 	public static final String PM_GROUP_LIST_URI = "/service/xusers/groups/";				// GET
 	private static final String PM_ADD_GROUP_URI = "/service/xusers/groups/";				// POST
-	
-	
+
+
 	public static final String PM_USER_GROUP_MAP_LIST_URI = "/service/xusers/groupusers/";		// GET
-	
+
 	private static final String PM_DEL_USER_GROUP_LINK_URI = "/service/xusers/group/${groupName}/user/${userName}"; // DELETE
-	
+
 	private static final String PM_ADD_LOGIN_USER_URI = "/service/users/default";			// POST
 	private static final String GROUP_SOURCE_EXTERNAL ="1";
-	
+
 	private static String LOCAL_HOSTNAME = "unknown";
 	private String recordsToPullPerCall = "1000";
 	private boolean isMockRun = false;
 	private String policyMgrBaseUrl;
-	
+
 	private UserGroupSyncConfig  config = UserGroupSyncConfig.getInstance();
 
 	private UserGroupInfo				usergroupInfo = new UserGroupInfo();
@@ -110,7 +110,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	private HashMap<String,XUserInfo>  	userId2XUserInfoMap = new HashMap<String,XUserInfo>();
 	private HashMap<String,XUserInfo>  	userName2XUserInfoMap = new HashMap<String,XUserInfo>();
 	private HashMap<String,XGroupInfo>  groupName2XGroupInfoMap = new HashMap<String,XGroupInfo>();
-	
+
 	private String keyStoreFile =  null;
 	private String keyStoreFilepwd = null;
 	private String trustStoreFile = null;
@@ -133,23 +133,23 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			LOCAL_HOSTNAME = "unknown";
 		}
 	}
-	
-	
+
+
 	public static void main(String[] args) throws Throwable {
 		PolicyMgrUserGroupBuilder  ugbuilder = new PolicyMgrUserGroupBuilder();
 		ugbuilder.init();
 	}
 
-	
+
 	synchronized public void init() throws Throwable {
 		recordsToPullPerCall = config.getMaxRecordsPerAPICall();
 		policyMgrBaseUrl = config.getPolicyManagerBaseURL();
 		isMockRun = config.isMockRunEnabled();
-		
+
 		if (isMockRun) {
 			LOG.setLevel(Level.DEBUG);
 		}
-		
+
 		keyStoreFile =  config.getSSLKeyStorePath();
 		keyStoreFilepwd = config.getSSLKeyStorePathPassword();
 		trustStoreFile = config.getSSLTrustStorePath();
@@ -170,17 +170,17 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
         }
 		buildUserGroupInfo();
 	}
-	
+
 	private void buildUserGroupInfo() throws Throwable {
 		if(authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType) && SecureClientLogin.isKerberosCredentialExists(principal, keytab)){
 			if(LOG.isDebugEnabled()) {
 				LOG.debug("==> Kerberos Environment : Principal is " + principal + " and Keytab is " + keytab);
 			}
-		}		
+		}
 		if (authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType) && SecureClientLogin.isKerberosCredentialExists(principal, keytab)) {
 			try {
 				LOG.info("Using principal = " + principal + " and keytab = " + keytab);
-				Subject sub = SecureClientLogin.loginUserFromKeytab(principal, keytab, nameRules);				
+				Subject sub = SecureClientLogin.loginUserFromKeytab(principal, keytab, nameRules);
 				Subject.doAs(sub, new PrivilegedAction<Void>() {
 					@Override
 					public Void run() {
@@ -206,56 +206,56 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			if (LOG.isDebugEnabled()) {
 				this.print();
 			}
-		}	
+		}
 	}
-	
+
 	private String getURL(String uri) {
 		String ret = null;
 		ret = policyMgrBaseUrl + (uri.startsWith("/") ? uri : ("/" + uri));
 		return ret;
 	}
-	
-	
+
+
 	private void rebuildUserGroupMap() {
-		
+
 		for(XUserInfo user : xuserList) {
 			addUserToList(user);
 		}
-		
+
 		for(XGroupInfo group : xgroupList) {
 			addGroupToList(group);
 		}
-		
-		
+
+
 		for(XUserGroupInfo ug : xusergroupList) {
 			addUserGroupToList(ug);
 		}
-		
-		
+
+
 	}
-	
-	
+
+
 	private void addUserToList(XUserInfo aUserInfo) {
 		if (! xuserList.contains(aUserInfo)) {
 			xuserList.add(aUserInfo);
 		}
-		
+
 		String userId = aUserInfo.getId();
-		
+
 		if (userId != null) {
 			userId2XUserInfoMap.put(userId, aUserInfo);
 		}
-		
+
 		String userName = aUserInfo.getName();
-		
+
 		if (userName != null) {
 			userName2XUserInfoMap.put(userName, aUserInfo);
 		}
 	}
-	
+
 
 	private void addGroupToList(XGroupInfo aGroupInfo) {
-		
+
 		if (! xgroupList.contains(aGroupInfo) ) {
 			xgroupList.add(aGroupInfo);
 		}
@@ -265,13 +265,13 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		}
 
 	}
-	
+
 	private void addUserGroupToList(XUserGroupInfo ugInfo) {
 		String userId = ugInfo.getUserId();
-		
+
 		if (userId != null) {
 			XUserInfo user = userId2XUserInfoMap.get(userId);
-			
+
 			if (user != null) {
 				List<String> groups = user.getGroups();
 				if (! groups.contains(ugInfo.getGroupName())) {
@@ -280,13 +280,13 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			}
 		}
 	}
-	
+
 	private void addUserGroupInfoToList(XUserInfo userInfo, XGroupInfo groupInfo) {
 		String userId = userInfo.getId();
-		
+
 		if (userId != null) {
 			XUserInfo user = userId2XUserInfoMap.get(userId);
-			
+
 			if (user != null) {
 				List<String> groups = user.getGroups();
 				if (! groups.contains(groupInfo.getName())) {
@@ -302,7 +302,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			groups.remove(groupInfo.getName());
 		}
 	}
-	
+
 	private void print() {
 		LOG.debug("Number of users read [" + xuserList.size() + "]");
 		for(XUserInfo user : xuserList) {
@@ -315,14 +315,14 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 
 	@Override
 	public void addOrUpdateUser(String userName, List<String> groups) throws Throwable {
-		
+
 		UserGroupInfo ugInfo		  = new UserGroupInfo();
 		XUserInfo user = userName2XUserInfoMap.get(userName);
-		
+
 		if (groups == null) {
 			groups = new ArrayList<String>();
 		}
-		
+
 		if (user == null) {    // Does not exists
 
 			LOG.debug("INFO: addPMAccount(" + userName + ")" );
@@ -333,10 +333,10 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 					throw new Exception(msg);
 				}
 			}
-			
+
 			//* Build the user group info object and do the rest call
  			if ( ! isMockRun ) {
- 				// If the rest call to ranger admin fails, 
+ 				// If the rest call to ranger admin fails,
  				// propagate the failure to the caller for retry in next sync cycle.
  				if (addUserGroupInfo(userName,groups) == null ) {
  					String msg = "Failed to add addorUpdate user group info";
@@ -362,7 +362,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 					}
 				}
 			}
-			
+
 			for(String group : oldGroups) {
 				if (! groups.contains(group) ) {
 					delGroups.add(group);
@@ -376,11 +376,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
                 if (!addGroups.isEmpty()) {
                     XUserInfo obj = addXUserInfo(userName);
                     if (obj != null) {
-                        for (int i = 0; i < addGroups.size(); i++) {
-                            if (groupMap.containsKey(addGroups.get(i))) {
+                        for (String group : addGroups) {
+                            String value = groupMap.get(group);
+                            if (value != null) {
                                 List<String> userRoleList = new ArrayList<String>();
-                                userRoleList
-                                        .add(groupMap.get(addGroups.get(i)));
+                                userRoleList.add(value);
                                 if (userMap.containsKey(obj.getName())) {
                                     List<String> userRole = new ArrayList<String>();
                                     userRole.add(userMap.get(obj.getName()));
@@ -388,8 +388,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
                                         obj.setUserRoleList(userRole);
 
                                     }
-                                } else if (!obj.getUserRoleList().equals(
-                                        userRoleList)) {
+                                } else if (!obj.getUserRoleList().equals(userRoleList)) {
                                     obj.setUserRoleList(userRoleList);
                                 }
                             }
@@ -419,7 +418,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
  			for(String g : delGroups) {
  				LOG.debug("INFO: delPMXAGroupFromUser(" + userName + "," + g + ")" );
  			}
- 			
+
  			if (! isMockRun ) {
  				delXUserGroupInfo(user, delGroups);
  			}
@@ -427,11 +426,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
                 if (!updateGroups.isEmpty()) {
                     XUserInfo obj = addXUserInfo(userName);
                     if (obj != null) {
-                        for (int i = 0; i < updateGroups.size(); i++) {
-                            if (groupMap.containsKey(updateGroups.get(i))) {
+                        for (String group : updateGroups) {
+                            String value = groupMap.get(group);
+                            if (value != null) {
                                 List<String> userRoleList = new ArrayList<String>();
-                                userRoleList.add(groupMap.get(updateGroups
-                                        .get(i)));
+                                userRoleList.add(value);
                                 if (userMap.containsKey(obj.getName())) {
                                     List<String> userRole = new ArrayList<String>();
                                     userRole.add(userMap.get(obj.getName()));
@@ -477,10 +476,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
                             roleFlag = true;
                         }
                     } else {
-                        for (int i = 0; i < groups.size(); i++) {
-                            if (groupMap.containsKey(groups.get(i))) {
+                        for (String group : groups) {
+                            String value = groupMap.get(group);
+                            if (value != null) {
                                 List<String> userRoleList = new ArrayList<String>();
-                                userRoleList.add(groupMap.get(groups.get(i)));
+                                userRoleList.add(value);
                                 if (!obj.getUserRoleList().equals(userRoleList)) {
                                     obj.setUserRoleList(userRoleList);
                                     roleFlag = true;
@@ -512,31 +512,31 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
             }
 		}
 	}
-	
+
 	private void buildGroupList() {
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> PolicyMgrUserGroupBuilder.buildGroupList");
-		}		
+		}
 		Client c = getClient();
-		
+
 		int totalCount = 100;
 		int retrievedCount = 0;
-		 	
+
 		while (retrievedCount < totalCount) {
 			WebResource r = c.resource(getURL(PM_GROUP_LIST_URI))
 					.queryParam("pageSize", recordsToPullPerCall)
 					.queryParam("startIndex", String.valueOf(retrievedCount));
-			
+
 		String response = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
-		
+
 		LOG.debug("RESPONSE: [" + response + "]");
-		    		
+
 		Gson gson = new GsonBuilder().create();
 
 		GetXGroupListResponse groupList = gson.fromJson(response, GetXGroupListResponse.class);
-				
+
 		totalCount = groupList.getTotalCount();
-		
+
 			if (groupList.getXgroupInfoList() != null) {
 				xgroupList.addAll(groupList.getXgroupInfoList());
 				retrievedCount = xgroupList.size();
@@ -547,32 +547,32 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			}
 		}
 	}
-	
+
 	private void buildUserList() {
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> PolicyMgrUserGroupBuilder.buildUserList");
 		}
-		Client c = getClient();	
-	
+		Client c = getClient();
+
 	    int totalCount = 100;
 	    int retrievedCount = 0;
-	
+
 	    while (retrievedCount < totalCount) {
-		
+
 		    WebResource r = c.resource(getURL(PM_USER_LIST_URI))
 		    					.queryParam("pageSize", recordsToPullPerCall)
 		    					.queryParam("startIndex", String.valueOf(retrievedCount));
-		
+
 		    String response = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
-		
+
 		    Gson gson = new GsonBuilder().create();
-	
+
 		    LOG.debug("RESPONSE: [" + response + "]");
-	
+
 		    GetXUserListResponse userList = gson.fromJson(response, GetXUserListResponse.class);
-		
+
 		    totalCount = userList.getTotalCount();
-		
+
 		    if (userList.getXuserInfoList() != null) {
 		    	xuserList.addAll(userList.getXuserInfoList());
 		    	retrievedCount = xuserList.size();
@@ -583,32 +583,32 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		    }
 	    }
 	}
-	
+
 	private void buildUserGroupLinkList() {
 		if(LOG.isDebugEnabled()) {
 	 		LOG.debug("==> PolicyMgrUserGroupBuilder.buildUserGroupLinkList");
 	 	}
 		Client c = getClient();
-	
+
 	    int totalCount = 100;
 	    int retrievedCount = 0;
-	
+
 	    while (retrievedCount < totalCount) {
-		
+
 		    WebResource r = c.resource(getURL(PM_USER_GROUP_MAP_LIST_URI))
 		    					.queryParam("pageSize", recordsToPullPerCall)
 		    					.queryParam("startIndex", String.valueOf(retrievedCount));
-		
+
 		    String response = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
-		
+
 		    LOG.debug("RESPONSE: [" + response + "]");
-		
+
 		    Gson gson = new GsonBuilder().create();
-	
+
 		    GetXUserGroupListResponse usergroupList = gson.fromJson(response, GetXUserGroupListResponse.class);
-		
+
 		    totalCount = usergroupList.getTotalCount();
-		
+
 		    if (usergroupList.getXusergroupInfoList() != null) {
 		    	xusergroupList.addAll(usergroupList.getXusergroupInfoList());
 		    	retrievedCount = xusergroupList.size();
@@ -626,15 +626,16 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	 	}
 		UserGroupInfo ret = null;
 		XUserInfo user = null;
-		
+
 		LOG.debug("INFO: addPMXAUser(" + userName + ")" );
 		if (! isMockRun) {
 			user = addXUserInfo(userName);
             if (!groups.isEmpty() && user != null) {
-                for (int i = 0; i < groups.size(); i++) {
-                    if (groupMap.containsKey(groups.get(i))) {
+                for (String group : groups) {
+                    String value = groupMap.get(group);
+                    if (value != null) {
                         List<String> userRoleList = new ArrayList<String>();
-                        userRoleList.add(groupMap.get(groups.get(i)));
+                        userRoleList.add(value);
                         if (userMap.containsKey(user.getName())) {
                             List<String> userRole = new ArrayList<String>();
                             userRole.add(userMap.get(user.getName()));
@@ -681,32 +682,32 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 
 	private UserGroupInfo getUsergroupInfo(UserGroupInfo ret) {
 		Client c = getClient();
-		
+
 		WebResource r = c.resource(getURL(PM_ADD_USER_GROUP_INFO_URI));
-		
+
 		Gson gson = new GsonBuilder().create();
-		
+
 		String jsonString = gson.toJson(usergroupInfo);
-		
+
 		LOG.debug("USER GROUP MAPPING" + jsonString);
-		
+
 		String response = r.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post(String.class, jsonString);
-		
+
 		LOG.debug("RESPONSE: [" + response + "]");
-		
+
 		ret = gson.fromJson(response, UserGroupInfo.class);
-		
+
 		if ( ret != null) {
-			
+
 			XUserInfo xUserInfo = ret.getXuserInfo();
 			addUserToList(xUserInfo);
-			
+
 			for(XGroupInfo xGroupInfo : ret.getXgroupInfo()) {
 				addGroupToList(xGroupInfo);
 				addUserGroupInfoToList(xUserInfo,xGroupInfo);
 			}
 		}
-		
+
 		return ret;
 	}
 
@@ -744,7 +745,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
             }
 		}
 	}
-	
+
 	private UserGroupInfo addUserGroupInfo(UserGroupInfo usergroupInfo){
 		if(LOG.isDebugEnabled()) {
 	 		LOG.debug("==> PolicyMgrUserGroupBuilder.addUserGroupInfo");
@@ -781,27 +782,27 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	}
 
 	private XUserInfo addXUserInfo(String aUserName) {
-		
+
 		XUserInfo xuserInfo = new XUserInfo();
 
 		xuserInfo.setName(aUserName);
-		
+
 		xuserInfo.setDescription(aUserName + " - add from Unix box");
-	   	
+
 		usergroupInfo.setXuserInfo(xuserInfo);
-		
+
 		return xuserInfo;
 	}
-	
+
 
 	private XGroupInfo addXGroupInfo(String aGroupName) {
-		
+
 		XGroupInfo addGroup = new XGroupInfo();
-		
+
 		addGroup.setName(aGroupName);
-		
+
 		addGroup.setDescription(aGroupName + " - add from Unix box");
-		
+
 		addGroup.setGroupType("1");
 
 		addGroup.setGroupSource(GROUP_SOURCE_EXTERNAL);
@@ -809,11 +810,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		return addGroup;
 	}
 
-	
+
 	private void addXUserGroupInfo(XUserInfo aUserInfo, List<String> aGroupList) {
-		
+
 		List<XGroupInfo> xGroupInfoList = new ArrayList<XGroupInfo>();
-		
+
 		for(String groupName : aGroupList) {
 			XGroupInfo group = groupName2XGroupInfoMap.get(groupName);
 			if (group == null) {
@@ -822,10 +823,10 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			xGroupInfoList.add(group);
 			addXUserGroupInfo(aUserInfo, group);
 		}
-		
+
 		usergroupInfo.setXgroupInfo(xGroupInfoList);
 	}
-	
+
 	private List<XGroupInfo> getXGroupInfoList(List<String> aGroupList) {
 
 		List<XGroupInfo> xGroupInfoList = new ArrayList<XGroupInfo>();
@@ -840,24 +841,24 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		}
 		return xGroupInfoList;
 	}
-	
 
-	
+
+
    private XUserGroupInfo addXUserGroupInfo(XUserInfo aUserInfo, XGroupInfo aGroupInfo) {
-		
-	
+
+
 	    XUserGroupInfo ugInfo = new XUserGroupInfo();
-		
+
 		ugInfo.setUserId(aUserInfo.getId());
-		
+
 		ugInfo.setGroupName(aGroupInfo.getName());
-		
+
 		// ugInfo.setParentGroupId("1");
-		
+
         return ugInfo;
 	}
 
-	
+
 	private void delXUserGroupInfo(final XUserInfo aUserInfo, List<String> aGroupList) {
 		for(String groupName : aGroupList) {
 			final XGroupInfo group = groupName2XGroupInfoMap.get(groupName);
@@ -888,11 +889,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	}
 
 	private void delXUserGroupInfo(XUserInfo aUserInfo, XGroupInfo aGroupInfo) {
-	
+
 		String groupName = aGroupInfo.getName();
 
 		String userName  = aUserInfo.getName();
-		
+
 		try {
 
 			Client c = getClient();
@@ -918,7 +919,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		}
 
 	}
-	
+
 	private MUserInfo addMUser(String aUserName) {
 		MUserInfo ret = null;
 		MUserInfo userInfo = new MUserInfo();
@@ -958,43 +959,43 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	}
 
 
-	private MUserInfo getMUser(MUserInfo userInfo, MUserInfo ret) {		
+	private MUserInfo getMUser(MUserInfo userInfo, MUserInfo ret) {
 		Client c = getClient();
-	
+
 	    WebResource r = c.resource(getURL(PM_ADD_LOGIN_USER_URI));
-	
+
 	    Gson gson = new GsonBuilder().create();
 
 	    String jsonString = gson.toJson(userInfo);
-	
+
 	    String response = r.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post(String.class, jsonString);
-	
+
 	    LOG.debug("RESPONSE[" + response + "]");
-	
+
 	    ret = gson.fromJson(response, MUserInfo.class);
-	
+
 	    LOG.debug("MUser Creation successful " + ret);
-		
+
 		return ret;
 	}
 
 	private synchronized Client getClient() {
-		
+
 		Client ret = null;
-		
+
 		if (policyMgrBaseUrl.startsWith("https://")) {
-			
+
 			ClientConfig config = new DefaultClientConfig();
-			
+
 			if (sslContext == null) {
-				
+
 				try {
 
 				KeyManager[] kmList = null;
 				TrustManager[] tmList = null;
-	
+
 				if (keyStoreFile != null && keyStoreFilepwd != null) {
-	
+
 					KeyStore keyStore = KeyStore.getInstance(keyStoreType);
 					InputStream in = null;
 					try {
@@ -1013,11 +1014,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 							in.close();
 						}
 					}
-					
+
 				}
-	
+
 				if (trustStoreFile != null && trustStoreFilepwd != null) {
-	
+
 					KeyStore trustStore = KeyStore.getInstance(trustStoreType);
 					InputStream in = null;
 					try {
@@ -1039,7 +1040,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 				}
 
 				sslContext = SSLContext.getInstance("SSL");
-	
+
 				sslContext.init(kmList, tmList, new SecureRandom());
 
 				hv = new HostnameVerifier() {
@@ -1058,12 +1059,12 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 
 			ret = Client.create(config);
 
-			
+
 		}
 		else {
 			ClientConfig cc = new DefaultClientConfig();
 		    cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
-		    ret = Client.create(cc);	
+		    ret = Client.create(cc);
 		}
 		if(!(authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType) && SecureClientLogin.isKerberosCredentialExists(principal, keytab))){
 			if(ret!=null){
@@ -1080,7 +1081,7 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 		}
 		return ret;
 	}
-	
+
 	private InputStream getFileInputStream(String path) throws FileNotFoundException {
 
 		InputStream ret = null;
@@ -1091,13 +1092,13 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			ret = new FileInputStream(f);
 		} else {
 			ret = PolicyMgrUserGroupBuilder.class.getResourceAsStream(path);
-			
+
 			if (ret == null) {
 				if (! path.startsWith("/")) {
 					ret = getClass().getResourceAsStream("/" + path);
 				}
 			}
-			
+
 			if (ret == null) {
 				ret = ClassLoader.getSystemClassLoader().getResourceAsStream(path);
 				if (ret == null) {
@@ -1115,9 +1116,9 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 	@Override
 	public void addOrUpdateGroup(String groupName) throws Throwable{
 		XGroupInfo group = groupName2XGroupInfoMap.get(groupName);
-		
+
 		if (group == null) {    // Does not exists
-			
+
 			//* Build the group info object and do the rest call
  			if ( ! isMockRun ) {
  				group = addGroupInfo(groupName);
@@ -1131,11 +1132,11 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
  			}
 		}
 	}
-	
+
 	private XGroupInfo addGroupInfo(final String groupName){
 		XGroupInfo ret = null;
 		XGroupInfo group = null;
-		
+
 		LOG.debug("INFO: addPMXAGroup(" + groupName + ")" );
 		if (! isMockRun) {
 			group = addXGroupInfo(groupName);
@@ -1163,43 +1164,43 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
 			return null;
 		} else {
 			return getAddedGroupInfo(group);
-		}	
+		}
 	}
 
-	private XGroupInfo getAddedGroupInfo(XGroupInfo group){	
+	private XGroupInfo getAddedGroupInfo(XGroupInfo group){
 		XGroupInfo ret = null;
-		
+
 		Client c = getClient();
-		
+
 		WebResource r = c.resource(getURL(PM_ADD_GROUP_URI));
-		
+
 		Gson gson = new GsonBuilder().create();
-		
+
 		String jsonString = gson.toJson(group);
-		
+
 		LOG.debug("Group" + jsonString);
-		
+
 		String response = r.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post(String.class, jsonString);
-		
+
 		LOG.debug("RESPONSE: [" + response + "]");
-		
+
 		ret = gson.fromJson(response, XGroupInfo.class);
-		
-		return ret;	
+
+		return ret;
 	}
 
 
 	@Override
 	public void addOrUpdateUser(String user) throws Throwable {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 
 	@Override
 	public void addOrUpdateGroup(String group, List<String> users) throws Throwable {
 		// TODO Auto-generated method stub
-		
+
 	}
 
     private void getRoleForUserGroups(String userGroupRolesData) {


Mime
View raw message