Search in sources :

Example 1 with VXAuditMapList

use of org.apache.ranger.view.VXAuditMapList 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 VXAuditMapList

use of org.apache.ranger.view.VXAuditMapList in project ranger by apache.

the class XAuditMapServiceBase method searchXAuditMaps.

/**
 * @param searchCriteria
 * @return
 */
public VXAuditMapList searchXAuditMaps(SearchCriteria searchCriteria) {
    VXAuditMapList returnList = new VXAuditMapList();
    List<VXAuditMap> xAuditMapList = new ArrayList<VXAuditMap>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXAuditMap : resultList) {
        VXAuditMap vXAuditMap = populateViewBean(gjXAuditMap);
        xAuditMapList.add(vXAuditMap);
    }
    returnList.setVXAuditMaps(xAuditMapList);
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXAuditMap(org.apache.ranger.view.VXAuditMap)

Example 3 with VXAuditMapList

use of org.apache.ranger.view.VXAuditMapList in project ranger by apache.

the class XPolicyService method mapPublicToXAObject.

public VXResource mapPublicToXAObject(VXPolicy vXPolicy, int operationContext) {
    VXResource vXResource = new VXResource();
    vXResource = super.mapBaseAttributesToXAObject(vXPolicy, vXResource);
    vXResource.setName(vXPolicy.getResourceName());
    vXResource.setPolicyName(StringUtils.trim(vXPolicy.getPolicyName()));
    vXResource.setDescription(vXPolicy.getDescription());
    vXResource.setResourceType(getResourceType(vXPolicy));
    XXAsset xAsset = xaDaoMgr.getXXAsset().findByAssetName(vXPolicy.getRepositoryName());
    if (xAsset == null) {
        throw restErrorUtil.createRESTException("The repository for which " + "you're updating policy, doesn't exist.", MessageEnums.INVALID_INPUT_DATA);
    }
    vXResource.setAssetId(xAsset.getId());
    if (operationContext == AbstractBaseResourceService.OPERATION_UPDATE_CONTEXT) {
        XXResource xxResource = xaDaoMgr.getXXResource().getById(vXPolicy.getId());
        if (xxResource == null) {
            logger.error("No policy found with given Id : " + vXPolicy.getId());
            throw restErrorUtil.createRESTException("No Policy found with given Id : " + vXResource.getId(), MessageEnums.DATA_NOT_FOUND);
        }
        /*
			 * While updating public object we wont have createDate/updateDate,
			 * so create time, addedById, updatedById, etc. we ll have to take
			 * from existing object
			 */
        xxResource.setUpdateTime(DateUtil.getUTCDate());
        xResourceService.mapBaseAttributesToViewBean(xxResource, vXResource);
        SearchCriteria scAuditMap = new SearchCriteria();
        scAuditMap.addParam("resourceId", xxResource.getId());
        VXAuditMapList vXAuditMapList = xAuditMapService.searchXAuditMaps(scAuditMap);
        List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
        if (vXAuditMapList.getListSize() > 0 && vXPolicy.getIsAuditEnabled()) {
            auditList.addAll(vXAuditMapList.getVXAuditMaps());
        } else if (vXAuditMapList.getListSize() == 0 && vXPolicy.getIsAuditEnabled()) {
            VXAuditMap vXAuditMap = new VXAuditMap();
            vXAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
            auditList.add(vXAuditMap);
        }
        List<VXPermMap> permMapList = mapPermObjToPermList(vXPolicy.getPermMapList(), vXPolicy);
        vXResource.setAuditList(auditList);
        vXResource.setPermMapList(permMapList);
    } else if (operationContext == AbstractBaseResourceService.OPERATION_CREATE_CONTEXT) {
        if (vXPolicy.getIsAuditEnabled()) {
            VXAuditMap vXAuditMap = new VXAuditMap();
            vXAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
            List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
            auditList.add(vXAuditMap);
            vXResource.setAuditList(auditList);
        }
        if (!stringUtil.isEmpty(vXPolicy.getPermMapList())) {
            List<VXPermMap> permMapList = mapPermObjToPermList(vXPolicy.getPermMapList());
            vXResource.setPermMapList(permMapList);
        }
    }
    vXResource.setDatabases(vXPolicy.getDatabases());
    vXResource.setTables(vXPolicy.getTables());
    vXResource.setColumnFamilies(vXPolicy.getColumnFamilies());
    vXResource.setColumns(vXPolicy.getColumns());
    vXResource.setUdfs(vXPolicy.getUdfs());
    vXResource.setAssetName(vXPolicy.getRepositoryName());
    int assetType = AppConstants.getEnumFor_AssetType(vXPolicy.getRepositoryType());
    if (assetType == AppConstants.ASSET_UNKNOWN) {
        assetType = xAsset.getAssetType();
        vXPolicy.setRepositoryType(AppConstants.getLabelFor_AssetType(assetType));
    }
    vXResource.setAssetType(assetType);
    int resourceStatus = AppConstants.STATUS_ENABLED;
    if (!vXPolicy.getIsEnabled()) {
        resourceStatus = AppConstants.STATUS_DISABLED;
    }
    vXResource.setResourceStatus(resourceStatus);
    // Allowing to create policy without checking parent permission
    vXResource.setCheckParentPermission(AppConstants.BOOL_FALSE);
    vXResource.setTopologies(vXPolicy.getTopologies());
    vXResource.setServices(vXPolicy.getServices());
    /*
		 * TODO : These parameters are specific for some components. Need to
		 * take care while adding new component
		 */
    if (vXPolicy.getRepositoryType().equalsIgnoreCase(AppConstants.getLabelFor_AssetType(AppConstants.ASSET_HIVE))) {
        vXResource.setTableType(AppConstants.getEnumFor_PolicyType(vXPolicy.getTableType()));
        vXResource.setColumnType(AppConstants.getEnumFor_PolicyType(vXPolicy.getColumnType()));
    }
    if (vXPolicy.getRepositoryType().equalsIgnoreCase(AppConstants.getLabelFor_AssetType(AppConstants.ASSET_HDFS))) {
        vXResource.setIsRecursive(AppConstants.getEnumFor_BooleanValue(vXPolicy.getIsRecursive()));
    }
    return vXResource;
}
Also used : VXPermMap(org.apache.ranger.view.VXPermMap) XXResource(org.apache.ranger.entity.XXResource) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) VXAuditMap(org.apache.ranger.view.VXAuditMap) 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)

