use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class TestPublicAPIs method test9updatePolicy.
@Test
public void test9updatePolicy() throws Exception {
RangerPolicy policy = rangerPolicy();
RangerService service = rangerService();
VXPolicy vXPolicy = vXPolicy(policy, service);
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
XXPolicy xXPolicy = policy();
Mockito.when(daoMgr.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.getById(Id)).thenReturn(xXPolicy);
Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service);
Mockito.when(serviceUtil.toRangerPolicy(vXPolicy, service)).thenReturn(policy);
Mockito.when(serviceREST.updatePolicy(policy)).thenReturn(policy);
Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
VXPolicy dbVXPolicy = publicAPIs.updatePolicy(vXPolicy, Id);
Assert.assertNotNull(dbVXPolicy);
Assert.assertEquals(dbVXPolicy, vXPolicy);
Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId());
Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName());
Mockito.verify(serviceREST).updatePolicy(policy);
Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName());
Mockito.verify(serviceUtil).toVXPolicy(policy, service);
Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy, service);
Mockito.verify(daoMgr).getXXPolicy();
Mockito.verify(xXPolicyDao).getById(Id);
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class TestXUserMgr method getXXPolicy.
private XXPolicy getXXPolicy() {
XXPolicy xxPolicy = new XXPolicy();
xxPolicy.setId(userId);
xxPolicy.setName("HDFS_1-1-20150316062453");
xxPolicy.setAddedByUserId(userId);
xxPolicy.setCreateTime(new Date());
xxPolicy.setDescription("test");
xxPolicy.setIsAuditEnabled(false);
xxPolicy.setIsEnabled(false);
xxPolicy.setService(1L);
xxPolicy.setUpdatedByUserId(userId);
xxPolicy.setUpdateTime(new Date());
return xxPolicy;
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class UpdateUserAndGroupNamesInJson method updateUserAndGroupNamesInPolicyJson.
// Update user and group name in policy json
private void updateUserAndGroupNamesInPolicyJson(RangerPolicyRetriever policyRetriever, Map<String, String> usersInDB, Map<String, String> groupsInDB) throws Exception {
logger.info("==> updateUserAndGroupNamesInPolicyJson() ");
List<RangerService> allServices = svcStore.getServices(new SearchFilter());
if (CollectionUtils.isNotEmpty(allServices)) {
for (RangerService service : allServices) {
XXService dbService = daoMgr.getXXService().getById(service.getId());
TransactionTemplate txTemplate = new TransactionTemplate(txManager);
logger.info("==> Update Policies of service(name=" + dbService.getName() + ")");
List<XXPolicy> policies = policyRetriever.getServicePolicies(dbService);
if (CollectionUtils.isNotEmpty(policies)) {
for (XXPolicy xPolicy : policies) {
if (xPolicy != null && !StringUtil.isEmpty(xPolicy.getPolicyText())) {
// logger.info("existingPolicyText:" + xPolicy.getPolicyText());
RangerPolicy rangerPolicy = JsonUtils.jsonToObject(xPolicy.getPolicyText(), RangerPolicy.class);
updatePolicyItemUsersAndGroups(rangerPolicy.getPolicyItems(), usersInDB, groupsInDB);
updatePolicyItemUsersAndGroups(rangerPolicy.getDenyPolicyItems(), usersInDB, groupsInDB);
updatePolicyItemUsersAndGroups(rangerPolicy.getAllowExceptions(), usersInDB, groupsInDB);
updatePolicyItemUsersAndGroups(rangerPolicy.getDenyExceptions(), usersInDB, groupsInDB);
updatePolicyItemUsersAndGroups(rangerPolicy.getDataMaskPolicyItems(), usersInDB, groupsInDB);
updatePolicyItemUsersAndGroups(rangerPolicy.getRowFilterPolicyItems(), usersInDB, groupsInDB);
String updatedPolicyText = JsonUtils.objectToJson(rangerPolicy);
xPolicy.setPolicyText(updatedPolicyText);
// logger.info("updatedPolicyText:" + updatedPolicyText);
PolicyUpdaterThread updaterThread = new PolicyUpdaterThread(txTemplate, xPolicy);
updaterThread.setDaemon(true);
updaterThread.start();
updaterThread.join();
String errorMsg = updaterThread.getErrorMsg();
if (StringUtils.isNotEmpty(errorMsg)) {
throw new Exception(errorMsg);
}
}
}
}
}
}
logger.info("<== updateUserAndGroupNamesInPolicyJson() ");
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchPreSql_058_ForUpdateToUniqueResoureceSignature_J10053 method updateDisabledPolicyResourceSignature.
private void updateDisabledPolicyResourceSignature() throws Exception {
logger.info("==> updateDisabledPolicyResourceSignature() ");
List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findByPolicyStatus(isPolicyEnabled);
if (CollectionUtils.isNotEmpty(xxPolicyList)) {
logger.info("==> Total number of disabled policies :" + xxPolicyList.size());
for (XXPolicy xxPolicy : xxPolicyList) {
RangerPolicy policy = svcStore.getPolicy(xxPolicy.getId());
if (policy != null) {
policy.setResourceSignature(null);
xxPolicy.setResourceSignature(null);
RangerPolicyResourceSignature policySignature = factory.createPolicyResourceSignature(policy);
String signature = policySignature.getSignature();
policy.setResourceSignature(signature);
xxPolicy.setPolicyText(JsonUtils.objectToJson(policy));
xxPolicy.setResourceSignature(signature);
daoMgr.getXXPolicy().update(xxPolicy);
}
}
} else {
logger.info("no disabled Policy found");
}
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchPreSql_057_ForUpdateToUniqueGUID_J10052 method updatePolicyGUIDToUniqueValue.
private void updatePolicyGUIDToUniqueValue() throws Exception {
logger.info("==> updatePolicyGUIDToUniqueValue() ");
List<XXSecurityZone> allXXZones = null;
List<XXService> allXXService = null;
allXXZones = daoMgr.getXXSecurityZoneDao().getAll();
allXXService = daoMgr.getXXService().getAll();
if (CollectionUtils.isNotEmpty(allXXZones) && CollectionUtils.isNotEmpty(allXXService)) {
logger.info("Total number of zones " + allXXZones.size() + ", service :" + allXXService.size());
for (XXSecurityZone xSecurityZone : allXXZones) {
for (XXService xService : allXXService) {
logger.info("serching duplicate guid policies for service :" + xService.getName() + " zone : " + xSecurityZone.getName());
List<String> duplicateGuidList = daoMgr.getXXPolicy().findDuplicateGUIDByServiceIdAndZoneId(xService.getId(), xSecurityZone.getId());
if (CollectionUtils.isNotEmpty(duplicateGuidList)) {
logger.info("Total number of duplicate GUIDs :" + duplicateGuidList.size() + " for service :" + xService.getName() + " and zone :" + xSecurityZone.getName());
for (String guid : duplicateGuidList) {
List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findPolicyByGUIDAndServiceIdAndZoneId(guid, xService.getId(), xSecurityZone.getId());
boolean isFirstElement = false;
if (CollectionUtils.isNotEmpty(xxPolicyList)) {
isFirstElement = true;
for (XXPolicy xxPolicy : xxPolicyList) {
if (isFirstElement) {
isFirstElement = false;
continue;
}
RangerPolicy policy = svcStore.getPolicy(xxPolicy.getId());
if (policy != null) {
guid = guidUtil.genGUID();
xxPolicy.setGuid(guid);
policy.setGuid(guid);
xxPolicy.setPolicyText(JsonUtils.objectToJson(policy));
daoMgr.getXXPolicy().update(xxPolicy);
}
}
} else {
logger.info("No policy found with guid:" + guid);
}
}
} else {
logger.info("No duplicate GUID found in policy for Service :" + xService.getName() + ", Zone : " + xSecurityZone.getName());
}
}
}
} else {
logger.info("No zone or service found");
}
}
Aggregations