Search in sources :

Example 6 with XXPolicy

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

the class TestRangerPolicyServiceBase method policy.

private XXPolicy policy() {
    XXPolicy xxPolicy = new XXPolicy();
    xxPolicy.setId(Id);
    xxPolicy.setName("HDFS_1-1-20150316062453");
    xxPolicy.setAddedByUserId(Id);
    xxPolicy.setCreateTime(new Date());
    xxPolicy.setDescription("test");
    xxPolicy.setIsAuditEnabled(false);
    xxPolicy.setIsEnabled(false);
    xxPolicy.setService(1L);
    xxPolicy.setUpdatedByUserId(Id);
    xxPolicy.setUpdateTime(new Date());
    return xxPolicy;
}
Also used : XXPolicy(org.apache.ranger.entity.XXPolicy) Date(java.util.Date)

Example 7 with XXPolicy

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

the class TestRangerPolicyServiceBase method test3mapEntityToViewBean.

@Test
public void test3mapEntityToViewBean() {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXService xService = Mockito.mock(XXService.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    XXPolicy policy = policy();
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getById(policy.getService())).thenReturn(xService);
    RangerPolicy dbRangerPolicy = policyService.mapEntityToViewBean(rangerPolicy, policy);
    Assert.assertNotNull(dbRangerPolicy);
    Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
    Assert.assertEquals(dbRangerPolicy.getGuid(), rangerPolicy.getGuid());
    Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName());
    Assert.assertEquals(dbRangerPolicy.getIsEnabled(), rangerPolicy.getIsEnabled());
    Assert.assertEquals(dbRangerPolicy.getVersion(), rangerPolicy.getVersion());
    Assert.assertEquals(dbRangerPolicy.getDescription(), rangerPolicy.getDescription());
    Mockito.verify(daoManager).getXXService();
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Example 8 with XXPolicy

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());
}
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 9 with XXPolicy

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

the class TestPublicAPIs method policy.

private XXPolicy policy() {
    XXPolicy xxPolicy = new XXPolicy();
    xxPolicy.setId(Id);
    xxPolicy.setName("HDFS_1-1-20150316062453");
    xxPolicy.setAddedByUserId(Id);
    xxPolicy.setCreateTime(new Date());
    xxPolicy.setDescription("test");
    xxPolicy.setIsAuditEnabled(false);
    xxPolicy.setIsEnabled(false);
    xxPolicy.setService(1L);
    xxPolicy.setUpdatedByUserId(Id);
    xxPolicy.setUpdateTime(new Date());
    xxPolicy.setVersion(Id);
    return xxPolicy;
}
Also used : XXPolicy(org.apache.ranger.entity.XXPolicy) Date(java.util.Date)

Example 10 with XXPolicy

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

the class PatchMigration_J10002 method migratePoliciesToNewSchema.

public void migratePoliciesToNewSchema() throws Exception {
    logger.info("==> MigrationPatch.migratePoliciesToNewSchema()");
    try {
        List<XXResource> resList = daoMgr.getXXResource().getAll();
        if (resList.isEmpty()) {
            return;
        }
        svcDBStore.setPopulateExistingBaseFields(true);
        for (XXResource xRes : resList) {
            if (xRes.getResourceStatus() == AppConstants.STATUS_DELETED) {
                continue;
            }
            XXAsset xAsset = daoMgr.getXXAsset().getById(xRes.getAssetId());
            if (xAsset == null) {
                logger.error("No Repository found for policyName: " + xRes.getPolicyName());
                continue;
            }
            RangerService service = svcDBStore.getServiceByName(xAsset.getName());
            if (service == null) {
                logger.error("No Service found for policy. Ignoring migration of such policy, policyName: " + xRes.getPolicyName());
                continue;
            }
            XXPolicy existing = daoMgr.getXXPolicy().findByNameAndServiceId(xRes.getPolicyName(), service.getId());
            if (existing != null) {
                logger.info("Policy already exists. Ignoring migration of policy: " + existing.getName());
                continue;
            }
            RangerPolicy policy = new RangerPolicy();
            policy = mapXResourceToPolicy(policy, xRes, service);
            if (policy != null) {
                policy = svcDBStore.createPolicy(policy);
                policyCounter++;
                logger.info("New policy created. policyName: " + policy.getName());
            }
        }
        svcDBStore.setPopulateExistingBaseFields(false);
    } catch (Exception e) {
        throw new Exception("Error while migrating data to new Plugin Schema.", e);
    }
    logger.info("<== MigrationPatch.migratePoliciesToNewSchema()");
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXResource(org.apache.ranger.entity.XXResource) XXAsset(org.apache.ranger.entity.XXAsset) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy)

Aggregations

XXPolicy (org.apache.ranger.entity.XXPolicy)20 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)14 Test (org.junit.Test)7 RangerService (org.apache.ranger.plugin.model.RangerService)6 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)5 XXTrxLog (org.apache.ranger.entity.XXTrxLog)5 ArrayList (java.util.ArrayList)4 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)4 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)4 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)4 RangerDataMaskPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerDataMaskPolicyItem)4 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)4 RangerRowFilterPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerRowFilterPolicyItem)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Date (java.util.Date)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXUserDao (org.apache.ranger.db.XXUserDao)3 XXUser (org.apache.ranger.entity.XXUser)3 SearchCriteria (org.apache.ranger.common.SearchCriteria)2