use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class TestXUserMgr method test27DeleteXGroup.
@Test
public void test27DeleteXGroup() {
setup();
boolean force = true;
VXGroup vXGroup = new VXGroup();
vXGroup.setId(userId);
vXGroup.setDescription("group test");
vXGroup.setName("grouptest");
// XXGroup
XXGroupDao xXGroupDao = Mockito.mock(XXGroupDao.class);
XXGroup xXGroup = new XXGroup();
Mockito.when(daoManager.getXXGroup()).thenReturn(xXGroupDao);
Mockito.when(xXGroupDao.getById(vXGroup.getId())).thenReturn(xXGroup);
Mockito.when(xGroupService.populateViewBean(xXGroup)).thenReturn(vXGroup);
// VXGroupUser
VXGroupUserList vxGroupUserList = new VXGroupUserList();
XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
VXGroupUser vxGroupUser = new VXGroupUser();
vxGroupUser.setId(userId);
vxGroupUser.setName("group user test");
vxGroupUser.setOwner("Admin");
vxGroupUser.setUserId(userId);
vxGroupUser.setUpdatedBy("User");
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
// VXPermMap
VXPermMapList vXPermMapList = new VXPermMapList();
XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
// VXAuditMap
VXAuditMapList vXAuditMapList = new VXAuditMapList();
XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
// XXGroupGroup
XXGroupGroupDao xXGroupGroupDao = Mockito.mock(XXGroupGroupDao.class);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
Mockito.when(daoManager.getXXGroupGroup()).thenReturn(xXGroupGroupDao);
Mockito.when(xXGroupGroupDao.findByGroupId(userId)).thenReturn(xXGroupGroups);
// update XXGroupPermission
XXGroupPermissionDao xXGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xXGroupPermissionDao);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
Mockito.when(xXGroupPermissionDao.findByGroupId(vXGroup.getId())).thenReturn(xXGroupPermissions);
// update XXPolicyItemUserPerm
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByGroupId(userId)).thenReturn(xXPolicyList);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchForMigratingOldRegimePolicyJson_J10046 method portPolicy.
private void portPolicy(String serviceType, RangerPolicy policy) throws Exception {
logger.info("==> portPolicy(id=" + policy.getId() + ")");
String policyText = JsonUtils.objectToJson(policy);
if (StringUtils.isEmpty(policyText)) {
throw new Exception("Failed to convert policy to json string. Policy: [id=" + policy.getId() + "; name=" + policy.getName() + "; serviceType=" + serviceType + "]");
}
XXPolicyDao policyDao = daoMgr.getXXPolicy();
XXPolicy dbBean = policyDao.getById(policy.getId());
dbBean.setPolicyText(policyText);
policyDao.update(dbBean);
try {
Set<String> accesses = new HashSet<>();
Set<String> users = new HashSet<>();
Set<String> groups = new HashSet<>();
Set<String> conditions = new HashSet<>();
Set<String> dataMasks = new HashSet<>();
buildLists(policy.getPolicyItems(), accesses, conditions, users, groups);
buildLists(policy.getDenyPolicyItems(), accesses, conditions, users, groups);
buildLists(policy.getAllowExceptions(), accesses, conditions, users, groups);
buildLists(policy.getDenyExceptions(), accesses, conditions, users, groups);
buildLists(policy.getDataMaskPolicyItems(), accesses, conditions, users, groups);
buildLists(policy.getRowFilterPolicyItems(), accesses, conditions, users, groups);
buildList(policy.getDataMaskPolicyItems(), dataMasks);
addResourceDefRef(serviceType, policy);
addUserNameRef(policy.getId(), users);
addGroupNameRef(policy.getId(), groups);
addAccessDefRef(serviceType, policy.getId(), accesses);
addPolicyConditionDefRef(serviceType, policy.getId(), conditions);
addDataMaskDefRef(serviceType, policy.getId(), dataMasks);
} catch (Exception e) {
logger.error("portPoliry(id=" + policy.getId() + ") failed!!");
logger.error("Offending policy:" + policyText);
throw e;
}
logger.info("<== portPolicy(id=" + policy.getId() + ")");
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchForMigratingOldRegimePolicyJson_J10046 method migrateRangerPolicyTableWithPolicyJson.
private void migrateRangerPolicyTableWithPolicyJson() throws Exception {
logger.info("==> updateRangerPolicyTableWithPolicyJson() ");
List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().getAllByPolicyItem();
if (CollectionUtils.isNotEmpty(xxPolicyList)) {
for (XXPolicy xxPolicy : xxPolicyList) {
logger.info("XXPolicy : " + xxPolicy);
RangerPolicy policy = svcStore.getPolicy(xxPolicy.getId());
if (policy != null) {
TransactionTemplate txTemplate = new TransactionTemplate(txManager);
RangerService service = svcStore.getServiceByName(policy.getService());
PolicyUpdaterThread updaterThread = new PolicyUpdaterThread(txTemplate, service, policy);
updaterThread.setDaemon(true);
updaterThread.start();
updaterThread.join();
String errorMsg = updaterThread.getErrorMsg();
if (StringUtils.isNotEmpty(errorMsg)) {
throw new Exception(errorMsg);
}
}
}
} else {
logger.info("no old XXPolicyItems found ");
}
logger.info("<== updateRangerPolicyTableWithPolicyJson() ");
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchForAtlasResourceAndAccessTypeUpdate_J10016 method updatePolicyForRelationshipType.
private void updatePolicyForRelationshipType() {
logger.info("===> updatePolicyForRelationshipType ");
XXPortalUser xxPortalUser = daoMgr.getXXPortalUser().findByLoginId(LOGIN_ID_ADMIN);
Long currentUserId = xxPortalUser.getId();
XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (xXServiceDefObj == null) {
logger.debug("xXServiceDefObj not found with name : " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
return;
}
Long xServiceDefId = xXServiceDefObj.getId();
XXResourceDef xxResourceDef = daoMgr.getXXResourceDef().findByNameAndServiceDefId(RESOURCE_DEF_NAME, xServiceDefId);
List<XXPolicyResource> policyResources = daoMgr.getXXPolicyResource().findByResDefId(xxResourceDef.getId());
for (XXPolicyResource xxPolicyResource : policyResources) {
XXPolicy xxPolicy = daoMgr.getXXPolicy().getById(xxPolicyResource.getPolicyid());
List<XXPolicyItem> xxPolicyItems = daoMgr.getXXPolicyItem().findByPolicyId(xxPolicy.getId());
for (XXPolicyItem xxPolicyItem : xxPolicyItems) {
XXGroup xxGroup = daoMgr.getXXGroup().findByGroupName(GROUP_PUBLIC);
if (xxGroup == null) {
logger.error("Group name 'public' not found in database");
return;
}
Long publicGroupId = xxGroup.getId();
XXPolicyItemGroupPerm xxPolicyItemGroupPerm = new XXPolicyItemGroupPerm();
xxPolicyItemGroupPerm.setPolicyItemId(xxPolicyItem.getId());
xxPolicyItemGroupPerm.setGroupId(publicGroupId);
xxPolicyItemGroupPerm.setOrder(0);
xxPolicyItemGroupPerm.setAddedByUserId(currentUserId);
xxPolicyItemGroupPerm.setUpdatedByUserId(currentUserId);
daoMgr.getXXPolicyItemGroupPerm().create(xxPolicyItemGroupPerm);
}
}
logger.info("<=== updatePolicyForRelationshipType ");
}
use of org.apache.ranger.entity.XXPolicy in project ranger by apache.
the class PatchForAtlasToAddTypeRead_J10040 method updateDefaultPolicyForType.
private void updateDefaultPolicyForType() throws Exception {
logger.info("==> updateDefaultPolicyForType() ");
XXServiceDef xXServiceDefObj = daoMgr.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (xXServiceDefObj == null) {
logger.debug("ServiceDef not found with name :" + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
return;
}
Long xServiceDefId = xXServiceDefObj.getId();
List<XXService> xxServices = daoMgr.getXXService().findByServiceDefId(xServiceDefId);
for (XXService xxService : xxServices) {
List<XXPolicy> xxPolicies = daoMgr.getXXPolicy().findByServiceId(xxService.getId());
for (XXPolicy xxPolicy : xxPolicies) {
if (xxPolicy.getName().equalsIgnoreCase(ALL_TYPE_RESOURCE_DEF_NAME)) {
RangerPolicy rPolicy = svcDBStore.getPolicy(xxPolicy.getId());
List<RangerPolicyItem> policyItems = rPolicy.getPolicyItems();
for (RangerPolicyItem item : policyItems) {
if (!checkIfTypeReadPermissionSet(item)) {
List<RangerPolicyItemAccess> itemAccesses = item.getAccesses();
itemAccesses.add(getTypeReadPolicyItemAccesses());
item.setAccesses(itemAccesses);
}
}
RangerPolicyItem rangerPolicyItemReadType = new RangerPolicyItem();
rangerPolicyItemReadType.setDelegateAdmin(Boolean.FALSE);
rangerPolicyItemReadType.setAccesses(Arrays.asList(getTypeReadPolicyItemAccesses()));
rangerPolicyItemReadType.setGroups(Arrays.asList(GROUP_PUBLIC));
policyItems.add(rangerPolicyItemReadType);
svcDBStore.updatePolicy(rPolicy);
}
}
}
logger.info("<== updateDefaultPolicyForType() ");
}
Aggregations