@Test public void test_isValidPolicyItem_happPath() { RangerPolicyItem policyItem = mock(RangerPolicyItem.class); when(policyItem.getAccesses()).thenReturn(null); when(policyItem.getDelegateAdmin()).thenReturn(true); List<String> users = Arrays.asList("user1"); when(policyItem.getUsers()).thenReturn(users); _failures.clear(); Assert.assertTrue(_validator.isValidPolicyItem(policyItem, _failures, _serviceDef)); Assert.assertTrue(_failures.isEmpty()); }
boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", policyItem, failures, serviceDef)); } boolean valid = true; if (policyItem == null) { LOG.debug("policy item was null!"); } else { if (CollectionUtils.isEmpty(policyItem.getAccesses())) { if (!Boolean.TRUE.equals(policyItem.getDelegateAdmin())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("policy item accesses") .isMissing() .becauseOf(error.getMessage("policy item accesses")) .errorCode(error.getErrorCode()) .build()); valid = false; } else { LOG.debug("policy item collection was null but delegated admin is true. Ok"); } } else { valid = isValidItemAccesses(policyItem.getAccesses(), failures, serviceDef) && valid; } if (CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_USER_AND_GROUPS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item users/user-groups/roles") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", policyItem, failures, serviceDef, valid)); } return valid; }
RangerPolicyValidator extends RangerValidator { boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", policyItem, failures, serviceDef)); } boolean valid = true; if (policyItem == null) { LOG.debug("policy item was null!"); } else { if (CollectionUtils.isEmpty(policyItem.getAccesses())) { if (!Boolean.TRUE.equals(policyItem.getDelegateAdmin())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("policy item accesses") .isMissing() .becauseOf(error.getMessage("policy item accesses")) .errorCode(error.getErrorCode()) .build()); valid = false; } else { LOG.debug("policy item collection was null but delegated admin is true. Ok"); } } else { valid = isValidItemAccesses(policyItem.getAccesses(), failures, serviceDef) && valid; } if (CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_USER_AND_GROUPS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item users/user-groups/roles") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", policyItem, failures, serviceDef, valid)); } return valid; } }
RangerPolicyValidator extends RangerValidator { boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", policyItem, failures, serviceDef)); } boolean valid = true; if (policyItem == null) { LOG.debug("policy item was null!"); } else { if (CollectionUtils.isEmpty(policyItem.getAccesses())) { if (!Boolean.TRUE.equals(policyItem.getDelegateAdmin())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("policy item accesses") .isMissing() .becauseOf(error.getMessage("policy item accesses")) .errorCode(error.getErrorCode()) .build()); valid = false; } else { LOG.debug("policy item collection was null but delegated admin is true. Ok"); } } else { valid = isValidItemAccesses(policyItem.getAccesses(), failures, serviceDef) && valid; } if (CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_USER_AND_GROUPS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item users/user-groups/roles") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", policyItem, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); }
RangerPolicyValidator extends RangerValidator { boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", policyItem, failures, serviceDef)); } boolean valid = true; if (policyItem == null) { LOG.debug("policy item was null!"); } else { if (CollectionUtils.isEmpty(policyItem.getAccesses())) { if (!Boolean.TRUE.equals(policyItem.getDelegateAdmin())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("policy item accesses") .isMissing() .becauseOf(error.getMessage("policy item accesses")) .errorCode(error.getErrorCode()) .build()); valid = false; } else { LOG.debug("policy item collection was null but delegated admin is true. Ok"); } } else { valid = isValidItemAccesses(policyItem.getAccesses(), failures, serviceDef) && valid; } if (CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_USER_AND_GROUPS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item users/user-groups/roles") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", policyItem, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin); }
RangerPolicyValidator extends RangerValidator { boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", policyItem, failures, serviceDef)); } boolean valid = true; if (policyItem == null) { LOG.debug("policy item was null!"); } else { if (CollectionUtils.isEmpty(policyItem.getAccesses())) { if (!Boolean.TRUE.equals(policyItem.getDelegateAdmin())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("policy item accesses") .isMissing() .becauseOf(error.getMessage("policy item accesses")) .errorCode(error.getErrorCode()) .build()); valid = false; } else { LOG.debug("policy item collection was null but delegated admin is true. Ok"); } } else { valid = isValidItemAccesses(policyItem.getAccesses(), failures, serviceDef) && valid; } if (CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_USER_AND_GROUPS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item users/user-groups/roles") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", policyItem, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin);  }