ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gau...@apache.org
Subject [1/4] incubator-ranger git commit: RANGER-985 : Support download csv in Reports page as enhancement
Date Mon, 30 May 2016 12:28:49 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master c498b0fc1 -> ced7c3b7a


RANGER-985 : Support download csv in Reports page as enhancement

Signed-off-by: Gautam Borad <gautam@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/7d452069
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/7d452069
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/7d452069

Branch: refs/heads/master
Commit: 7d452069c636419dcb5084292377f977487cf123
Parents: c498b0f
Author: Mehul Parikh <mehul.parikh@freestoneinfotech.com>
Authored: Wed May 25 12:02:42 2016 +0530
Committer: Gautam Borad <gautam@apache.org>
Committed: Mon May 30 17:58:04 2016 +0530

----------------------------------------------------------------------
 .../org/apache/ranger/biz/ServiceDBStore.java   | 457 +++++++++++++++++--
 .../org/apache/ranger/rest/ServiceREST.java     |  36 ++
 .../scripts/views/reports/UserAccessLayout.js   | 158 ++++---
 .../scripts/views/users/UserTableLayout.js      |  57 +--
 security-admin/src/main/webapp/styles/xa.css    |  49 +-
 .../reports/UserAccessLayout_tmpl.html          |  14 +-
 .../templates/users/UserTableLayout_tmpl.html   |  14 +-
 7 files changed, 612 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 2f88a9b..c488d4a 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -27,13 +27,19 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.StringTokenizer;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.text.SimpleDateFormat;
 import java.util.TreeMap;
 
 import javax.annotation.PostConstruct;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -1974,6 +1980,36 @@ public class ServiceDBStore extends AbstractServiceStore {
 		writeExcel(policies, excelFileName, response);
 	}
 
