Search in sources :

Example 31 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class TestTagREST method test57getSecureServiceTagsIfUpdated.

@Test
public void test57getSecureServiceTagsIfUpdated() {
    boolean isAdmin = false;
    boolean isKeyAdmin = false;
    boolean isAllowed = true;
    ServiceTags oldServiceTag = null;
    XXService xService = new XXService();
    xService.setId(id);
    xService.setName(serviceName);
    xService.setType(5L);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(id);
    xServiceDef.setVersion(5L);
    RangerService rangerService = new RangerService();
    rangerService.setId(id);
    rangerService.setName(serviceName);
    XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
    Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
    Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
    Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
    Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    try {
        Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
    } catch (Exception e) {
    }
    Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
    try {
        Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion, true)).thenReturn(oldServiceTag);
    } catch (Exception e) {
    }
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, false, capabilityVector, null);
    Mockito.verify(bizUtil).isAdmin();
    Mockito.verify(bizUtil).isKeyAdmin();
    Mockito.verify(daoManager).getXXService();
    Mockito.verify(xXServiceDao).findByName(serviceName);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(xXServiceDefDao).getById(xService.getType());
    try {
        Mockito.verify(svcStore).getServiceByName(serviceName);
    } catch (Exception e) {
    }
    Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
    try {
        Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion, false);
    } catch (Exception e) {
    }
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) WebApplicationException(javax.ws.rs.WebApplicationException) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 32 with XXServiceDao

use of org.apache.ranger.db.XXServiceDao in project ranger by apache.

the class RangerRoleService method updateRoleVersions.

private void updateRoleVersions(Set<Long> roleIds) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> updatePolicyVersions(roleIds=" + roleIds + ")");
    }
    if (CollectionUtils.isNotEmpty(roleIds)) {
        Set<Long> allAffectedServiceIds = new HashSet<>();
        for (Long roleId : roleIds) {
            List<Long> affectedServiceIds = daoMgr.getXXPolicy().findServiceIdsByRoleId(roleId);
            allAffectedServiceIds.addAll(affectedServiceIds);
        }
        XXServiceDao serviceDao = daoMgr.getXXService();
        if (CollectionUtils.isNotEmpty(allAffectedServiceIds)) {
            for (final Long serviceId : allAffectedServiceIds) {
                Runnable serviceVersionUpdater = new ServiceDBStore.ServiceVersionUpdater(daoMgr, serviceId, ServiceDBStore.VERSION_TYPE.ROLE_VERSION, null, RangerPolicyDelta.CHANGE_TYPE_ROLE_UPDATE, null);
                daoMgr.getRangerTransactionSynchronizationAdapter().executeOnTransactionCommit(serviceVersionUpdater);
                XXService serviceDbObj = serviceDao.getById(serviceId);
                boolean isTagService = serviceDbObj.getType() == EmbeddedServiceDefsUtil.instance().getTagServiceDefId();
                if (isTagService) {
                    updateRoleVersionOfAllServicesRefferingTag(daoMgr, serviceDao, serviceId);
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== updatePolicyVersions(roleIds=" + roleIds + ")");
    }
}
Also used : XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) HashSet(java.util.HashSet)

Aggregations

XXServiceDao (org.apache.ranger.db.XXServiceDao)32 XXService (org.apache.ranger.entity.XXService)31 Test (org.junit.Test)26 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)23 XXServiceDef (org.apache.ranger.entity.XXServiceDef)20 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)13 ArrayList (java.util.ArrayList)11 RangerService (org.apache.ranger.plugin.model.RangerService)11 WebApplicationException (javax.ws.rs.WebApplicationException)9 VXString (org.apache.ranger.view.VXString)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)6 ExpectedException (org.junit.rules.ExpectedException)6 HashSet (java.util.HashSet)5 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)5 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)5 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)4 Date (java.util.Date)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 XXPolicy (org.apache.ranger.entity.XXPolicy)3