Search in sources :

Example 16 with RangerServiceConfigDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.

the class RangerSecurityZoneValidatorTest method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    RangerResourceDef rangerResourceDef = new RangerResourceDef();
    rangerResourceDef.setName("hdfs");
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
    resources.add(rangerResourceDef);
    List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
    RangerServiceDef rangerServiceDef = new RangerServiceDef();
    rangerServiceDef.setId(1L);
    rangerServiceDef.setImplClass("RangerServiceHdfs");
    rangerServiceDef.setName("HDFS Repository");
    rangerServiceDef.setLabel("HDFS Repository");
    rangerServiceDef.setDescription("HDFS Repository");
    rangerServiceDef.setRbKeyDescription(null);
    rangerServiceDef.setUpdatedBy("Admin");
    rangerServiceDef.setUpdateTime(new Date());
    rangerServiceDef.setConfigs(configs);
    rangerServiceDef.setResources(resources);
    rangerServiceDef.setAccessTypes(accessTypes);
    rangerServiceDef.setPolicyConditions(policyConditions);
    rangerServiceDef.setContextEnrichers(contextEnrichers);
    rangerServiceDef.setEnums(enums);
    return rangerServiceDef;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 17 with RangerServiceConfigDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.

the class TestRangerServiceValidator method testIsValidServiceNameCreationWithSpecialCharacters.

@Test
public void testIsValidServiceNameCreationWithSpecialCharacters() throws Exception {
    String serviceName = "<script>c1_yarn</script>";
    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);
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) HashMap(java.util.HashMap) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) ValidationErrorCode(org.apache.ranger.plugin.errors.ValidationErrorCode) Test(org.junit.Test)

Example 18 with RangerServiceConfigDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.

the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithGreater255Characters.

@Test
public void testIsValidServiceNameUpdationWithGreater255Characters() 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.setId(1L);
    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.getService(1L)).thenReturn(rangerService);
    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);
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) HashMap(java.util.HashMap) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) ValidationErrorCode(org.apache.ranger.plugin.errors.ValidationErrorCode) Test(org.junit.Test)

Example 19 with RangerServiceConfigDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.

the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithSpecialCharacters.

@Test
public void testIsValidServiceNameUpdationWithSpecialCharacters() throws Exception {
    String serviceName = "<alert>c1_yarn</alert>";
    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.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.getService(1L)).thenReturn(rangerService);
    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);
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) HashMap(java.util.HashMap) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) ValidationErrorCode(org.apache.ranger.plugin.errors.ValidationErrorCode) Test(org.junit.Test)

Example 20 with RangerServiceConfigDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.

the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithOutSpecialCharacters.

@Test
public void testIsValidServiceNameUpdationWithOutSpecialCharacters() throws Exception {
    String serviceName = "c1_yarn";
    String serviceDisplayName = serviceName;
    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);
    when(_store.getService(1L)).thenReturn(rangerService);
    when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
    boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures);
    Assert.assertEquals(0, _failures.size());
    Assert.assertTrue(valid);
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) HashMap(java.util.HashMap) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)30 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)22 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)13 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)11 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)11 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)11 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)11 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)11 RangerService (org.apache.ranger.plugin.model.RangerService)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)6 XXServiceConfigDef (org.apache.ranger.entity.XXServiceConfigDef)4 XXServiceDef (org.apache.ranger.entity.XXServiceDef)4 RangerDataMaskDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskDef)3 RangerDataMaskTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskTypeDef)3 RangerRowFilterDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerRowFilterDef)3 VXString (org.apache.ranger.view.VXString)3 XXAccessTypeDefDao (org.apache.ranger.db.XXAccessTypeDefDao)2