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);
}
}
}
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);
}
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();
}
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());
}
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);
}
Aggregations