Search in sources :

Example 31 with XXPolicy

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

the class TestPublicAPIs method test9updatePolicy.

@Test
public void test9updatePolicy() throws Exception {
    RangerPolicy policy = rangerPolicy();
    RangerService service = rangerService();
    VXPolicy vXPolicy = vXPolicy(policy, service);
    XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
    XXPolicy xXPolicy = policy();
    Mockito.when(daoMgr.getXXPolicy()).thenReturn(xXPolicyDao);
    Mockito.when(xXPolicyDao.getById(Id)).thenReturn(xXPolicy);
    Mockito.when(serviceREST.getServiceByName(vXPolicy.getRepositoryName())).thenReturn(service);
    Mockito.when(serviceUtil.toRangerPolicy(vXPolicy, service)).thenReturn(policy);
    Mockito.when(serviceREST.updatePolicy(policy)).thenReturn(policy);
    Mockito.when(serviceUtil.toVXPolicy(policy, service)).thenReturn(vXPolicy);
    VXPolicy dbVXPolicy = publicAPIs.updatePolicy(vXPolicy, Id);
    Assert.assertNotNull(dbVXPolicy);
    Assert.assertEquals(dbVXPolicy, vXPolicy);
    Assert.assertEquals(dbVXPolicy.getId(), vXPolicy.getId());
    Assert.assertEquals(dbVXPolicy.getRepositoryName(), vXPolicy.getRepositoryName());
    Mockito.verify(serviceREST).updatePolicy(policy);
    Mockito.verify(serviceREST).getServiceByName(vXPolicy.getRepositoryName());
    Mockito.verify(serviceUtil).toVXPolicy(policy, service);
    Mockito.verify(serviceUtil).toRangerPolicy(vXPolicy, service);
    Mockito.verify(daoMgr).getXXPolicy();
    Mockito.verify(xXPolicyDao).getById(Id);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicy(org.apache.ranger.view.VXPolicy) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Example 32 with XXPolicy

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

the class TestXUserMgr method getXXPolicy.

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

Example 33 with XXPolicy

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

the class UpdateUserAndGroupNamesInJson method updateUserAndGroupNamesInPolicyJson.

// Update user and group name in policy json
private void updateUserAndGroupNamesInPolicyJson(RangerPolicyRetriever policyRetriever, Map<String, String> usersInDB, Map<String, String> groupsInDB) throws Exception {
    logger.info("==> updateUserAndGroupNamesInPolicyJson() ");
    List<RangerService> allServices = svcStore.getServices(new SearchFilter());
    if (CollectionUtils.isNotEmpty(allServices)) {
        for (RangerService service : allServices) {
            XXService dbService = daoMgr.getXXService().getById(service.getId());
            TransactionTemplate txTemplate = new TransactionTemplate(txManager);
            logger.info("==> Update Policies of service(name=" + dbService.getName() + ")");
            List<XXPolicy> policies = policyRetriever.getServicePolicies(dbService);
            if (CollectionUtils.isNotEmpty(policies)) {
                for (XXPolicy xPolicy : policies) {
                    if (xPolicy != null && !StringUtil.isEmpty(xPolicy.getPolicyText())) {
                        // logger.info("existingPolicyText:" + xPolicy.getPolicyText());
                        RangerPolicy rangerPolicy = JsonUtils.jsonToObject(xPolicy.getPolicyText(), RangerPolicy.class);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getPolicyItems(), usersInDB, groupsInDB);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getDenyPolicyItems(), usersInDB, groupsInDB);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getAllowExceptions(), usersInDB, groupsInDB);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getDenyExceptions(), usersInDB, groupsInDB);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getDataMaskPolicyItems(), usersInDB, groupsInDB);
                        updatePolicyItemUsersAndGroups(rangerPolicy.getRowFilterPolicyItems(), usersInDB, groupsInDB);
                        String updatedPolicyText = JsonUtils.objectToJson(rangerPolicy);
                        xPolicy.setPolicyText(updatedPolicyText);
                        // logger.info("updatedPolicyText:" + updatedPolicyText);
                        PolicyUpdaterThread updaterThread = new PolicyUpdaterThread(txTemplate, xPolicy);
                        updaterThread.setDaemon(true);
                        updaterThread.start();
                        updaterThread.join();
                        String errorMsg = updaterThread.getErrorMsg();
                        if (StringUtils.isNotEmpty(errorMsg)) {
                            throw new Exception(errorMsg);
                        }
                    }
                }
            }
        }
    }
    logger.info("<== updateUserAndGroupNamesInPolicyJson() ");
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy)

Example 34 with XXPolicy

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

the class PatchPreSql_058_ForUpdateToUniqueResoureceSignature_J10053 method updateDisabledPolicyResourceSignature.

