use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchTagModulePermission_J10005 method trimPolicyName.
private void trimPolicyName() {
List<XXPolicy> policies = daoManager.getXXPolicy().getAll();
if (!CollectionUtils.isEmpty(policies)) {
String policyName = null;
for (XXPolicy xXPolicy : policies) {
try {
if (xXPolicy != null) {
policyName = xXPolicy.getName();
if (!StringUtils.isEmpty(policyName)) {
if (policyName.startsWith(" ") || policyName.endsWith(" ")) {
xXPolicy.setName(StringUtils.trim(policyName));
daoManager.getXXPolicy().update(xXPolicy);
}
}
}
} catch (Exception ex) {
logger.info("Error during policy update:" + xXPolicy.toString());
logger.error(ex);
}
}
}
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PublicAPIs method updatePolicy.
@PUT
@Path("/api/policy/{id}")
@Produces({ "application/json", "application/xml" })
public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy);
}
XXPolicy existing = daoMgr.getXXPolicy().getById(id);
if (existing == null) {
throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND);
}
vXPolicy.setId(id);
RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName());
RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy, service);
VXPolicy ret = null;
if (policy != null) {
policy.setVersion(existing.getVersion());
RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy);
ret = serviceUtil.toVXPolicy(updatedPolicy, service);
}
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret);
}
return ret;
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class ServiceDBStore method getPoliciesByResourceSignature.
@Override
public List<RangerPolicy> getPoliciesByResourceSignature(String serviceName, String policySignature, Boolean isPolicyEnabled) throws Exception {
List<XXPolicy> xxPolicies = daoMgr.getXXPolicy().findByResourceSignatureByPolicyStatus(serviceName, policySignature, isPolicyEnabled);
List<RangerPolicy> policies = new ArrayList<RangerPolicy>(xxPolicies.size());
for (XXPolicy xxPolicy : xxPolicies) {
RangerPolicy policy = policyService.getPopulatedViewObject(xxPolicy);
policies.add(policy);
}
return policies;
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class ServiceDBStore method deleteService.
@Override
public void deleteService(Long id) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deleteService(" + id + ")");
}
RangerService service = getService(id);
if (service == null) {
throw new Exception("no service exists with ID=" + id);
}
List<XXPolicy> policies = daoMgr.getXXPolicy().findByServiceId(service.getId());
RangerPolicy rangerPolicy = null;
for (XXPolicy policy : policies) {
LOG.info("Deleting Policy, policyName: " + policy.getName());
rangerPolicy = getPolicy(policy.getId());
deletePolicy(rangerPolicy);
}
XXServiceConfigMapDao configDao = daoMgr.getXXServiceConfigMap();
List<XXServiceConfigMap> configs = configDao.findByServiceId(service.getId());
for (XXServiceConfigMap configMap : configs) {
configDao.remove(configMap);
}
Long version = service.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);
}
service.setVersion(version);
svcService.delete(service);
dataHistService.createObjectDataHistory(service, RangerDataHistService.ACTION_DELETE);
List<XXTrxLog> trxLogList = svcService.getTransactionLog(service, RangerServiceService.OPERATION_DELETE_CONTEXT);
bizUtil.createTrxLog(trxLogList);
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class ServiceDBStore method updatePolicy.
@Override
public RangerPolicy updatePolicy(RangerPolicy policy) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.updatePolicy(" + policy + ")");
}
XXPolicy xxExisting = daoMgr.getXXPolicy().getById(policy.getId());
RangerPolicy existing = policyService.getPopulatedViewObject(xxExisting);
if (existing == null) {
throw new Exception("no policy exists with ID=" + policy.getId());
}
RangerService service = getServiceByName(policy.getService());
if (service == null) {
throw new Exception("service does not exist - name=" + policy.getService());
}
XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(service.getType());
if (xServiceDef == null) {
throw new Exception("service-def does not exist - name=" + service.getType());
}
if (!StringUtils.equalsIgnoreCase(existing.getService(), policy.getService())) {
throw new Exception("policy id=" + policy.getId() + " already exists in service " + existing.getService() + ". It can not be moved to service " + policy.getService());
}
boolean renamed = !StringUtils.equalsIgnoreCase(policy.getName(), existing.getName());
if (renamed) {
XXPolicy newNamePolicy = daoMgr.getXXPolicy().findByNameAndServiceId(policy.getName(), service.getId());
if (newNamePolicy != null) {
throw new Exception("another policy already exists with name '" + policy.getName() + "'. ID=" + newNamePolicy.getId());
}
}
Map<String, RangerPolicyResource> newResources = policy.getResources();
List<RangerPolicyItem> policyItems = policy.getPolicyItems();
List<RangerPolicyItem> denyPolicyItems = policy.getDenyPolicyItems();
List<RangerPolicyItem> allowExceptions = policy.getAllowExceptions();
List<RangerPolicyItem> denyExceptions = policy.getDenyExceptions();
List<RangerDataMaskPolicyItem> dataMaskPolicyItems = policy.getDataMaskPolicyItems();
List<RangerRowFilterPolicyItem> rowFilterItems = policy.getRowFilterPolicyItems();
List<String> policyLabels = policy.getPolicyLabels();
policy.setCreateTime(xxExisting.getCreateTime());
policy.setGuid(xxExisting.getGuid());
policy.setVersion(xxExisting.getVersion());
List<XXTrxLog> trxLogList = policyService.getTransactionLog(policy, xxExisting, RangerPolicyService.OPERATION_UPDATE_CONTEXT);
updatePolicySignature(policy);
boolean isTagVersionUpdateNeeded = false;
if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME.equals(service.getType())) {
isTagVersionUpdateNeeded = existing.getIsEnabled() ? !policy.getIsEnabled() : policy.getIsEnabled();
isTagVersionUpdateNeeded = isTagVersionUpdateNeeded || !StringUtils.equals(existing.getResourceSignature(), policy.getResourceSignature());
}
policy = policyService.update(policy);
XXPolicy newUpdPolicy = daoMgr.getXXPolicy().getById(policy.getId());
deleteExistingPolicyResources(policy);
deleteExistingPolicyItems(policy);
deleteExistingPolicyLabel(policy);
createNewResourcesForPolicy(policy, newUpdPolicy, newResources);
createNewPolicyItemsForPolicy(policy, newUpdPolicy, policyItems, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_ALLOW);
createNewPolicyItemsForPolicy(policy, newUpdPolicy, denyPolicyItems, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_DENY);
createNewPolicyItemsForPolicy(policy, newUpdPolicy, allowExceptions, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_ALLOW_EXCEPTIONS);
createNewPolicyItemsForPolicy(policy, newUpdPolicy, denyExceptions, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_DENY_EXCEPTIONS);
createNewDataMaskPolicyItemsForPolicy(policy, newUpdPolicy, dataMaskPolicyItems, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_DATAMASK);
createNewRowFilterPolicyItemsForPolicy(policy, newUpdPolicy, rowFilterItems, xServiceDef, RangerPolicyItemEvaluator.POLICY_ITEM_TYPE_ROWFILTER);
createNewLabelsForPolicy(newUpdPolicy, policyLabels);
handlePolicyUpdate(service, isTagVersionUpdateNeeded);
RangerPolicy updPolicy = policyService.getPopulatedViewObject(newUpdPolicy);
dataHistService.createObjectDataHistory(updPolicy, RangerDataHistService.ACTION_UPDATE);
bizUtil.createTrxLog(trxLogList);
return updPolicy;
}
Aggregations