use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ValidationTestUtils method createServiceDefWithAccessTypes.
RangerServiceDef createServiceDefWithAccessTypes(String[] accesses) {
RangerServiceDef serviceDef = mock(RangerServiceDef.class);
List<RangerAccessTypeDef> accessTypeDefs = new ArrayList<>();
for (String access : accesses) {
RangerAccessTypeDef accessTypeDef = mock(RangerAccessTypeDef.class);
when(accessTypeDef.getName()).thenReturn(access);
accessTypeDefs.add(accessTypeDef);
}
when(serviceDef.getAccessTypes()).thenReturn(accessTypeDefs);
return serviceDef;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerServiceDefValidator method validate.
public void validate(final RangerServiceDef serviceDef, final Action action) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.validate(%s, %s)", serviceDef, action));
}
RangerServiceDef normalizedServiceDef = ServiceDefUtil.normalize(serviceDef);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Normalized Service Definition being validated: (%s, %s)", serviceDef, action));
}
List<ValidationFailureDetails> failures = new ArrayList<>();
boolean valid = isValid(normalizedServiceDef, action, failures);
String message = "";
try {
if (!valid) {
message = serializeFailures(failures);
throw new Exception(message);
}
} finally {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.validate(%s, %s): %s, reason[%s]", normalizedServiceDef, action, valid, message));
}
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerServiceDefValidator method isValidServiceDefName.
boolean isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures));
}
boolean valid = true;
if (StringUtils.isBlank(name)) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME;
failures.add(new ValidationFailureDetailsBuilder().field("name").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build());
valid = false;
} else {
RangerServiceDef otherServiceDef = getServiceDef(name);
if (otherServiceDef != null && action == Action.CREATE) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT;
failures.add(new ValidationFailureDetailsBuilder().field("name").isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(name)).build());
valid = false;
} else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT;
failures.add(new ValidationFailureDetailsBuilder().field("id/name").isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(name, otherServiceDef.getId())).build());
valid = false;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, failures, valid));
}
return valid;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefService method test2ValidateForUpdate.
@Test
public void test2ValidateForUpdate() {
RangerServiceDef rangerServiceDef = rangerServiceDef();
XXServiceDef serviceDef = serviceDef();
serviceDefService.validateForUpdate(rangerServiceDef, serviceDef);
Assert.assertNotNull(rangerServiceDef);
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefService method test3PopulateViewBean.
@Test
public void test3PopulateViewBean() {
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
XXAccessTypeDefDao xAccessTypeDefDao = Mockito.mock(XXAccessTypeDefDao.class);
XXPolicyConditionDefDao xPolicyConditionDefDao = Mockito.mock(XXPolicyConditionDefDao.class);
XXServiceConfigDefDao xServiceConfigDefDao = Mockito.mock(XXServiceConfigDefDao.class);
XXContextEnricherDefDao xContextEnricherDefDao = Mockito.mock(XXContextEnricherDefDao.class);
XXEnumDefDao xEnumDefDao = Mockito.mock(XXEnumDefDao.class);
XXEnumElementDefDao xEnumElementDefDao = Mockito.mock(XXEnumElementDefDao.class);
XXServiceDef serviceDef = serviceDef();
String name = "fdfdfds";
XXPortalUser tUser = new XXPortalUser();
tUser.setAddedByUserId(Id);
tUser.setCreateTime(new Date());
tUser.setEmailAddress("test@gmail.com");
tUser.setFirstName(name);
tUser.setId(Id);
tUser.setLastName(name);
List<XXResourceDef> resDefList = new ArrayList<XXResourceDef>();
XXResourceDef resourceDef = new XXResourceDef();
resourceDef.setAddedByUserId(Id);
resourceDef.setCreateTime(new Date());
resourceDef.setDefid(Id);
resourceDef.setDescription("test");
resourceDef.setId(Id);
resDefList.add(resourceDef);
List<XXPolicyItem> xPolicyItemList = new ArrayList<XXPolicyItem>();
XXPolicyItem xPolicyItem = new XXPolicyItem();
xPolicyItem.setDelegateAdmin(false);
xPolicyItem.setAddedByUserId(null);
xPolicyItem.setCreateTime(new Date());
xPolicyItem.setGUID(null);
xPolicyItem.setId(Id);
xPolicyItem.setOrder(null);
xPolicyItem.setPolicyId(Id);
xPolicyItem.setUpdatedByUserId(null);
xPolicyItem.setUpdateTime(new Date());
xPolicyItemList.add(xPolicyItem);
List<XXPolicyItemAccess> policyItemAccessList = new ArrayList<XXPolicyItemAccess>();
XXPolicyItemAccess policyItemAccess = new XXPolicyItemAccess();
policyItemAccess.setAddedByUserId(Id);
policyItemAccess.setCreateTime(new Date());
policyItemAccess.setPolicyitemid(Id);
policyItemAccess.setId(Id);
policyItemAccess.setOrder(1);
policyItemAccess.setUpdatedByUserId(Id);
policyItemAccess.setUpdateTime(new Date());
policyItemAccessList.add(policyItemAccess);
List<XXPolicyConditionDef> xConditionDefList = new ArrayList<XXPolicyConditionDef>();
XXPolicyConditionDef policyConditionDefObj = new XXPolicyConditionDef();
policyConditionDefObj.setAddedByUserId(Id);
policyConditionDefObj.setCreateTime(new Date());
policyConditionDefObj.setDefid(Id);
policyConditionDefObj.setDescription("policy conditio");
policyConditionDefObj.setId(Id);
policyConditionDefObj.setName(name);
policyConditionDefObj.setOrder(1);
policyConditionDefObj.setLabel("label");
xConditionDefList.add(policyConditionDefObj);
List<XXPolicyItemCondition> policyItemConditionList = new ArrayList<XXPolicyItemCondition>();
XXPolicyItemCondition policyItemCondition = new XXPolicyItemCondition();
policyItemCondition.setAddedByUserId(Id);
policyItemCondition.setCreateTime(new Date());
policyItemCondition.setType(1L);
policyItemCondition.setId(Id);
policyItemCondition.setOrder(1);
policyItemCondition.setPolicyItemId(Id);
policyItemCondition.setUpdatedByUserId(Id);
policyItemCondition.setUpdateTime(new Date());
policyItemConditionList.add(policyItemCondition);
List<XXServiceConfigDef> serviceConfigDefList = new ArrayList<XXServiceConfigDef>();
XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
serviceConfigDefObj.setAddedByUserId(Id);
serviceConfigDefObj.setCreateTime(new Date());
serviceConfigDefObj.setDefaultvalue("simple");
serviceConfigDefObj.setDescription("service config");
serviceConfigDefObj.setId(Id);
serviceConfigDefObj.setIsMandatory(true);
serviceConfigDefObj.setName(name);
serviceConfigDefObj.setLabel("username");
serviceConfigDefObj.setRbkeydescription(null);
serviceConfigDefObj.setRbkeylabel(null);
serviceConfigDefObj.setRbKeyValidationMessage(null);
serviceConfigDefObj.setType("password");
serviceConfigDefList.add(serviceConfigDefObj);
List<XXContextEnricherDef> contextEnrichersList = new ArrayList<XXContextEnricherDef>();
XXContextEnricherDef contextEnricherDefObj = new XXContextEnricherDef();
contextEnricherDefObj.setAddedByUserId(Id);
contextEnricherDefObj.setCreateTime(new Date());
contextEnricherDefObj.setDefid(Id);
contextEnricherDefObj.setEnricher("RangerCountryProvider");
contextEnricherDefObj.setName("country-provider");
contextEnricherDefObj.setId(Id);
contextEnricherDefObj.setOrder(0);
contextEnricherDefObj.setUpdatedByUserId(Id);
contextEnricherDefObj.setUpdateTime(new Date());
contextEnrichersList.add(contextEnricherDefObj);
List<XXEnumDef> xEnumList = new ArrayList<XXEnumDef>();
XXEnumDef enumDefObj = new XXEnumDef();
enumDefObj.setAddedByUserId(Id);
enumDefObj.setCreateTime(new Date());
enumDefObj.setDefaultindex(null);
enumDefObj.setDefid(Id);
enumDefObj.setId(Id);
enumDefObj.setName(name);
enumDefObj.setUpdatedByUserId(Id);
enumDefObj.setUpdateTime(new Date());
xEnumList.add(enumDefObj);
List<XXEnumElementDef> xElementsList = new ArrayList<XXEnumElementDef>();
XXEnumElementDef enumElementDefObj = new XXEnumElementDef();
enumElementDefObj.setAddedByUserId(Id);
enumElementDefObj.setCreateTime(new Date());
enumElementDefObj.setEnumdefid(Id);
enumElementDefObj.setId(Id);
enumElementDefObj.setLabel("Authentication");
enumElementDefObj.setName("authentication");
enumElementDefObj.setUpdateTime(new Date());
enumElementDefObj.setUpdatedByUserId(Id);
enumElementDefObj.setRbkeylabel(null);
enumElementDefObj.setOrder(0);
xElementsList.add(enumElementDefObj);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(Id)).thenReturn(tUser);
Mockito.when(daoManager.getXXServiceConfigDef()).thenReturn(xServiceConfigDefDao);
Mockito.when(xServiceConfigDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(serviceConfigDefList);
Mockito.when(daoManager.getXXResourceDef()).thenReturn(xResourceDefDao);
Mockito.when(daoManager.getXXAccessTypeDef()).thenReturn(xAccessTypeDefDao);
Mockito.when(daoManager.getXXPolicyConditionDef()).thenReturn(xPolicyConditionDefDao);
Mockito.when(daoManager.getXXContextEnricherDef()).thenReturn(xContextEnricherDefDao);
Mockito.when(xContextEnricherDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(contextEnrichersList);
Mockito.when(daoManager.getXXEnumDef()).thenReturn(xEnumDefDao);
Mockito.when(xEnumDefDao.findByServiceDefId(serviceDef.getId())).thenReturn(xEnumList);
Mockito.when(daoManager.getXXEnumElementDef()).thenReturn(xEnumElementDefDao);
Mockito.when(xEnumElementDefDao.findByEnumDefId(enumElementDefObj.getId())).thenReturn(xElementsList);
XXDataMaskTypeDefDao xDataMaskTypeDao = Mockito.mock(XXDataMaskTypeDefDao.class);
List<XXDataMaskTypeDef> xDataMaskTypeDefs = new ArrayList<XXDataMaskTypeDef>();
Mockito.when(daoManager.getXXDataMaskTypeDef()).thenReturn(xDataMaskTypeDao);
Mockito.when(xDataMaskTypeDao.findByServiceDefId(serviceDef.getId())).thenReturn(xDataMaskTypeDefs);
RangerServiceDef dbRangerServiceDef = serviceDefService.populateViewBean(serviceDef);
Assert.assertNotNull(dbRangerServiceDef);
Assert.assertEquals(dbRangerServiceDef.getId(), serviceDef.getId());
Assert.assertEquals(dbRangerServiceDef.getName(), serviceDef.getName());
Assert.assertEquals(dbRangerServiceDef.getDescription(), serviceDef.getDescription());
Assert.assertEquals(dbRangerServiceDef.getGuid(), serviceDef.getGuid());
Assert.assertEquals(dbRangerServiceDef.getVersion(), serviceDef.getVersion());
Mockito.verify(daoManager).getXXServiceConfigDef();
Mockito.verify(daoManager).getXXResourceDef();
Mockito.verify(daoManager).getXXAccessTypeDef();
Mockito.verify(daoManager).getXXPolicyConditionDef();
Mockito.verify(daoManager).getXXContextEnricherDef();
Mockito.verify(daoManager).getXXEnumDef();
Mockito.verify(daoManager).getXXEnumElementDef();
}
Aggregations