use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceUtil method toRangerService.
public RangerService toRangerService(VXAsset asset) {
if (asset == null) {
return null;
}
RangerService ret = new RangerService();
dataObjectToRangerObject(asset, ret);
ret.setType(toServiceType(asset.getAssetType()));
ret.setName(asset.getName());
ret.setDescription(asset.getDescription());
ret.setIsEnabled(asset.getActiveStatus() == RangerCommonEnums.STATUS_ENABLED);
ret.setConfigs(jsonUtil.jsonToMap(asset.getConfig()));
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceUtil method toGrantRevokeRequest.
public GrantRevokeRequest toGrantRevokeRequest(VXPolicy vXPolicy) {
String serviceType = null;
RangerService service = null;
GrantRevokeRequest ret = new GrantRevokeRequest();
if (vXPolicy != null) {
String serviceName = vXPolicy.getRepositoryName();
try {
service = svcStore.getServiceByName(serviceName);
} catch (Exception e) {
LOG.error(HttpServletResponse.SC_BAD_REQUEST + "No Service Found for ServiceName:" + serviceName);
throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage() + serviceName, true);
}
if (service != null) {
serviceType = service.getType();
} else {
LOG.error(HttpServletResponse.SC_BAD_REQUEST + "No Service Found for ServiceName" + serviceName);
throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, "No Service Found for ServiceName" + serviceName, true);
}
if (vXPolicy.getGrantor() != null) {
ret.setGrantor(vXPolicy.getGrantor());
}
ret.setEnableAudit(Boolean.TRUE);
ret.setIsRecursive(Boolean.FALSE);
ret.setReplaceExistingPermissions(toBooleanReplacePerm(vXPolicy.isReplacePerm()));
Integer assetType = toAssetType(serviceType);
if (assetType == RangerCommonEnums.ASSET_HIVE) {
String database = StringUtils.isEmpty(vXPolicy.getDatabases()) ? "*" : vXPolicy.getDatabases();
String table = getTableOrUdf(vXPolicy);
String column = StringUtils.isEmpty(vXPolicy.getColumns()) ? "*" : vXPolicy.getColumns();
Map<String, String> mapResource = new HashMap<String, String>();
mapResource.put("database", database);
mapResource.put("table", table);
mapResource.put("column", column);
ret.setResource(mapResource);
} else if (assetType == RangerCommonEnums.ASSET_HBASE) {
String tableName = vXPolicy.getTables();
tableName = StringUtil.isEmpty(tableName) ? "*" : tableName;
String colFamily = vXPolicy.getColumnFamilies();
colFamily = StringUtil.isEmpty(colFamily) ? "*" : colFamily;
String qualifier = vXPolicy.getColumns();
qualifier = StringUtil.isEmpty(qualifier) ? "*" : qualifier;
Map<String, String> mapResource = new HashMap<String, String>();
mapResource.put("table", tableName);
mapResource.put("column-family", colFamily);
mapResource.put("column", qualifier);
}
List<VXPermObj> vXPermObjList = vXPolicy.getPermMapList();
if (vXPermObjList != null) {
for (VXPermObj vXPermObj : vXPermObjList) {
boolean delegatedAdmin = false;
if (vXPermObj.getUserList() != null) {
for (String user : vXPermObj.getUserList()) {
if (user.contains(getUserName(user))) {
ret.getUsers().add(user);
}
}
}
if (vXPermObj.getGroupList() != null) {
for (String group : vXPermObj.getGroupList()) {
if (group.contains(getGroupName(group))) {
ret.getGroups().add(group);
}
}
}
if (vXPermObj.getPermList() != null) {
for (String perm : vXPermObj.getPermList()) {
if (AppConstants.getEnumFor_XAPermType(perm) != 0) {
if ("Admin".equalsIgnoreCase(perm)) {
delegatedAdmin = true;
if (assetType != null && assetType.intValue() != RangerCommonEnums.ASSET_HBASE) {
continue;
}
}
ret.getAccessTypes().add(perm);
}
}
}
if (delegatedAdmin) {
ret.setDelegateAdmin(Boolean.TRUE);
} else {
ret.setDelegateAdmin(Boolean.FALSE);
}
}
}
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceDBStore method deletePolicy.
@Override
public void deletePolicy(Long policyId) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deletePolicy(" + policyId + ")");
}
RangerPolicy policy = getPolicy(policyId);
if (policy == null) {
throw new Exception("no policy exists with ID=" + policyId);
}
String policyName = policy.getName();
RangerService service = getServiceByName(policy.getService());
if (service == null) {
throw new Exception("service does not exist - name='" + policy.getService());
}
Long version = policy.getVersion();
if (version == null) {
version = Long.valueOf(1);
LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
} else {
version = Long.valueOf(version.longValue() + 1);
}
policy.setVersion(version);
List<XXTrxLog> trxLogList = policyService.getTransactionLog(policy, RangerPolicyService.OPERATION_DELETE_CONTEXT);
deleteExistingPolicyItems(policy);
deleteExistingPolicyResources(policy);
deleteExistingPolicyLabel(policy);
policyService.delete(policy);
handlePolicyUpdate(service, true);
dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE);
bizUtil.createTrxLog(trxLogList);
LOG.info("Policy Deleted Successfully. PolicyName : " + policyName);
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceDBStore method updateServiceWithCustomProperty.
private void updateServiceWithCustomProperty() {
LOG.info("Adding custom properties to services");
SearchFilter filter = new SearchFilter();
try {
List<RangerService> lstRangerService = getServices(filter);
for (RangerService rangerService : lstRangerService) {
String serviceUser = PropertiesUtil.getProperty("ranger.plugins." + rangerService.getType() + ".serviceuser");
if (!StringUtils.isEmpty(serviceUser)) {
boolean chkServiceUpdate = false;
LOG.debug("customproperty = " + rangerService.getConfigs().get(ServiceREST.Allowed_User_List_For_Download) + " for service = " + rangerService.getName());
if (!rangerService.getConfigs().containsKey(ServiceREST.Allowed_User_List_For_Download)) {
rangerService.getConfigs().put(ServiceREST.Allowed_User_List_For_Download, serviceUser);
chkServiceUpdate = true;
}
if ((!rangerService.getConfigs().containsKey(ServiceREST.Allowed_User_List_For_Grant_Revoke)) && ("hbase".equalsIgnoreCase(rangerService.getType()) || "hive".equalsIgnoreCase(rangerService.getType()))) {
rangerService.getConfigs().put(ServiceREST.Allowed_User_List_For_Grant_Revoke, serviceUser);
chkServiceUpdate = true;
}
if (!rangerService.getConfigs().containsKey(TagREST.Allowed_User_List_For_Tag_Download)) {
rangerService.getConfigs().put(TagREST.Allowed_User_List_For_Tag_Download, serviceUser);
chkServiceUpdate = true;
}
if (chkServiceUpdate) {
updateService(rangerService, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Updated service " + rangerService.getName() + " with custom properties in secure environment");
}
}
}
}
} catch (Throwable e) {
LOG.fatal("updateServiceWithCustomProperty failed with exception : " + e.getMessage());
}
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceDBStore method deletePolicy.
public void deletePolicy(RangerPolicy policy) throws Exception {
if (policy == null) {
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deletePolicy(" + policy.getId() + ")");
}
RangerService service = getServiceByName(policy.getService());
if (service == null) {
throw new Exception("service does not exist - name='" + policy.getService());
}
Long version = policy.getVersion();
if (version == null) {
version = Long.valueOf(1);
LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
} else {
version = Long.valueOf(version.longValue() + 1);
}
policy.setVersion(version);
List<XXTrxLog> trxLogList = policyService.getTransactionLog(policy, RangerPolicyService.OPERATION_DELETE_CONTEXT);
deleteExistingPolicyItemsNative(policy);
deleteExistingPolicyResourcesNative(policy);
deleteExistingPolicyLabelNative(policy);
daoMgr.getXXPolicy().deletePolicyIDReference("id", policy.getId());
handlePolicyUpdate(service, true);
dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE);
bizUtil.createTrxLog(trxLogList);
}
Aggregations