Search in sources :

Example 21 with XXServiceDao

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

the class ServiceDBStore method updateServicesForServiceDefUpdate.

// when a service-def is updated, the updated service-def should be made available to plugins
// this is achieved by incrementing policyVersion of all services of this service-def
protected void updateServicesForServiceDefUpdate(RangerServiceDef serviceDef) throws Exception {
    if (serviceDef == null) {
        return;
    }
    final RangerDaoManager daoManager = daoMgr;
    boolean isTagServiceDef = StringUtils.equals(serviceDef.getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME);
    XXServiceDao serviceDao = daoMgr.getXXService();
    List<XXService> services = serviceDao.findByServiceDefId(serviceDef.getId());
    if (CollectionUtils.isNotEmpty(services)) {
        for (XXService service : services) {
            if (isTagServiceDef) {
                List<XXService> referringServices = serviceDao.findByTagServiceId(service.getId());
                if (CollectionUtils.isNotEmpty(referringServices)) {
                    for (XXService referringService : referringServices) {
                        final Long referringServiceId = referringService.getId();
                        final VERSION_TYPE tagServiceVersionType = VERSION_TYPE.POLICY_VERSION;
                        Runnable tagServiceVersionUpdater = new ServiceVersionUpdater(daoManager, referringServiceId, tagServiceVersionType, RangerPolicyDelta.CHANGE_TYPE_SERVICE_DEF_CHANGE);
                        transactionSynchronizationAdapter.executeOnTransactionCommit(tagServiceVersionUpdater);
                    }
                }
            }
            final Long serviceId = service.getId();
            final VERSION_TYPE versionType = VERSION_TYPE.POLICY_VERSION;
            Runnable serviceVersionUpdater = new ServiceVersionUpdater(daoManager, serviceId, versionType, RangerPolicyDelta.CHANGE_TYPE_SERVICE_DEF_CHANGE);
            transactionSynchronizationAdapter.executeOnTransactionCommit(serviceVersionUpdater);
        }
    }
}
Also used : RangerDaoManager(org.apache.ranger.db.RangerDaoManager) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService)

Example 22 with XXServiceDao

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

the class TestRangerPolicyService method test8getTransactionLog.

@Test
public void test8getTransactionLog() {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    XXService xService = xService();
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(xService);
    List<XXTrxLog> dbXXTrxLogList = policyService.getTransactionLog(rangerPolicy, 1);
    Assert.assertNotNull(dbXXTrxLogList);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) Test(org.junit.Test)

Example 23 with XXServiceDao

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

the class ServiceDBStore method getRangerServiceByName.

private Long getRangerServiceByName(String name) {
    XXService xxService = null;
    XXServiceDao xxServiceDao = daoMgr.getXXService();
    if (xxServiceDao != null) {
        xxService = xxServiceDao.findByName(name);
    }
    return xxService == null ? null : xxService.getId();
}
Also used : XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao)

Example 24 with XXServiceDao

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

the class TestServiceREST method test19getPolicyFalse.

@Test
public void test19getPolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(svcStore.getPolicy(rangerPolicy.getId())).thenReturn(rangerPolicy);
    String userName = "admin";
    Set<String> userGroupsList = new HashSet<String>();
    userGroupsList.add("group1");
    userGroupsList.add("group2");
    List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
    RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
    rangerAccessTypeDefObj.setLabel("Read");
    rangerAccessTypeDefObj.setName("read");
    rangerAccessTypeDefObj.setRbKeyLabel(null);
    rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
    XXServiceDef xServiceDef = serviceDef();
    XXService xService = xService();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    Mockito.when(bizUtil.isAdmin()).thenReturn(true);
    Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    RangerPolicy dbRangerPolicy = serviceREST.getPolicy(rangerPolicy.getId());
    Assert.assertNotNull(dbRangerPolicy);
    Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
    Mockito.verify(svcStore).getPolicy(rangerPolicy.getId());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with XXServiceDao

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

the class TestServiceREST method test50importPoliciesFromFileNotAllowingOverride.

