use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameCreationWithGreater255Characters.
@Test
public void testIsValidServiceNameCreationWithGreater255Characters() throws Exception {
String serviceName = "c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1";
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setName(serviceName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, _action, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithSpaceCharacter.
@Test
public void testIsValidServiceNameUpdationWithSpaceCharacter() throws Exception {
String serviceName = "Cluster 1_c1_yarn";
String serviceDisplayName = serviceName;
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setId(1L);
rangerService.setName(serviceName);
rangerService.setDisplayName(serviceDisplayName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
String serviceNameWithoutSpace = "Cluster_1_c1_yarn";
String serviceDisplayNameWithoutSpace = serviceNameWithoutSpace;
RangerService rangerServiceWithoutSpace = new RangerService();
rangerServiceWithoutSpace.setId(1L);
rangerServiceWithoutSpace.setName(serviceNameWithoutSpace);
rangerServiceWithoutSpace.setDisplayName(serviceDisplayNameWithoutSpace);
rangerServiceWithoutSpace.setType("yarn");
rangerServiceWithoutSpace.setTagService("");
// Case: previous service name does not have space, updating with name containing space
when(_store.getService(1L)).thenReturn(rangerServiceWithoutSpace);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
// Case: previous service name does have space, updating with name containing space
when(_store.getService(1L)).thenReturn(rangerService);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean validWithSpace = _validator.isValid(rangerService, Action.UPDATE, _failures);
Assert.assertTrue(validWithSpace);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class ValidationTestUtils method createServiceDefConfigs.
List<RangerServiceConfigDef> createServiceDefConfigs(Object[][] input) {
if (input == null) {
return null;
}
List<RangerServiceConfigDef> result = new ArrayList<>();
for (Object[] row : input) {
RangerServiceConfigDef configDef = mock(RangerServiceConfigDef.class);
switch(row.length) {
case // default value
5:
when(configDef.getDefaultValue()).thenReturn((String) row[4]);
case // subtype
4:
when(configDef.getSubType()).thenReturn((String) row[3]);
case // type
3:
String type = (String) row[2];
when(configDef.getType()).thenReturn(type);
case // name
2:
String name = (String) row[1];
when(configDef.getName()).thenReturn(name);
case // id
1:
Long itemId = (Long) row[0];
when(configDef.getItemId()).thenReturn(itemId);
}
result.add(configDef);
}
return result;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class ValidationTestUtils method createServiceConditionDefs.
// helper methods for tests
List<RangerServiceConfigDef> createServiceConditionDefs(Object[][] input) {
List<RangerServiceConfigDef> result = new ArrayList<>();
for (Object[] data : input) {
RangerServiceConfigDef aConfigDef = mock(RangerServiceConfigDef.class);
when(aConfigDef.getName()).thenReturn((String) data[0]);
when(aConfigDef.getMandatory()).thenReturn((boolean) data[1]);
result.add(aConfigDef);
}
return result;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class RangerServiceDefServiceBase method populateViewBean.
@Override
protected V populateViewBean(T xServiceDef) {
V serviceDef = super.populateViewBean((T) xServiceDef);
Long serviceDefId = xServiceDef.getId();
List<XXServiceConfigDef> xConfigs = daoMgr.getXXServiceConfigDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xConfigs)) {
List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
for (XXServiceConfigDef xConfig : xConfigs) {
RangerServiceConfigDef config = populateXXToRangerServiceConfigDef(xConfig);
configs.add(config);
}
serviceDef.setConfigs(configs);
}
List<XXResourceDef> xResources = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xResources)) {
List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
for (XXResourceDef xResource : xResources) {
RangerResourceDef resource = populateXXToRangerResourceDef(xResource);
resources.add(resource);
}
serviceDef.setResources(resources);
}
List<XXAccessTypeDef> xAccessTypes = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
Map<String, List<String>> impliedGrants = daoMgr.getXXAccessTypeDefGrants().findImpliedGrantsByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xAccessTypes)) {
List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
for (XXAccessTypeDef xAtd : xAccessTypes) {
RangerAccessTypeDef accessType = populateXXToRangerAccessTypeDef(xAtd, impliedGrants.get(xAtd.getName()));
accessTypes.add(accessType);
}
serviceDef.setAccessTypes(accessTypes);
}
List<XXPolicyConditionDef> xPolicyConditions = daoMgr.getXXPolicyConditionDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xPolicyConditions)) {
List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
for (XXPolicyConditionDef xPolicyCondDef : xPolicyConditions) {
RangerPolicyConditionDef policyCondition = populateXXToRangerPolicyConditionDef(xPolicyCondDef);
policyConditions.add(policyCondition);
}
serviceDef.setPolicyConditions(policyConditions);
}
List<XXContextEnricherDef> xContextEnrichers = daoMgr.getXXContextEnricherDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xContextEnrichers)) {
List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
for (XXContextEnricherDef xContextEnricherDef : xContextEnrichers) {
RangerContextEnricherDef contextEnricher = populateXXToRangerContextEnricherDef(xContextEnricherDef);
contextEnrichers.add(contextEnricher);
}
serviceDef.setContextEnrichers(contextEnrichers);
}
List<XXEnumDef> xEnumList = daoMgr.getXXEnumDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xEnumList)) {
List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
for (XXEnumDef xEnum : xEnumList) {
RangerEnumDef vEnum = populateXXToRangerEnumDef(xEnum);
enums.add(vEnum);
}
serviceDef.setEnums(enums);
}
RangerDataMaskDef dataMaskDef = new RangerDataMaskDef();
RangerRowFilterDef rowFilterDef = new RangerRowFilterDef();
List<XXDataMaskTypeDef> xDataMaskTypes = daoMgr.getXXDataMaskTypeDef().findByServiceDefId(serviceDefId);
if (!stringUtil.isEmpty(xDataMaskTypes)) {
List<RangerDataMaskTypeDef> dataMaskTypes = new ArrayList<RangerDataMaskTypeDef>();
for (XXDataMaskTypeDef xDataMaskType : xDataMaskTypes) {
RangerDataMaskTypeDef dataMaskType = populateXXToRangerDataMaskTypeDef(xDataMaskType);
dataMaskTypes.add(dataMaskType);
}
dataMaskDef.setMaskTypes(dataMaskTypes);
}
if (!stringUtil.isEmpty(xResources)) {
for (XXResourceDef xResource : xResources) {
if (StringUtils.isNotEmpty(xResource.getDataMaskOptions())) {
RangerResourceDef dataMaskResource = jsonToObject(xResource.getDataMaskOptions(), RangerResourceDef.class);
dataMaskDef.getResources().add(dataMaskResource);
}
if (StringUtils.isNotEmpty(xResource.getRowFilterOptions())) {
RangerResourceDef resource = jsonToObject(xResource.getRowFilterOptions(), RangerResourceDef.class);
rowFilterDef.getResources().add(resource);
}
}
}
if (!stringUtil.isEmpty(xAccessTypes)) {
for (XXAccessTypeDef xAtd : xAccessTypes) {
if (StringUtils.isNotEmpty(xAtd.getDataMaskOptions())) {
RangerAccessTypeDef dataMaskAccessType = jsonToObject(xAtd.getDataMaskOptions(), RangerAccessTypeDef.class);
dataMaskDef.getAccessTypes().add(dataMaskAccessType);
}
if (StringUtils.isNotEmpty(xAtd.getRowFilterOptions())) {
RangerAccessTypeDef accessType = jsonToObject(xAtd.getRowFilterOptions(), RangerAccessTypeDef.class);
rowFilterDef.getAccessTypes().add(accessType);
}
}
}
serviceDef.setDataMaskDef(dataMaskDef);
serviceDef.setRowFilterDef(rowFilterDef);
ServiceDefUtil.normalize(serviceDef);
return serviceDef;
}
Aggregations