use of org.apache.ranger.view.VXPermMapList 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.view.VXPermMapList in project ranger by apache.
the class XPermMapServiceBase method searchXPermMaps.
/**
* @param searchCriteria
* @return
*/
public VXPermMapList searchXPermMaps(SearchCriteria searchCriteria) {
VXPermMapList returnList = new VXPermMapList();
List<VXPermMap> xPermMapList = new ArrayList<VXPermMap>();
List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
// Iterate over the result list and create the return list
for (T gjXPermMap : resultList) {
VXPermMap vXPermMap = populateViewBean(gjXPermMap);
xPermMapList.add(vXPermMap);
}
returnList.setVXPermMaps(xPermMapList);
return returnList;
}
use of org.apache.ranger.view.VXPermMapList in project ranger by apache.
the class XPolicyService method updatePermGroup.
public List<VXPermMap> updatePermGroup(VXResource vXResource) {
XXResource xxResource = xaDaoMgr.getXXResource().getById(vXResource.getId());
if (xxResource == null) {
logger.info("Resource : " + vXResource.getPolicyName() + " Not Found, while updating PermGroup");
throw restErrorUtil.createRESTException("Resource Not found to update PermGroup", MessageEnums.DATA_NOT_FOUND);
}
Long resId = vXResource.getId();
List<VXPermMap> updatedPermMapList = new ArrayList<VXPermMap>();
SearchCriteria searchCriteria = new SearchCriteria();
searchCriteria.addParam("resourceId", resId);
VXPermMapList currentPermMaps = xPermMapService.searchXPermMaps(searchCriteria);
List<VXPermMap> currentPermMapList = currentPermMaps.getVXPermMaps();
HashMap<String, List<String>> userPermMap = new HashMap<String, List<String>>();
for (VXPermMap currentPermMap : currentPermMapList) {
Long userId = currentPermMap.getUserId();
Long groupId = currentPermMap.getGroupId();
int permFor = currentPermMap.getPermFor();
int permType = currentPermMap.getPermType();
String ipAddress = currentPermMap.getIpAddress();
String uniKey = resId + uniqueKeySeparator + permFor;
if (permFor == AppConstants.XA_PERM_FOR_GROUP) {
uniKey = uniKey + uniqueKeySeparator + groupId;
} else if (permFor == AppConstants.XA_PERM_FOR_USER) {
uniKey = uniKey + uniqueKeySeparator + userId;
}
List<String> permList = userPermMap.get(uniKey);
if (permList == null) {
permList = new ArrayList<String>();
userPermMap.put(uniKey, permList);
}
permList.add("" + permType);
if (stringUtil.isEmpty(ipAddress)) {
permList.add(ipAddress);
}
}
List<List<String>> masterKeyList = new ArrayList<List<String>>();
List<String> proceedKeyList = new ArrayList<String>();
for (Entry<String, List<String>> upMap : userPermMap.entrySet()) {
if (proceedKeyList.contains(upMap.getKey())) {
continue;
}
List<String> keyList = new ArrayList<String>();
keyList.add(upMap.getKey());
proceedKeyList.add(upMap.getKey());
for (Entry<String, List<String>> entry : userPermMap.entrySet()) {
if (proceedKeyList.contains(entry.getKey())) {
continue;
}
boolean result = compareTwoListElements(upMap.getValue(), entry.getValue());
if (result) {
keyList.add(entry.getKey());
proceedKeyList.add(entry.getKey());
}
}
masterKeyList.add(keyList);
}
for (List<String> keyList : masterKeyList) {
Random rand = new Random();
String permGrp = new Date() + " : " + rand.nextInt(9999);
for (String key : keyList) {
SearchCriteria scPermMap = new SearchCriteria();
String[] keyEle = StringUtils.split(key, uniqueKeySeparator);
if (keyEle != null && keyEle.length == 3) {
int permFor = Integer.parseInt(keyEle[1]);
int ugId = Integer.parseInt(keyEle[2]);
scPermMap.addParam("resourceId", resId);
scPermMap.addParam("permFor", permFor);
if (permFor == AppConstants.XA_PERM_FOR_GROUP) {
scPermMap.addParam("groupId", ugId);
} else if (permFor == AppConstants.XA_PERM_FOR_USER) {
scPermMap.addParam("userId", ugId);
}
VXPermMapList permList = xPermMapService.searchXPermMaps(scPermMap);
for (VXPermMap vXPerm : permList.getVXPermMaps()) {
vXPerm.setPermGroup(permGrp);
xPermMapService.updateResource(vXPerm);
updatedPermMapList.add(vXPerm);
}
} else {
logger.info("variable : keyEle, should fulfill the checked" + " condition, but its not fulfilling required " + "condition. Ignoring appropriate permMap from" + " updating permGroup. Key : " + key + "Resource Id : " + resId);
}
}
}
return updatedPermMapList;
}
use of org.apache.ranger.view.VXPermMapList in project ranger by apache.
the class TestXUserREST method test48searchXPermMaps.
@SuppressWarnings("unchecked")
@Test
public void test48searchXPermMaps() {
VXPermMap permMap = testcreateXPermMap();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchCriteria testSearchCriteria = createsearchCriteria();
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(permMap);
VXPermMapList testvXGroupList = new VXPermMapList();
testvXGroupList.setTotalCount(1);
testvXGroupList.setVXPermMaps(vXPermMaps);
Mockito.when(xUserMgr.searchXPermMaps(testSearchCriteria)).thenReturn(testvXGroupList);
VXPermMapList outputvXGroupList = xUserRest.searchXPermMaps(request);
Mockito.verify(xUserMgr).searchXPermMaps(testSearchCriteria);
Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
assertNotNull(outputvXGroupList);
assertEquals(outputvXGroupList.getClass(), testvXGroupList.getClass());
assertEquals(outputvXGroupList.getTotalCount(), testvXGroupList.getTotalCount());
}
use of org.apache.ranger.view.VXPermMapList in project ranger by apache.
the class TestXUserMgr method test28DeleteXUser.
@Test
public void test28DeleteXUser() {
setup();
boolean force = true;
VXUser vXUser = vxUser();
// XXUser
XXUser xXUser = new XXUser();
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
// 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(vXUser.getId());
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);
// XXPortalUser
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = new XXPortalUser();
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
// update XXPolicyItemUserPerm
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
Aggregations