Search in sources :

Example 1 with VXPermMapList

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());
}
Also used : VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) XXPolicy(org.apache.ranger.entity.XXPolicy) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) VXPermMapList(org.apache.ranger.view.VXPermMapList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupGroupDao(org.apache.ranger.db.XXGroupGroupDao) XXGroupDao(org.apache.ranger.db.XXGroupDao) XXGroupGroup(org.apache.ranger.entity.XXGroupGroup) Test(org.junit.Test)

Example 2 with VXPermMapList

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;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) ArrayList(java.util.ArrayList) VXPermMapList(org.apache.ranger.view.VXPermMapList)

Example 3 with VXPermMapList

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;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) XXResource(org.apache.ranger.entity.XXResource) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date) Random(java.util.Random) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPermMapList(org.apache.ranger.view.VXPermMapList) List(java.util.List) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXPermMapList(org.apache.ranger.view.VXPermMapList)

Example 4 with VXPermMapList

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXPermMap(org.apache.ranger.view.VXPermMap) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXPermMapList(org.apache.ranger.view.VXPermMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 5 with VXPermMapList

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());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)5 VXPermMapList (org.apache.ranger.view.VXPermMapList)5 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)3 VXPermMap (org.apache.ranger.view.VXPermMap)3 Test (org.junit.Test)3 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)2 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)2 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)2 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)2 XXPolicy (org.apache.ranger.entity.XXPolicy)2 VXGroupUser (org.apache.ranger.view.VXGroupUser)2 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SortField (org.apache.ranger.common.SortField)1