Search in sources :

Example 6 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class TestRangerBizUtil method testHasPermission_emptyResourceName.

@Test
public void testHasPermission_emptyResourceName() {
    VXResource vXResource = new VXResource();
    vXResource.setAssetId(12345L);
    XXPortalUser portalUser = new XXPortalUser();
    portalUser.setId(id);
    portalUser.setLoginId("12121");
    RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUser xxUser = new XXUser();
    XXAsset xxAsset = new XXAsset();
    List<XXResource> lst = new ArrayList<XXResource>();
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
    Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
    Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(userDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
    Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) XXAssetDao(org.apache.ranger.db.XXAssetDao) XXResource(org.apache.ranger.entity.XXResource) XXUserDao(org.apache.ranger.db.XXUserDao) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) Test(org.junit.Test)

Example 7 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class TestRangerBizUtil method testGetDisplayName_MoreThanMaxLen.

@Test
public void testGetDisplayName_MoreThanMaxLen() {
    XXAsset obj = new XXAsset();
    String name = resourceName;
    for (int i = 0; i < 16; i++) {
        name = name + "_" + name + "1";
    }
    obj.setDescription(name);
    String displayNameChk = rangerBizUtil.getDisplayName(obj);
    Assert.assertEquals(displayNameChk.length(), 150);
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset) Test(org.junit.Test)

Example 8 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class XAssetService method validateForCreate.

@Override
protected void validateForCreate(VXAsset vObj) {
    XXAsset xxAsset = daoManager.getXXAsset().findByAssetName(vObj.getName());
    if (xxAsset != null) {
        String errorMessage = "Repository Name already exists";
        throw restErrorUtil.createRESTException(errorMessage, MessageEnums.INVALID_INPUT_DATA, null, null, vObj.toString());
    }
    if (vObj.getName() == null || vObj.getName().trim().length() == 0) {
        String errorMessage = "Repository Name can't be empty";
        throw restErrorUtil.createRESTException(errorMessage, MessageEnums.INVALID_INPUT_DATA, null, null, vObj.toString());
    }
    validateConfig(vObj);
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset)

Example 9 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class XResourceService method populateAssetProperties.

private void populateAssetProperties(VXResource vXResource) {
    XXAsset xxAsset = daoManager.getXXAsset().getById(vXResource.getAssetId());
    if (xxAsset != null) {
        vXResource.setAssetName(xxAsset.getName());
        vXResource.setAssetType(xxAsset.getAssetType());
    }
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset)

Example 10 with XXAsset

use of org.apache.ranger.entity.XXAsset 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)

Aggregations

XXAsset (org.apache.ranger.entity.XXAsset)15 Test (org.junit.Test)6 XXResource (org.apache.ranger.entity.XXResource)4 ArrayList (java.util.ArrayList)3 BaseDao (org.apache.ranger.common.db.BaseDao)2 XXDBBase (org.apache.ranger.entity.XXDBBase)2 RangerService (org.apache.ranger.plugin.model.RangerService)2 VXResource (org.apache.ranger.view.VXResource)2 VXResponse (org.apache.ranger.view.VXResponse)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 SearchField (org.apache.ranger.common.SearchField)1 SortField (org.apache.ranger.common.SortField)1 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)1 XXAssetDao (org.apache.ranger.db.XXAssetDao)1 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)1 XXResourceDao (org.apache.ranger.db.XXResourceDao)1 XXUserDao (org.apache.ranger.db.XXUserDao)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1