@SuppressWarnings("unchecked")
@Test
public void test50importPoliciesFromFileNotAllowingOverride() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Map<String, RangerPolicy> policiesMap = new LinkedHashMap<String, RangerPolicy>();
    RangerPolicy rangerPolicy = rangerPolicy();
    XXService xService = xService();
    policiesMap.put("Name", rangerPolicy);
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceDef xServiceDef = serviceDef();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXSecurityZoneRefServiceDao xSecZoneRefServiceDao = Mockito.mock(XXSecurityZoneRefServiceDao.class);
    XXSecurityZoneRefTagServiceDao xSecZoneRefTagServiceDao = Mockito.mock(XXSecurityZoneRefTagServiceDao.class);
    XXSecurityZoneRefService xSecZoneRefService = Mockito.mock(XXSecurityZoneRefService.class);
    XXSecurityZoneRefTagService xSecZoneRefTagService = Mockito.mock(XXSecurityZoneRefTagService.class);
    XXSecurityZoneDao xSecZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    XXSecurityZone xSecZone = Mockito.mock(XXSecurityZone.class);
    List<XXSecurityZoneRefService> zoneServiceList = new ArrayList<>();
    List<XXSecurityZoneRefTagService> zoneTagServiceList = new ArrayList<>();
    zoneServiceList.add(xSecZoneRefService);
    zoneTagServiceList.add(xSecZoneRefTagService);
    Map<String, String> zoneMappingMap = new LinkedHashMap<String, String>();
    zoneMappingMap.put("ZoneSource", "ZoneDestination");
    String PARAM_SERVICE_TYPE = "serviceType";
    String serviceTypeList = "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop";
    request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
    SearchFilter filter = new SearchFilter();
    filter.setParam("serviceType", "value");
    File jsonPolicyFile = new File(importPoliceTestFilePath);
    InputStream uploadedInputStream = new FileInputStream(jsonPolicyFile);
    FormDataContentDisposition fileDetail = FormDataContentDisposition.name("file").fileName(jsonPolicyFile.getName()).size(uploadedInputStream.toString().length()).build();
    boolean isOverride = false;
    InputStream zoneInputStream = IOUtils.toInputStream("ZoneSource=ZoneDestination", "UTF-8");
    Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(request.getParameter(PARAM_SERVICE_TYPE)).thenReturn(serviceTypeList);
    Mockito.when(svcStore.createPolicyMap(Mockito.any(Map.class), Mockito.any(List.class), Mockito.anyString(), Mockito.any(Map.class), Mockito.any(List.class), Mockito.any(List.class), Mockito.any(RangerPolicy.class), Mockito.any(Map.class))).thenReturn(policiesMap);
    Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
    Mockito.when(bizUtil.isAdmin()).thenReturn(true);
    Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
    Mockito.when(svcStore.getMapFromInputStream(zoneInputStream)).thenReturn(zoneMappingMap);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xSecZoneDao);
    Mockito.when(xSecZoneDao.findByZoneName(Mockito.anyString())).thenReturn(xSecZone);
    Mockito.when(daoManager.getXXSecurityZoneRefService()).thenReturn(xSecZoneRefServiceDao);
    Mockito.when(xSecZoneRefServiceDao.findByServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneServiceList);
    Mockito.when(daoManager.getXXSecurityZoneRefTagService()).thenReturn(xSecZoneRefTagServiceDao);
    Mockito.when(xSecZoneRefTagServiceDao.findByTagServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneTagServiceList);
    serviceREST.importPoliciesFromFile(request, null, zoneInputStream, uploadedInputStream, fileDetail, isOverride, "unzoneToUnZone");
    Mockito.verify(svcStore).createPolicy(rangerPolicy);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXSecurityZoneRefTagServiceDao(org.apache.ranger.db.XXSecurityZoneRefTagServiceDao) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) XXServiceDao(org.apache.ranger.db.XXServiceDao) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) RangerServiceList(org.apache.ranger.view.RangerServiceList) ArrayList(java.util.ArrayList) List(java.util.List) RangerExportPolicyList(org.apache.ranger.view.RangerExportPolicyList) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) PList(org.apache.ranger.plugin.store.PList) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) FileInputStream(java.io.FileInputStream) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) XXSecurityZoneRefServiceDao(org.apache.ranger.db.XXSecurityZoneRefServiceDao) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) XXService(org.apache.ranger.entity.XXService) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

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