+	public void getPoliciesInCSV(List<RangerPolicy> policies, HttpServletResponse response)
throws Exception {
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("==> ServiceDBStore.getPoliciesInCSV()");
+				}
+				InputStream in=null;
+				ServletOutputStream out=null;
+				String CSVFileName=null;
+				try {
+					String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
+					CSVFileName = "Ranger_Policies_" + timeStamp + ".csv";
+					out = response.getOutputStream();
+					StringBuffer sb = writeCSV(policies, CSVFileName, response);
+					in = new ByteArrayInputStream(sb.toString().getBytes());
+					byte[] outputByte = new byte[sb.length()];
+					while (in.read(outputByte, 0, sb.length()) != -1) {
+						out.write(outputByte, 0, sb.length());
+					}
+			}
+				catch (Exception e) {
+					 LOG.error("Error while generating report file " + CSVFileName, e);
+					 e.printStackTrace();
+
+				}
+				finally {
+					in.close();
+					out.flush();
+					out.close();
+				}
+			}
+
 	public PList<RangerPolicy> getPaginatedPolicies(SearchFilter filter) throws Exception
{
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("==> ServiceDBStore.getPaginatedPolicies(+ " + filter + ")");
@@ -3090,19 +3126,42 @@ public class ServiceDBStore extends AbstractServiceStore {
 
 		return false;
 	}
+
 	private void writeExcel(List<RangerPolicy> policies, String excelFileName, HttpServletResponse
response)
 			throws IOException {
-		Workbook workbook=null;
-		OutputStream outStream =null;
-		try{
+		Workbook workbook = null;
+		OutputStream outStream = null;
+		try {
 			workbook = new HSSFWorkbook();
 			Sheet sheet = workbook.createSheet();
 			createHeaderRow(sheet);
 			int rowCount = 0;
-			if (!CollectionUtils.isEmpty(policies)){
+			if (!CollectionUtils.isEmpty(policies)) {
 				for (RangerPolicy policy : policies) {
-					Row row = sheet.createRow(++rowCount);
-					writeBook(policy, row);
+					long serviceType = daoMgr.getXXService().findByName(policy.getService()).getType();
+					List<RangerPolicyItem> policyItems = policy.getPolicyItems();
+					List<RangerRowFilterPolicyItem> rowFilterPolicyItems = policy.getRowFilterPolicyItems();
+					List<RangerDataMaskPolicyItem> dataMaskPolicyItems = policy.getDataMaskPolicyItems();
+
+					if (CollectionUtils.isNotEmpty(policyItems)) {
+						for (RangerPolicyItem policyItem : policyItems) {
+							Row row = sheet.createRow(++rowCount);
+							writeBookForPolicyItems(policy, policyItem, null, null, row);
+						}
+					} else if (CollectionUtils.isNotEmpty(dataMaskPolicyItems)) {
+						for (RangerDataMaskPolicyItem dataMaskPolicyItem : dataMaskPolicyItems) {
+							Row row = sheet.createRow(++rowCount);
+							writeBookForPolicyItems(policy, null, dataMaskPolicyItem, null, row);
+						}
+					} else if (CollectionUtils.isNotEmpty(rowFilterPolicyItems)) {
+						for (RangerRowFilterPolicyItem rowFilterPolicyItem : rowFilterPolicyItems) {
+							Row row = sheet.createRow(++rowCount);
+							writeBookForPolicyItems(policy, null, null, rowFilterPolicyItem, row);
+						}
+					} else if (serviceType == 100) {
+						Row row = sheet.createRow(++rowCount);
+						writeBookForTag(policy, row);
+					}
 				}
 			}
 			ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
@@ -3112,36 +3171,351 @@ public class ServiceDBStore extends AbstractServiceStore {
 			response.setContentLength(outArray.length);
 			response.setHeader("Expires:", "0");
 			response.setHeader("Content-Disposition", "attachment; filename=" + excelFileName);
-			outStream=response.getOutputStream();
+			outStream = response.getOutputStream();
 			outStream.write(outArray);
 			outStream.flush();
-		}catch(IOException ex){
+		} catch (IOException ex) {
 			LOG.error("Failed to create report file " + excelFileName, ex);
-		}catch(Exception ex){
+		} catch (Exception ex) {
 			LOG.error("Error while generating report file " + excelFileName, ex);
-		}finally{
-			if(outStream!=null){
+		} finally {
+			if (outStream != null) {
 				outStream.close();
 			}
-			if(workbook!=null){
+			if (workbook != null) {
 				workbook.close();
 			}
 		}
 	}
 
-	private void writeBook(RangerPolicy policy, Row row) {
+	private StringBuffer writeCSV(List<RangerPolicy> policies, String cSVFileName, HttpServletResponse
response) {
+		response.setContentType("text/csv");
+		final String COMMA_DELIMITER = "|";
+		final String LINE_SEPARATOR = "\n";
+		final String FILE_HEADER = "ID|Name|Resources|Groups|Users|Accesses|Service Type|Status";
+		StringBuffer csvBuffer = new StringBuffer();
+		csvBuffer.append(FILE_HEADER);
+		csvBuffer.append(LINE_SEPARATOR);
+		for (RangerPolicy policy : policies) {
+			String policyStatus = "";
+			String policyName = "";
+			String ServiceType = "";
+			Long serviceTypeId = null;
+			List<String> groups = new ArrayList<String>();
+			List<String> users = new ArrayList<String>();
+			List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
+			String groupNames = "";
+			String userNames = "";
+			String accessType = "";
+			String resValue = "";
+			String resourceKeyVal = "";
+			String resKey = "";
+			policyName = policy.getName();
+			policyName=policyName.replace("|", "");
+			Long policyId = policy.getId();
+
+			if (policy.getIsEnabled()) {
+				policyStatus = "Enabled";
+			} else {
+				policyStatus = "Disabled";
+			}
+			XXService xxservice = daoMgr.getXXService().findByName(policy.getService());
+
+			if (xxservice != null) {
+				serviceTypeId = xxservice.getType();
+				XXServiceDef xxservDef = daoMgr.getXXServiceDef().getById(serviceTypeId);
+				if (xxservDef != null) {
+					ServiceType = xxservDef.getName();
+				}
+			}
+			int policyType = policy.getPolicyType();
+			List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
+			List<RangerPolicyItem> policyItems0 = new ArrayList<RangerPolicyItem>();
+			List<RangerDataMaskPolicyItem> policyItems1 = new ArrayList<RangerDataMaskPolicyItem>();
+			List<RangerRowFilterPolicyItem> policyItems2 = new ArrayList<RangerRowFilterPolicyItem>();
+			switch (policyType) {
+			case 0:
+				policyItems0 = policy.getPolicyItems();
+				policyItems.addAll(policyItems0);
+				break;
+			case 1:
+				policyItems1 = policy.getDataMaskPolicyItems();
+				policyItems.addAll(policyItems1);
+				break;
+			case 2:
+				policyItems2 = policy.getRowFilterPolicyItems();
+				policyItems.addAll(policyItems2);
+				break;
+			}
+
+			if (serviceTypeId == 100) {
+				Map<String, RangerPolicyResource> resources = policy.getResources();
+
+				if (resources != null) {
+					for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
+						resKey = resource.getKey();
+						RangerPolicyResource policyResource = resource.getValue();
+						List<String> resvalueList = policyResource.getValues();
+						resValue = resvalueList.toString();
+						resourceKeyVal = resourceKeyVal + " " + resKey + "=" + resValue;
+						resourceKeyVal = resourceKeyVal.replace("|", "");
+					}
+				}
+
+				if (!CollectionUtils.isEmpty(policyItems)) {
+					for (RangerPolicyItem policyItem : policyItems) {
+						groupNames = "";
+						userNames = "";
+						accessType = "";
+						groups = null;
+						users = null;
+						accesses = null;
+						groups = policyItem.getGroups();
+						accesses = policyItem.getAccesses();
+						users = policyItem.getUsers();
+
+						for (RangerPolicyItemAccess access : accesses) {
+							accessType = accessType + access.getType().replace("#", "").replace("|","") + "#";
+						}
+						accessType = accessType.substring(0, accessType.lastIndexOf("#"));
+						if (CollectionUtils.isNotEmpty(groups)) {
+							for (String group : groups){
+								group=group.replace("|", "");
+								group=group.replace("#", "");
+								groupNames=groupNames+group+ "#";
+							}
+							groupNames = groupNames.substring(0, groupNames.lastIndexOf("#"));
+						}
+
+						if (CollectionUtils.isNotEmpty(users)) {
+							for (String user : users){
+								user=user.replace("|", "");
+								user=user.replace("#", "");
+								userNames=userNames +user + "#";
+							}
+							userNames=userNames.substring(0,userNames.lastIndexOf("#"));
+						}
+
+						csvBuffer.append(policyId);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(policyName);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(resourceKeyVal);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(groupNames);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(userNames);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(accessType);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(ServiceType);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(policyStatus);
+						csvBuffer.append(COMMA_DELIMITER);
+						csvBuffer.append(LINE_SEPARATOR);
+
+					}
+				} else {
+					csvBuffer.append(policyId);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(policyName);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(resourceKeyVal);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(groupNames);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(userNames);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(accessType);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(ServiceType);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(policyStatus);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(LINE_SEPARATOR);
+				}
+			}
+
+			else {
+				Map<String, RangerPolicyResource> resources = policy.getResources();
+				if (resources != null) {
+					for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
+						resKey = resource.getKey();
+						RangerPolicyResource policyResource = resource.getValue();
+						List<String> resvalueList = policyResource.getValues();
+						resValue = resvalueList.toString();
+						resourceKeyVal = resourceKeyVal + " " + resKey + "=" + resValue;
+						resourceKeyVal = resourceKeyVal.replace("|", "");
+					}
+				}
+
+				for (RangerPolicyItem policyItem : policyItems) {
+					groups = null;
+					users = null;
+					accesses = null;
+					groupNames = "";
+					userNames = "";
+					accessType = "";
+					groups = policyItem.getGroups();
+					users = policyItem.getUsers();
+					accesses = policyItem.getAccesses();
+
+					if (CollectionUtils.isNotEmpty(accesses)) {
+						for (RangerPolicyItemAccess access : accesses) {
+							accessType = accessType + access.getType().replace("#", "").replace("|","") + "#";
+						}
+						accessType = accessType.substring(0, accessType.lastIndexOf("#"));
+					}
+					if (CollectionUtils.isNotEmpty(groups)) {
+						for (String group : groups){
+							group=group.replace("|", "");
+							group=group.replace("#", "");
+							groupNames=groupNames+group+ "#";
+						}
+						groupNames = groupNames.substring(0, groupNames.lastIndexOf("#"));
+					}
+					if (CollectionUtils.isNotEmpty(users)) {
+						for (String user : users){
+							user=user.replace("|", "");
+							user=user.replace("#", "");
+							userNames=userNames +user + "#";
+						}
+						userNames=userNames.substring(0,userNames.lastIndexOf("#"));
+					}
+					csvBuffer.append(policyId);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(policyName);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(resourceKeyVal);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(groupNames);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(userNames);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(accessType);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(ServiceType);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(policyStatus);
+					csvBuffer.append(COMMA_DELIMITER);
+					csvBuffer.append(LINE_SEPARATOR);
+				}
+			}
+		}
+		response.setHeader("Content-Disposition", "attachment; filename=" + cSVFileName);
+		return csvBuffer;
+	}
+
+	private void writeBookForPolicyItems(RangerPolicy policy, RangerPolicyItem policyItem,
+			RangerDataMaskPolicyItem dataMaskPolicyItem, RangerRowFilterPolicyItem rowFilterPolicyItem,
Row row) {
+		List<String> groups = new ArrayList<String>();
+		List<String> users = new ArrayList<String>();
+		String groupNames = "";
+		String userNames = "";
+		String accessType = "";
 		String policyStatus = "";
 		Cell cell = row.createCell(0);
 		cell.setCellValue(policy.getId());
+		List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
 		cell = row.createCell(1);
 		cell.setCellValue(policy.getName());
 		cell = row.createCell(2);
+		String resValue = "";
+		String resourceKeyVal = "";
+		String resKey = "";
+		Map<String, RangerPolicyResource> resources = policy.getResources();
+		if (resources != null) {
+			for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
+				resKey = resource.getKey();
+				RangerPolicyResource policyResource = resource.getValue();
+				List<String> resvalueList = policyResource.getValues();
+				resValue = resvalueList.toString();
+				resourceKeyVal = resourceKeyVal + " " + resKey + "=" + resValue;
+			}
+
+			cell.setCellValue(resourceKeyVal);
+			if (policyItem != null && dataMaskPolicyItem == null && rowFilterPolicyItem
== null) {
+				groups = policyItem.getGroups();
+				users = policyItem.getUsers();
+				accesses = policyItem.getAccesses();
+			} else if (dataMaskPolicyItem != null && policyItem == null && rowFilterPolicyItem
== null) {
+				groups = dataMaskPolicyItem.getGroups();
+				users = dataMaskPolicyItem.getUsers();
+				accesses = dataMaskPolicyItem.getAccesses();
+			} else if (rowFilterPolicyItem != null && policyItem == null && dataMaskPolicyItem
== null) {
+				groups = rowFilterPolicyItem.getGroups();
+				users = rowFilterPolicyItem.getUsers();
+				accesses = rowFilterPolicyItem.getAccesses();
+			}
+			if (CollectionUtils.isNotEmpty(accesses)) {
+				for (RangerPolicyItemAccess access : accesses) {
+					accessType = accessType + access.getType();
+					accessType = accessType + " ,";
+				}
+				accessType = accessType.substring(0, accessType.lastIndexOf(","));
+			}
+			if (CollectionUtils.isNotEmpty(groups)) {
+				groupNames = groupNames + groups.toString();
+				StringTokenizer groupToken = new StringTokenizer(groupNames, "[]");
+				groupNames = groupToken.nextToken().toString();
+			}
+			if (CollectionUtils.isNotEmpty(users)) {
+				userNames = userNames + users.toString();
+				StringTokenizer userToken = new StringTokenizer(userNames, "[]");
+				userNames = userToken.nextToken().toString();
+			}
+			cell = row.createCell(3);
+			cell.setCellValue(groupNames);
+			cell = row.createCell(4);
+			cell.setCellValue(userNames);
+			cell = row.createCell(5);
+			cell.setCellValue(accessType.trim());
+			cell = row.createCell(6);
+			XXService xxservice = daoMgr.getXXService().findByName(policy.getService());
+			String ServiceType = "";
+			if (xxservice != null) {
+				Long ServiceId = xxservice.getType();
+				XXServiceDef xxservDef = daoMgr.getXXServiceDef().getById(ServiceId);
+				if (xxservDef != null) {
+					ServiceType = xxservDef.getName();
+				}
+			}
+			cell.setCellValue(ServiceType);
+			cell = row.createCell(7);
+
+		}
 		if (policy.getIsEnabled()) {
 			policyStatus = "Enabled";
 		} else {
 			policyStatus = "Disabled";
 		}
 		cell.setCellValue(policyStatus);
+	}
+
+	private void writeBookForTag(RangerPolicy policy, Row row) {
+		String policyStatus = "";
+		Cell cell = row.createCell(0);
+		cell.setCellValue(policy.getId());
+		cell = row.createCell(1);
+		cell.setCellValue(policy.getName());
+		cell = row.createCell(2);
+		String resValue = "";
+		String resourceKeyVal = "";
+		String resKey = "";
+		String groupNames = "";
+		String userNames = "";
+		String accessType = "";
+		Map<String, RangerPolicyResource> resources = policy.getResources();
+		if (resources!=null) {
+			for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
+				resKey = resource.getKey();
+				RangerPolicyResource policyResource = resource.getValue();
+				List<String> resvalueList = policyResource.getValues();
+				resValue = resvalueList.toString();
+				resourceKeyVal = resourceKeyVal + " " + resKey + "=" + resValue;
+			}
+		}
+		cell.setCellValue(resourceKeyVal);
 		cell = row.createCell(3);
 		int policyType=policy.getPolicyType();
 		List<RangerPolicyItem> policyItems=new ArrayList<RangerPolicyItem>();
@@ -3165,18 +3539,18 @@ public class ServiceDBStore extends AbstractServiceStore {
 
 		List<String> groups = new ArrayList<String>();
 		List<String> users = new ArrayList<String>();
-		String groupNames = "";
-		String userNames = "";
-		String accessType = "";
+
 		if (!CollectionUtils.isEmpty(policyItems)) {
 			for (RangerPolicyItem policyItem : policyItems) {
+				groupNames = "";
+				userNames = "";
+				accessType = "";
 				groups = policyItem.getGroups();
 				List<RangerPolicyItemAccess> accesses = policyItem.getAccesses();
-				accessType = accessType + "[";
 				for (RangerPolicyItemAccess access : accesses) {
-					accessType = accessType + access.getType() + " ";
+					accessType = accessType + access.getType() + " ,";
 				}
-				accessType = accessType + "] ";
+				accessType = accessType.substring(0,accessType.lastIndexOf(","));
 				if (!groups.isEmpty()) {
 					groupNames = groupNames + groups.toString();
 				}
@@ -3190,6 +3564,8 @@ public class ServiceDBStore extends AbstractServiceStore {
 		cell = row.createCell(4);
 		cell.setCellValue(userNames);
 		cell = row.createCell(5);
+		cell.setCellValue(accessType.trim());
+		cell = row.createCell(6);
 		XXService xxservice = daoMgr.getXXService().findByName(policy.getService());
 		String ServiceType = "";
 		if (xxservice != null) {
@@ -3200,25 +3576,16 @@ public class ServiceDBStore extends AbstractServiceStore {
 			}
 		}
 		cell.setCellValue(ServiceType);
-		cell = row.createCell(6);
-		cell.setCellValue(accessType.trim());
 		cell = row.createCell(7);
-		String resValue = "";
-		String resourceKeyVal = "";
-		String resKey = "";
-		Map<String, RangerPolicyResource> resources = policy.getResources();
-		if (resources!=null) {
-			for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
-				resKey = resource.getKey();
-				RangerPolicyResource policyResource = resource.getValue();
-				List<String> resvalueList = policyResource.getValues();
-				resValue = resvalueList.toString();
-				resourceKeyVal = resourceKeyVal + " " + resKey + "=" + resValue;
-			}
+		if (policy.getIsEnabled()) {
+			policyStatus = "Enabled";
+		} else {
+			policyStatus = "Disabled";
 		}
-		cell.setCellValue(resourceKeyVal);
+		cell.setCellValue(policyStatus);
 	}
 
+
 	private void createHeaderRow(Sheet sheet) {
 		CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
 		Font font = sheet.getWorkbook().createFont();
@@ -3236,9 +3603,9 @@ public class ServiceDBStore extends AbstractServiceStore {
 		cellNAME.setCellStyle(cellStyle);
 		cellNAME.setCellValue("Name");
 
-		Cell cellStatus = row.createCell(2);
-		cellStatus.setCellStyle(cellStyle);
-		cellStatus.setCellValue("Status");
+		Cell cellResources = row.createCell(2);
+		cellResources.setCellStyle(cellStyle);
+		cellResources.setCellValue("Resources");
 
 		Cell cellGroups = row.createCell(3);
 		cellGroups.setCellStyle(cellStyle);
@@ -3248,16 +3615,16 @@ public class ServiceDBStore extends AbstractServiceStore {
 		cellUsers.setCellStyle(cellStyle);
 		cellUsers.setCellValue("Users");
 
-		Cell cellServiceType = row.createCell(5);
-		cellServiceType.setCellStyle(cellStyle);
-		cellServiceType.setCellValue("Service Type");
-
-		Cell cellAccesses = row.createCell(6);
+		Cell cellAccesses = row.createCell(5);
 		cellAccesses.setCellStyle(cellStyle);
 		cellAccesses.setCellValue("Accesses");
 
-		Cell cellResources = row.createCell(7);
-		cellResources.setCellStyle(cellStyle);
-		cellResources.setCellValue("Resources");
+		Cell cellServiceType = row.createCell(6);
+		cellServiceType.setCellStyle(cellStyle);
+		cellServiceType.setCellValue("Service Type");
+
+		Cell cellStatus = row.createCell(7);
+		cellStatus.setCellStyle(cellStyle);
+		cellStatus.setCellValue("Status");
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index 19a1509..052254d 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -19,6 +19,7 @@
 
 package org.apache.ranger.rest;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -1526,6 +1527,41 @@ public class ServiceREST {
 
 	}
 
+	@GET
+	@Path("/policies/csv")
+	@Produces("text/csv")
+	public void getPoliciesInCsv(@Context HttpServletRequest request, @Context HttpServletResponse
response) throws IOException {
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("==> ServiceREST.getPoliciesInCsv()");
+		}
+		RangerPerfTracer perf = null;
+
+		SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
+
+		try {
+			if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+				perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getPoliciesInCsv()");
+			}
+			List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
+			if (filter != null) {
+				filter.setStartIndex(0);
+				filter.setMaxRows(Integer.MAX_VALUE);
+				policies = svcStore.getPoliciesForReports(filter);
+			}
+			svcStore.getPoliciesInCSV(policies, response);
+
+		} catch (WebApplicationException excp) {
+			throw excp;
+		} catch (Throwable excp) {
+			LOG.error("Error while downloading policy report", excp);
+
+			throw restErrorUtil.createRESTException(excp.getMessage());
+		} finally {
+			RangerPerfTracer.log(perf);
+		}
+	}
+
 
 	public List<RangerPolicy> getPolicies(SearchFilter filter) {
 		if(LOG.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/webapp/scripts/views/reports/UserAccessLayout.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/reports/UserAccessLayout.js b/security-admin/src/main/webapp/scripts/views/reports/UserAccessLayout.js
index c3acf6b..4c02504 100644
--- a/security-admin/src/main/webapp/scripts/views/reports/UserAccessLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/reports/UserAccessLayout.js
@@ -76,7 +76,6 @@ define(function(require) {'use strict';
 			btnShowLessUsers 	: '[data-id="showLessUsers"]',
 			componentType       : '[data-id="component"]',
 			downloadReport      : '[data-id="downloadReport"]',
-			downloadBtn         : '[data-js="downloadBtn"]',
 			policyType          : '[data-id="policyType"]'
 		},
 
@@ -90,7 +89,7 @@ define(function(require) {'use strict';
 			events['click ' + this.ui.btnShowLess]  = 'onShowLess';
 			events['click ' + this.ui.btnShowMoreUsers]  = 'onShowMoreUsers';
 			events['click ' + this.ui.btnShowLessUsers]  = 'onShowLessUsers';
-			events['click ' + this.ui.downloadBtn] = 'onDownload';
+			events['click .downloadFormat'] = 'setDownloadFormatFilter';
 			return events;
 		},
 
@@ -103,7 +102,7 @@ define(function(require) {'use strict';
 			_.extend(this, _.pick(options, 'groupList','userList'));
 			this.bindEvents();
 			this.previousSearchUrl = '';
-			this.searchedFlag = true;
+			this.searchedFlag = false;
 			this.allowDownload = false;
 		},
 		initializeRequiredData : function() {
@@ -206,18 +205,51 @@ define(function(require) {'use strict';
 					editable: false,
 					sortable : false
 				},
-				isEnabled:{
-					label:localization.tt('lbl.status'),
-					cell :"html",
-					editable:false,
+				resources:
+				{
+					label: 'Resources',
+					cell: 'Html',
 					formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
-						fromRaw: function (rawValue) {
-							return rawValue ? '<label class="label label-success">Enabled</label>'
: '<label class="label label-important">Disabled</label>';
+						fromRaw: function (rawValue,model) {
+							var strVal = '', names = '';
+							var resource = model.get('resources');
+							_.each(resource,function(resourceObj,key){
+								strVal += "<b>"+key+":</b>";
+								strVal += "<span title='";
+								names = '';
+								_.map(resourceObj.values,function(resourceVal){
+									names += resourceVal+",";
+								});
+								names = names.slice(0,-1);
+								strVal += names + "'>"+names +"</span>";
+								strVal = strVal+ "<br />";
+							});
+							return strVal;
+							}
+					}),
+					editable: false,
+					sortable: false,
+					click: false
+				},
+				policyType: {
+					label: 'Policy Type',
+					cell: Backgrid.HtmlCell.extend({className: 'cellWidth-1', className: 'html-cell'}),
+					formatter: _.extend({}, Backgrid.CellFormatter.prototype,{
+						fromRaw: function(rawValue,model){
+							var policyType = model.get("policyType");
+							var startLbl = '<label class="label label-ranger" style="float:inherit;">';
+							if (XAUtil.isMaskingPolicy(policyType)) {
+								return startLbl + XAEnums.RangerPolicyType.RANGER_MASKING_POLICY_TYPE.label + '</label>';
+							} else if (XAUtil.isRowFilterPolicy(policyType)) {
+								return startLbl + XAEnums.RangerPolicyType.RANGER_ROW_FILTER_POLICY_TYPE.label +
'</label>';
+							}else{// by default it is access
+								return startLbl + XAEnums.RangerPolicyType.RANGER_ACCESS_POLICY_TYPE.label + '</label>';
+							}
 						}
 					}),
-					click : false,
-					drag : false,
-					sortable : false
+					editable: false,
+					sortable: false,
+					click: false
 				},
 				permissions: {
 					label: 'Permissions',
@@ -254,9 +286,9 @@ define(function(require) {'use strict';
 										});
 										
 									}
-									htmlStr += '<tr style="height:60px"><td style ="width:80px">'+grpStr+'</td>\
-												<td style="width:80px">'+(userStr)+'</td>\
-												<td style="width:150px">'+accessStr+'</td></tr>';
+									htmlStr += '<tr style="height:60px"><td class="report-user-group">'+grpStr+'</td>\
+												<td class="report-user-group">'+(userStr)+'</td>\
+												<td class="report-access">'+accessStr+'</td></tr>';
 									accessStr = '', grpStr = '', userStr = '';
 								});
 								return htmlStr;
@@ -269,32 +301,20 @@ define(function(require) {'use strict';
 					sortable: false,
 					click: false
 				},
-				resources:
-				{
-					label: 'Resources',
-					cell: 'Html',
+				isEnabled:{
+					label:localization.tt('lbl.status'),
+					cell :"html",
+					editable:false,
 					formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
-						fromRaw: function (rawValue,model) {
-							var strVal = '', names = '';
-							var resource = model.get('resources');
-							_.each(resource,function(resourceObj,key){
-								strVal += "<b>"+key+":</b>";
-								strVal += "<span title='";
-								names = '';
-								_.map(resourceObj.values,function(resourceVal){
-									names += resourceVal+",";
-								});
-								names = names.slice(0,-1);
-								strVal += names + "'>"+names +"</span>";
-								strVal = strVal+ "<br />";
-							});
-							return strVal;
-							}
+						fromRaw: function (rawValue) {
+							return rawValue ? '<label class="label label-success" style="float:inherit;">Enabled</label>'
: '<label class="label label-important" style="float:inherit;">Disabled</label>';
+						}
 					}),
-					editable: false,
-					sortable: false,
-					click: false
+					click : false,
+					drag : false,
+					sortable : false
 				}
+
 			};
 
 			return coll.constructor.getTableCols(cols, coll);
@@ -327,7 +347,7 @@ define(function(require) {'use strict';
 	},
 	modifyTableForSubcolumns : function(){
 		this.$el.find(".permissions").html('<tr><th colspan="3">Permissions</th></tr>\
-							<tr><th style="width:80px">Groups</th><th style="width:80px">Users</th>\
+							<tr><th style="width:80px;max-width:80px;">Groups</th><th style="width:80px;max-width:80px;">Users</th>\
 							<th style="width:150px">Accesses</th></tr>');
 	},
 	onDownload: function(e){
@@ -338,14 +358,28 @@ define(function(require) {'use strict';
 			});
 			return;
 		}
-		if(this.searchedFlag) {
+		if(!this.searchedFlag) {
 			url =  this.previousSearchUrl;
+		} else if (this.searchedFlag && this.updatedUrl) {
+			var urlString = XAUtil.getBaseUrl();
+			if(urlString.slice(-1) === "/") {
+				urlString = urlString.slice(0,-1);
+			}
+			url = url + urlString;
+			if (e === "xlsFormat") {
+					url = url + '/service/plugins/policies/downloadExcel?';
+			} else {
+					url = url + '/service/plugins/policies/csv?';
+			}
+			url = url + this.searchedParamsString + this.searchedComponentString;
+			this.previousSearchUrl = url;
+			this.searchedFlag = true;
 		}
 		this.ui.downloadReport.attr("href",url)[0].click();
-
 	},
-	getDownloadExcelUrl: function(that,component,params){
-		var compString = '', url = '/service/plugins/policies/downloadExcel?';
+	setDownloadReportUrl: function(that,component,params){
+
+		var compString = '', url = '';
 		if(!_.isUndefined(component)) {
 			_.each(component,function(comp){
 				compString = compString + comp + '_';
@@ -360,11 +394,10 @@ define(function(require) {'use strict';
 			}
 		});
 		var str = jQuery.param( params );
-		url = url + str;
-		if(!_.isEmpty(compString)) {
-			url = url + "&serviceType=" + compString;
-		}
-		return url;
+		this.searchedComponentString = "&serviceType=" + compString;
+		this.searchedParamsString = str;
+		this.updatedUrl = true;
+
 	},
 		/** on render callback */
 		setupGroupAutoComplete : function(){
@@ -567,11 +600,8 @@ define(function(require) {'use strict';
 				policyNamePartial : policyName,
 				policyType: policyType
 			};
-			if(urlString.slice(-1) == "/") {
-				urlString = urlString.slice(0,-1);
-			}
-			url = urlString	+ this.getDownloadExcelUrl(this, component,	params);
-			this.previousSearchUrl = url;
+
+			this.setDownloadReportUrl(this,component,params);
 			this.searchedFlag = true;
         },
 		autocompleteFilter	: function(e){
@@ -591,6 +621,28 @@ define(function(require) {'use strict';
 				$button.text('Username');
 			}
 		},
+		setDownloadFormatFilter : function(e){
+			var that = this;
+			var el = $(e.currentTarget);
+			if(el.data('id') === "xlsFormat") {
+				if(!that.searchedFlag) {
+					var urlString = XAUtil.getBaseUrl();
+					if(urlString.slice(-1) === "/") {
+						urlString = urlString.slice(0,-1);
+					}
+				}
+				this.previousSearchUrl = urlString + "/service/plugins/policies/downloadExcel?";
+			} else {
+				if(!that.searchedFlag) {
+					var urlString = XAUtil.getBaseUrl();
+					if(urlString.slice(-1) === "/") {
+						urlString = urlString.slice(0,-1);
+					}
+					this.previousSearchUrl = urlString + "/service/plugins/policies/csv?";
+				}
+			}
+			this.onDownload(el.data('id'));
+		},
 		gotoTable : function(e){
 			var that = this, elem = $(e.currentTarget),pos;
 			var scroll = false;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
index ecd97e8..a766705 100644
--- a/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/users/UserTableLayout.js
@@ -63,8 +63,6 @@ define(function(require){
     		btnSave		: '[data-id="save"]',
     		btnShowHide		: '[data-action="showHide"]',
 			visibilityDropdown		: '[data-id="visibilityDropdown"]',
-			activeStatusDropdown		: '[data-id="activeStatusDropdown"]',
-			activeStatusDiv		:'[data-id="activeStatusDiv"]',
 			addNewBtnDiv	: '[data-id="addNewBtnDiv"]',
 			deleteUser: '[data-id="deleteUserGroup"]'
     	},
@@ -77,7 +75,6 @@ define(function(require){
 			events['click ' + this.ui.btnShowLess]  = 'onShowLess';
 			events['click ' + this.ui.btnSave]  = 'onSave';
 			events['click ' + this.ui.visibilityDropdown +' li a']  = 'onVisibilityChange';
-			events['click ' + this.ui.activeStatusDropdown +' li a']  = 'onStatusChange';
 			events['click ' + this.ui.deleteUser] = 'onDeleteUser';
 			return events;
 		},
@@ -168,38 +165,6 @@ define(function(require){
                 });
 			}
 		},
-		onStatusChange : function(e){
-			var that = this;
-			var status = $(e.currentTarget).attr('data-id') == 'Enable' ? true : false;
-			var updateMap = {};
-			var collection = this.showUsers ? this.collection : this.groupList;
-
-			_.each(collection.selected, function(s){
-				if( s.get('status') != status ){
-					s.set('status', status);
-					s.toServerStatus();
-					updateMap[s.get('id')] = s.get('status');
-				}
-			});
-
-			var clearCache = function(coll){
-                _.each(Backbone.fetchCache._cache, function(url, val){
-                   var urlStr = coll.url;
-                   if((val.indexOf(urlStr) != -1)){
-                       Backbone.fetchCache.clearItem(val);
-                   }
-                });
-                coll.fetch({reset: true, cache : false});
-			}
-			if(this.showUsers){
-				collection.setStatus(updateMap, {
-					success : function(){
-						that.chgFlags = [];
-						clearCache(collection);
-					}
-				});
-			}
-		},
 		renderUserTab : function(){
 			var that = this;
 			if(_.isUndefined(this.collection)){
@@ -217,7 +182,6 @@ define(function(require){
 				if(!_.isString(that.ui.addNewGroup)){
 					that.ui.addNewGroup.hide();
 					that.ui.addNewUser.show();
-					that.ui.activeStatusDiv.show();
 				}
 				that.$('.wrap-header').text('User List');
 				that.checkRoleKeyAdmin();
@@ -237,7 +201,6 @@ define(function(require){
 			}).done(function(){
 				that.ui.addNewUser.hide();
 				that.ui.addNewGroup.show();
-				that.ui.activeStatusDiv.hide();
 				that.$('.wrap-header').text('Group List');
 				that.$('ul').find('[data-js="groups"]').addClass('active');
 				that.$('ul').find('[data-js="users"]').removeClass();
@@ -364,25 +327,7 @@ define(function(require){
 					}),
 					editable:false,
 					sortable:false
-				},
-				status : {
-					label	: localization.tt("lbl.status"),
-					cell	: Backgrid.HtmlCell.extend({className: 'cellWidth-1'}),
-					formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
-						fromRaw: function (rawValue, model) {
-							if(!_.isUndefined(rawValue)){
-								if(rawValue)
-									return '<span class="label label-success">'+XAEnums.ActiveStatus.STATUS_ENABLED.label+'</span>';
-								else
-									return '<span class="label label-green">'+XAEnums.ActiveStatus.STATUS_DISABLED.label+'</span>';
-							}else
-								return '--';
-						}
-					}),
-					editable:false,
-					sortable:false
-				},
-				
+				}
 			};
 			return this.collection.constructor.getTableCols(cols, this.collection);
 		},

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/webapp/styles/xa.css
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/styles/xa.css b/security-admin/src/main/webapp/styles/xa.css
index b586e11..a451761 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1915,10 +1915,6 @@ input[type="radio"], input[type="checkbox"] {margin-top: 0;}
     margin-top: -2px;
     font-size: 11px;
 }
-.backgrid > tbody > tr > td:nth-child(5) {
-  text-align: left !important;
-  width: 200px
-}
 .control-label-align {
 	width: 80px !important;
 }
@@ -1944,3 +1940,48 @@ input[type="radio"], input[type="checkbox"] {margin-top: 0;}
 .permissionItemSortable > tr:hover > td:first-child:after {
   border-color: rgba(0,0,0,0.5);
 }
+.download-list {
+  min-width: 100px;
+  max-width: 120px;
+}
+.hdfs-table table.backgrid thead th:nth-child(1){
+  width: 60px;
+  max-width: 60px
+}
+.hdfs-table table.backgrid thead th:nth-child(2) {
+  /*width: 300px;*/
+  width: 25%;
+}
+.hdfs-table table.backgrid thead th:nth-child(3){
+  width:200px;
+}
+.hdfs-table table.backgrid thead th:nth-child(4){
+  width:100px;
+}
+.hdfs-table table.backgrid tbody td:nth-child(4){
+  width:100px;
+  text-align: center;
+}
+.hdfs-table table.backgrid tbody tr td:nth-child(3){
+ text-align: left !important;
+ max-width: 200px;
+}
+.hdfs-table table.backgrid tbody tr td:nth-child(6){
+  text-align: center;
+  width: 100px
+}
+.hdfs-table table.backgrid thead th:nth-child(6){
+  text-align: center;
+  width: 100px;
+}
+.hdfs-table table.backgrid thead th:nth-child(5) tr{
+  border-left-style: hidden;
+}
+.report-access{
+  width:100%;
+  border-right:1px solid #DDD;
+}
+.report-user-group{
+  width:80px;
+  min-width:80px;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/webapp/templates/reports/UserAccessLayout_tmpl.html
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/templates/reports/UserAccessLayout_tmpl.html b/security-admin/src/main/webapp/templates/reports/UserAccessLayout_tmpl.html
index 48741ce..df7acfb 100644
--- a/security-admin/src/main/webapp/templates/reports/UserAccessLayout_tmpl.html
+++ b/security-admin/src/main/webapp/templates/reports/UserAccessLayout_tmpl.html
@@ -96,10 +96,18 @@
 	</div>
 	<div class="row-fluid">
 	<span>
-		<button type="button" class="btn btn-primary btn-small btn-right" data-js="downloadBtn"
title="Download all below policies" name="downloadPolicy">
-								<i class="icon-download-alt"></i>
-										Download
+		<div class="btn-group btn-right">
+			<button type="button" data-name="downloadFormatBtn" class="btn btn-primary dropdown-toggle"
title="Download all below policies" data-toggle="dropdown">
+				<i class="icon-download-alt"></i>
+				<span>Download</span>
+				<span class="caret"> </span>
 			</button>
+			<ul class="dropdown-menu download-list">
+				<li><a data-id="xlsFormat" class="downloadFormat" href="javascript:void(0)">Excel
file</a></li>
+				<li role="separator" class="divider"></li>
+				<li><a data-id="csvFormat" class="downloadFormat" href="javascript:void(0)">CSV
file</a></li>
+			</ul>
+		</div>
 	</span>
 	<a href="javascript:void(0)" data-id="downloadReport"></a>
 	 </div>

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/7d452069/security-admin/src/main/webapp/templates/users/UserTableLayout_tmpl.html
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/templates/users/UserTableLayout_tmpl.html b/security-admin/src/main/webapp/templates/users/UserTableLayout_tmpl.html
index f7c90f3..b7d4967 100644
--- a/security-admin/src/main/webapp/templates/users/UserTableLayout_tmpl.html
+++ b/security-admin/src/main/webapp/templates/users/UserTableLayout_tmpl.html
@@ -33,8 +33,6 @@
 			{{#isSystemAdmin .}}
 				<a href="javascript:void(0);" data-id="deleteUserGroup" title="Permanently delete
selected users/groups" class="btn btn-primary btn-right btn-danger"><i class="icon-trash
icon-large" /></a>
 			{{/isSystemAdmin}}
-			<a href="#!/user/create" class="btn btn-primary btn-right" type="button" data-id="addNewUser">
{{tt 'lbl.addNewUser'}} </a>
-			<a href="#!/group/create" class="btn btn-primary btn-right" type="button" data-id="addNewGroup"
style="display:none;"> {{tt 'lbl.addNewGroup'}} </a>
       <div class="btn-group btn-right">
         <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
           {{tt 'btn.setVisibility'}}
@@ -45,16 +43,8 @@
           <li><a href="javascript:void(0);" data-id="hidden">{{tt 'lbl.VisibilityStatus_IS_HIDDEN'}}</a></li>
         </ul>
       </div>
-      <div class="btn-group btn-right" data-id="activeStatusDiv">
-        <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
-          {{tt 'btn.setStatus'}}
-          <span class="caret"></span>
-        </a>
-        <ul class="dropdown-menu" data-id="activeStatusDropdown">
-          <li><a href="javascript:void(0);" data-id="Enable">{{tt 'lbl.ActiveStatus_STATUS_ENABLED'}}</a></li>
-          <li><a href="javascript:void(0);" data-id="Disable">{{tt 'lbl.ActiveStatus_STATUS_DISABLED'}}</a></li>
-        </ul>
-      </div>
+      <a href="#!/user/create" class="btn btn-primary btn-right" type="button" data-id="addNewUser">
{{tt 'lbl.addNewUser'}} </a>
+      <a href="#!/group/create" class="btn btn-primary btn-right" type="button" data-id="addNewGroup"
style="display:none;"> {{tt 'lbl.addNewGroup'}} </a>
 		</div>
 		<div data-id="r_tableList" class="clickable">
           <b class="_prevNav"></b>



Mime
View raw message