use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemRowFilterInfo in project ranger by apache.
the class ServiceDBStore method writeCSVForPolicyItems.
private void writeCSVForPolicyItems(RangerPolicy policy, RangerPolicyItem policyItem, RangerDataMaskPolicyItem dataMaskPolicyItem, RangerRowFilterPolicyItem rowFilterPolicyItem, StringBuilder csvBuffer, String policyConditionType) {
if (LOG.isDebugEnabled()) {
// To avoid PMD violation
LOG.debug("policyConditionType:[" + policyConditionType + "]");
}
final String COMMA_DELIMITER = "|";
final String LINE_SEPARATOR = "\n";
List<String> groups = new ArrayList<String>();
List<String> users = new ArrayList<String>();
String groupNames = "";
String userNames = "";
String policyLabelName = "";
String accessType = "";
String policyStatus = "";
String policyType = "";
Boolean delegateAdmin = false;
String isRecursive = "";
String isExcludes = "";
String serviceName = "";
String description = "";
Boolean isAuditEnabled = true;
String isExcludesValue = "";
String maskingInfo = "";
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<RangerPolicyItemCondition> conditionsList = new ArrayList<RangerPolicyItemCondition>();
String conditionKeyValue = "";
String resValue = "";
String resourceKeyVal = "";
String isRecursiveValue = "";
String resKey = "";
String ServiceType = "";
String filterExpr = "";
String policyName = "";
List<String> policyLabels = new ArrayList<String>();
String policyConditionTypeValue = "";
serviceName = policy.getService();
description = policy.getDescription();
isAuditEnabled = policy.getIsAuditEnabled();
policyLabels = policy.getPolicyLabels();
StringBuffer sb = new StringBuffer();
StringBuffer sbIsRecursive = new StringBuffer();
StringBuffer sbIsExcludes = new StringBuffer();
Map<String, RangerPolicyResource> resources = policy.getResources();
RangerPolicyItemDataMaskInfo dataMaskInfo = new RangerPolicyItemDataMaskInfo();
RangerPolicyItemRowFilterInfo filterInfo = new RangerPolicyItemRowFilterInfo();
policyName = policy.getName();
policyName = policyName.replace("|", "");
if (resources != null) {
for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
resKey = resource.getKey();
RangerPolicyResource policyResource = resource.getValue();
List<String> resvalueList = policyResource.getValues();
isExcludes = policyResource.getIsExcludes().toString();
isRecursive = policyResource.getIsRecursive().toString();
resValue = resvalueList.toString();
sb = sb.append(resourceKeyVal).append(" ").append(resKey).append("=").append(resValue);
sbIsExcludes = sbIsExcludes.append(resourceKeyVal).append(" ").append(resKey).append("=[").append(isExcludes).append("]");
sbIsRecursive = sbIsRecursive.append(resourceKeyVal).append(" ").append(resKey).append("=[").append(isRecursive).append("]");
}
isExcludesValue = sbIsExcludes.toString();
isExcludesValue = isExcludesValue.substring(1);
isRecursiveValue = sbIsRecursive.toString();
isRecursiveValue = isRecursiveValue.substring(1);
resourceKeyVal = sb.toString();
resourceKeyVal = resourceKeyVal.substring(1);
if (policyItem != null && dataMaskPolicyItem == null && rowFilterPolicyItem == null) {
groups = policyItem.getGroups();
users = policyItem.getUsers();
accesses = policyItem.getAccesses();
delegateAdmin = policyItem.getDelegateAdmin();
conditionsList = policyItem.getConditions();
} else if (dataMaskPolicyItem != null && policyItem == null && rowFilterPolicyItem == null) {
groups = dataMaskPolicyItem.getGroups();
users = dataMaskPolicyItem.getUsers();
accesses = dataMaskPolicyItem.getAccesses();
delegateAdmin = dataMaskPolicyItem.getDelegateAdmin();
conditionsList = dataMaskPolicyItem.getConditions();
dataMaskInfo = dataMaskPolicyItem.getDataMaskInfo();
String dataMaskType = dataMaskInfo.getDataMaskType();
String conditionExpr = dataMaskInfo.getConditionExpr();
String valueExpr = dataMaskInfo.getValueExpr();
maskingInfo = "dataMasktype=[" + dataMaskType + "]";
if (conditionExpr != null && !conditionExpr.isEmpty() && valueExpr != null && !valueExpr.isEmpty()) {
maskingInfo = maskingInfo + "; conditionExpr=[" + conditionExpr + "]";
}
} else if (rowFilterPolicyItem != null && policyItem == null && dataMaskPolicyItem == null) {
groups = rowFilterPolicyItem.getGroups();
users = rowFilterPolicyItem.getUsers();
accesses = rowFilterPolicyItem.getAccesses();
delegateAdmin = rowFilterPolicyItem.getDelegateAdmin();
conditionsList = rowFilterPolicyItem.getConditions();
filterInfo = rowFilterPolicyItem.getRowFilterInfo();
filterExpr = filterInfo.getFilterExpr();
}
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("#"));
}
String conditionValue = "";
for (RangerPolicyItemCondition conditions : conditionsList) {
String conditionType = conditions.getType();
List<String> conditionList = conditions.getValues();
conditionValue = conditionList.toString();
conditionKeyValue = conditionType + "=" + conditionValue;
}
XXService xxservice = daoMgr.getXXService().findByName(policy.getService());
if (xxservice != null) {
Long ServiceId = xxservice.getType();
XXServiceDef xxservDef = daoMgr.getXXServiceDef().getById(ServiceId);
if (xxservDef != null) {
ServiceType = xxservDef.getName();
}
}
}
if (policyConditionType != null) {
policyConditionTypeValue = policyConditionType;
}
if (policyConditionType == null && ServiceType.equalsIgnoreCase("tag")) {
policyConditionTypeValue = POLICY_ALLOW_INCLUDE;
} else if (policyConditionType == null) {
policyConditionTypeValue = "";
}
if (policy.getIsEnabled()) {
policyStatus = "Enabled";
} else {
policyStatus = "Disabled";
}
int policyTypeInt = policy.getPolicyType();
switch(policyTypeInt) {
case RangerPolicy.POLICY_TYPE_ACCESS:
policyType = POLICY_TYPE_ACCESS;
break;
case RangerPolicy.POLICY_TYPE_DATAMASK:
policyType = POLICY_TYPE_DATAMASK;
break;
case RangerPolicy.POLICY_TYPE_ROWFILTER:
policyType = POLICY_TYPE_ROWFILTER;
break;
}
if (CollectionUtils.isNotEmpty(policyLabels)) {
for (String policyLabel : policyLabels) {
policyLabel = policyLabel.replace("|", "");
policyLabel = policyLabel.replace("#", "");
policyLabelName = policyLabelName + policyLabel + "#";
}
policyLabelName = policyLabelName.substring(0, policyLabelName.lastIndexOf("#"));
}
csvBuffer.append(policy.getId());
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.trim());
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(ServiceType);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(policyStatus);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(policyType);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(delegateAdmin.toString().toUpperCase());
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(isRecursiveValue);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(isExcludesValue);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(serviceName);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(description);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(isAuditEnabled.toString().toUpperCase());
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(conditionKeyValue.trim());
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(policyConditionTypeValue);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(maskingInfo);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(filterExpr);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(policyLabelName);
csvBuffer.append(COMMA_DELIMITER);
csvBuffer.append(LINE_SEPARATOR);
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemRowFilterInfo in project ranger by apache.
the class ServiceDBStore method createNewRowFilterPolicyItemsForPolicy.
private void createNewRowFilterPolicyItemsForPolicy(RangerPolicy policy, XXPolicy xPolicy, List<RangerRowFilterPolicyItem> policyItems, XXServiceDef xServiceDef, int policyItemType) throws Exception {
if (CollectionUtils.isNotEmpty(policyItems)) {
for (int itemOrder = 0; itemOrder < policyItems.size(); itemOrder++) {
RangerRowFilterPolicyItem policyItem = policyItems.get(itemOrder);
XXPolicyItem xPolicyItem = createNewPolicyItemForPolicy(policy, xPolicy, policyItem, xServiceDef, itemOrder, policyItemType);
RangerPolicyItemRowFilterInfo dataMaskInfo = policyItem.getRowFilterInfo();
if (dataMaskInfo != null) {
XXPolicyItemRowFilterInfo xxRowFilterInfo = new XXPolicyItemRowFilterInfo();
xxRowFilterInfo.setPolicyItemId(xPolicyItem.getId());
xxRowFilterInfo.setFilterExpr(dataMaskInfo.getFilterExpr());
xxRowFilterInfo = daoMgr.getXXPolicyItemRowFilterInfo().create(xxRowFilterInfo);
}
}
}
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemRowFilterInfo in project ranger by apache.
the class RangerDefaultRowFilterPolicyItemEvaluator method updateAccessResult.
@Override
public void updateAccessResult(RangerAccessResult result, RangerPolicyResourceMatcher.MatchType matchType, RangerPolicy policy) {
RangerPolicyItemRowFilterInfo rowFilterInfo = getRowFilterInfo();
if (rowFilterInfo != null) {
result.setIsAllowed(true);
result.setIsAccessDetermined(true);
result.setFilterExpr(rowFilterInfo.getFilterExpr());
result.setPolicyPriority(policy.getPolicyPriority());
result.setPolicyId(policyId);
}
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemRowFilterInfo in project ranger by apache.
the class ServiceDBStore method writeBookForPolicyItems.
private void writeBookForPolicyItems(RangerPolicy policy, RangerPolicyItem policyItem, RangerDataMaskPolicyItem dataMaskPolicyItem, RangerRowFilterPolicyItem rowFilterPolicyItem, Row row, String policyConditionType) {
if (LOG.isDebugEnabled()) {
// To avoid PMD violation
LOG.debug("policyConditionType:[" + policyConditionType + "]");
}
List<String> groups = new ArrayList<String>();
List<String> users = new ArrayList<String>();
String groupNames = "";
String policyConditionTypeValue = "";
String userNames = "";
String policyLabelNames = "";
String accessType = "";
String policyStatus = "";
String policyType = "";
Boolean delegateAdmin = false;
String isRecursive = "";
String isExcludes = "";
String serviceName = "";
String description = "";
Boolean isAuditEnabled = true;
isAuditEnabled = policy.getIsAuditEnabled();
String isExcludesValue = "";
Cell cell = row.createCell(0);
cell.setCellValue(policy.getId());
List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
List<RangerPolicyItemCondition> conditionsList = new ArrayList<RangerPolicyItemCondition>();
String conditionKeyValue = "";
List<String> policyLabels = new ArrayList<String>();
String resValue = "";
String resourceKeyVal = "";
String isRecursiveValue = "";
String resKey = "";
StringBuffer sb = new StringBuffer();
StringBuffer sbIsRecursive = new StringBuffer();
StringBuffer sbIsExcludes = new StringBuffer();
Map<String, RangerPolicyResource> resources = policy.getResources();
RangerPolicyItemDataMaskInfo dataMaskInfo = new RangerPolicyItemDataMaskInfo();
RangerPolicyItemRowFilterInfo filterInfo = new RangerPolicyItemRowFilterInfo();
cell = row.createCell(1);
cell.setCellValue(policy.getName());
cell = row.createCell(2);
if (resources != null) {
for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
resKey = resource.getKey();
RangerPolicyResource policyResource = resource.getValue();
List<String> resvalueList = policyResource.getValues();
isExcludes = policyResource.getIsExcludes().toString();
isRecursive = policyResource.getIsRecursive().toString();
resValue = resvalueList.toString();
sb = sb.append(resourceKeyVal).append("; ").append(resKey).append("=").append(resValue);
sbIsExcludes = sbIsExcludes.append(resourceKeyVal).append("; ").append(resKey).append("=[").append(isExcludes).append("]");
sbIsRecursive = sbIsRecursive.append(resourceKeyVal).append("; ").append(resKey).append("=[").append(isRecursive).append("]");
}
isExcludesValue = sbIsExcludes.toString();
isExcludesValue = isExcludesValue.substring(1);
isRecursiveValue = sbIsRecursive.toString();
isRecursiveValue = isRecursiveValue.substring(1);
resourceKeyVal = sb.toString();
resourceKeyVal = resourceKeyVal.substring(1);
cell.setCellValue(resourceKeyVal);
if (policyItem != null && dataMaskPolicyItem == null && rowFilterPolicyItem == null) {
groups = policyItem.getGroups();
users = policyItem.getUsers();
accesses = policyItem.getAccesses();
delegateAdmin = policyItem.getDelegateAdmin();
conditionsList = policyItem.getConditions();
} else if (dataMaskPolicyItem != null && policyItem == null && rowFilterPolicyItem == null) {
groups = dataMaskPolicyItem.getGroups();
users = dataMaskPolicyItem.getUsers();
accesses = dataMaskPolicyItem.getAccesses();
delegateAdmin = dataMaskPolicyItem.getDelegateAdmin();
conditionsList = dataMaskPolicyItem.getConditions();
dataMaskInfo = dataMaskPolicyItem.getDataMaskInfo();
String dataMaskType = dataMaskInfo.getDataMaskType();
String conditionExpr = dataMaskInfo.getConditionExpr();
String valueExpr = dataMaskInfo.getValueExpr();
String maskingInfo = "dataMasktype=[" + dataMaskType + "]";
if (conditionExpr != null && !conditionExpr.isEmpty() && valueExpr != null && !valueExpr.isEmpty()) {
maskingInfo = maskingInfo + "; conditionExpr=[" + conditionExpr + "]";
}
cell = row.createCell(17);
cell.setCellValue(maskingInfo);
} else if (rowFilterPolicyItem != null && policyItem == null && dataMaskPolicyItem == null) {
groups = rowFilterPolicyItem.getGroups();
users = rowFilterPolicyItem.getUsers();
accesses = rowFilterPolicyItem.getAccesses();
delegateAdmin = rowFilterPolicyItem.getDelegateAdmin();
conditionsList = rowFilterPolicyItem.getConditions();
filterInfo = rowFilterPolicyItem.getRowFilterInfo();
String filterExpr = filterInfo.getFilterExpr();
cell = row.createCell(18);
cell.setCellValue(filterExpr);
}
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();
}
String conditionValue = "";
for (RangerPolicyItemCondition conditions : conditionsList) {
String conditionType = conditions.getType();
List<String> conditionList = conditions.getValues();
conditionValue = conditionList.toString();
conditionKeyValue = conditionType + "=" + conditionValue;
}
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();
}
}
if (policyConditionType != null) {
policyConditionTypeValue = policyConditionType;
}
if (policyConditionType == null && ServiceType.equalsIgnoreCase("tag")) {
policyConditionTypeValue = POLICY_ALLOW_INCLUDE;
} else if (policyConditionType == null) {
policyConditionTypeValue = "";
}
cell.setCellValue(ServiceType);
cell = row.createCell(7);
}
if (policy.getIsEnabled()) {
policyStatus = "Enabled";
} else {
policyStatus = "Disabled";
}
policyLabels = policy.getPolicyLabels();
if (CollectionUtils.isNotEmpty(policyLabels)) {
policyLabelNames = policyLabelNames + policyLabels.toString();
StringTokenizer policyLabelToken = new StringTokenizer(policyLabelNames, "[]");
policyLabelNames = policyLabelToken.nextToken().toString();
}
cell.setCellValue(policyStatus);
cell = row.createCell(8);
int policyTypeInt = policy.getPolicyType();
switch(policyTypeInt) {
case RangerPolicy.POLICY_TYPE_ACCESS:
policyType = POLICY_TYPE_ACCESS;
break;
case RangerPolicy.POLICY_TYPE_DATAMASK:
policyType = POLICY_TYPE_DATAMASK;
break;
case RangerPolicy.POLICY_TYPE_ROWFILTER:
policyType = POLICY_TYPE_ROWFILTER;
break;
}
cell.setCellValue(policyType);
cell = row.createCell(9);
cell.setCellValue(delegateAdmin.toString().toUpperCase());
cell = row.createCell(10);
cell.setCellValue(isRecursiveValue);
cell = row.createCell(11);
cell.setCellValue(isExcludesValue);
cell = row.createCell(12);
serviceName = policy.getService();
cell.setCellValue(serviceName);
cell = row.createCell(13);
description = policy.getDescription();
cell.setCellValue(description);
cell = row.createCell(14);
cell.setCellValue(isAuditEnabled.toString().toUpperCase());
cell = row.createCell(15);
cell.setCellValue(conditionKeyValue.trim());
cell = row.createCell(16);
cell.setCellValue(policyConditionTypeValue);
cell = row.createCell(19);
cell.setCellValue(policyLabelNames);
}
Aggregations