Example 4 with VXAuditMapList

use of org.apache.ranger.view.VXAuditMapList in project ranger by apache.

the class TestXUserREST method test60searchXAuditMaps.

@SuppressWarnings("unchecked")
@Test
public void test60searchXAuditMaps() {
    VXAuditMap testvXAuditMap = createVXAuditMapObj();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    List<VXAuditMap> testvXAuditMaps = new ArrayList<VXAuditMap>();
    testvXAuditMaps.add(testvXAuditMap);
    VXAuditMapList testVXAuditMapList = new VXAuditMapList();
    testVXAuditMapList.setVXAuditMaps(testvXAuditMaps);
    Mockito.when(xUserMgr.searchXAuditMaps(testSearchCriteria)).thenReturn(testVXAuditMapList);
    VXAuditMapList outputVXAuditMapList = xUserRest.searchXAuditMaps(request);
    Mockito.verify(xUserMgr).searchXAuditMaps(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    assertNotNull(outputVXAuditMapList);
    assertEquals(outputVXAuditMapList.getClass(), testVXAuditMapList.getClass());
    assertEquals(outputVXAuditMapList.getResultSize(), testVXAuditMapList.getResultSize());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) VXAuditMap(org.apache.ranger.view.VXAuditMap) SortField(org.apache.ranger.common.SortField) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 5 with VXAuditMapList

use of org.apache.ranger.view.VXAuditMapList 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 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)5 VXAuditMap (org.apache.ranger.view.VXAuditMap)3 VXPermMapList (org.apache.ranger.view.VXPermMapList)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 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SortField (org.apache.ranger.common.SortField)1 XXAuthSessionDao (org.apache.ranger.db.XXAuthSessionDao)1 XXGroupDao (org.apache.ranger.db.XXGroupDao)1 XXGroupGroupDao (org.apache.ranger.db.XXGroupGroupDao)1 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)1