private void updateDisabledPolicyResourceSignature() throws Exception {
    logger.info("==> updateDisabledPolicyResourceSignature() ");
    List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findByPolicyStatus(isPolicyEnabled);
    if (CollectionUtils.isNotEmpty(xxPolicyList)) {
        logger.info("==> Total number of disabled policies :" + xxPolicyList.size());
        for (XXPolicy xxPolicy : xxPolicyList) {
            RangerPolicy policy = svcStore.getPolicy(xxPolicy.getId());
            if (policy != null) {
                policy.setResourceSignature(null);
                xxPolicy.setResourceSignature(null);
                RangerPolicyResourceSignature policySignature = factory.createPolicyResourceSignature(policy);
                String signature = policySignature.getSignature();
                policy.setResourceSignature(signature);
                xxPolicy.setPolicyText(JsonUtils.objectToJson(policy));
                xxPolicy.setResourceSignature(signature);
                daoMgr.getXXPolicy().update(xxPolicy);
            }
        }
    } else {
        logger.info("no disabled Policy found");
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyResourceSignature(org.apache.ranger.plugin.model.RangerPolicyResourceSignature) XXPolicy(org.apache.ranger.entity.XXPolicy)

Example 35 with XXPolicy

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

the class PatchPreSql_057_ForUpdateToUniqueGUID_J10052 method updatePolicyGUIDToUniqueValue.

private void updatePolicyGUIDToUniqueValue() throws Exception {
    logger.info("==> updatePolicyGUIDToUniqueValue() ");
    List<XXSecurityZone> allXXZones = null;
    List<XXService> allXXService = null;
    allXXZones = daoMgr.getXXSecurityZoneDao().getAll();
    allXXService = daoMgr.getXXService().getAll();
    if (CollectionUtils.isNotEmpty(allXXZones) && CollectionUtils.isNotEmpty(allXXService)) {
        logger.info("Total number of zones " + allXXZones.size() + ", service :" + allXXService.size());
        for (XXSecurityZone xSecurityZone : allXXZones) {
            for (XXService xService : allXXService) {
                logger.info("serching duplicate guid policies for service :" + xService.getName() + " zone : " + xSecurityZone.getName());
                List<String> duplicateGuidList = daoMgr.getXXPolicy().findDuplicateGUIDByServiceIdAndZoneId(xService.getId(), xSecurityZone.getId());
                if (CollectionUtils.isNotEmpty(duplicateGuidList)) {
                    logger.info("Total number of duplicate GUIDs :" + duplicateGuidList.size() + " for service :" + xService.getName() + " and zone :" + xSecurityZone.getName());
                    for (String guid : duplicateGuidList) {
                        List<XXPolicy> xxPolicyList = daoMgr.getXXPolicy().findPolicyByGUIDAndServiceIdAndZoneId(guid, xService.getId(), xSecurityZone.getId());
                        boolean isFirstElement = false;
                        if (CollectionUtils.isNotEmpty(xxPolicyList)) {
                            isFirstElement = true;
                            for (XXPolicy xxPolicy : xxPolicyList) {
                                if (isFirstElement) {
                                    isFirstElement = false;
                                    continue;
                                }
                                RangerPolicy policy = svcStore.getPolicy(xxPolicy.getId());
                                if (policy != null) {
                                    guid = guidUtil.genGUID();
                                    xxPolicy.setGuid(guid);
                                    policy.setGuid(guid);
                                    xxPolicy.setPolicyText(JsonUtils.objectToJson(policy));
                                    daoMgr.getXXPolicy().update(xxPolicy);
                                }
                            }
                        } else {
                            logger.info("No policy found with guid:" + guid);
                        }
                    }
                } else {
                    logger.info("No duplicate GUID found in policy for Service :" + xService.getName() + ", Zone : " + xSecurityZone.getName());
                }
            }
        }
    } else {
        logger.info("No zone or service found");
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone)

Aggregations

XXPolicy (org.apache.ranger.entity.XXPolicy)43 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)25 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)11 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)10 VXPermMapList (org.apache.ranger.view.VXPermMapList)10 XXPortalUser (org.apache.ranger.entity.XXPortalUser)9 XXService (org.apache.ranger.entity.XXService)9 XXServiceDef (org.apache.ranger.entity.XXServiceDef)9 XXUser (org.apache.ranger.entity.XXUser)9 XXUserDao (org.apache.ranger.db.XXUserDao)8 RangerService (org.apache.ranger.plugin.model.RangerService)8 VXAuditMap (org.apache.ranger.view.VXAuditMap)8 VXPermMap (org.apache.ranger.view.VXPermMap)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)6 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)6 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)6 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)6