@Test public void test_isValidItemAccesses_failure() { List<RangerPolicyItemAccess> accesses = new ArrayList<>(); accesses.add(null); _failures.clear(); Assert.assertFalse(_validator.isValidItemAccesses(accesses, _failures, _serviceDef)); _utils.checkFailureForMissingValue(_failures, "policy item access"); Object[][] data = new Object[][] { { "a", null }, { null, null }, { "c", true }, }; accesses = _utils.createItemAccess(data); _serviceDef = _utils.createServiceDefWithAccessTypes(new String[] { "a", "b", "c", "d" }); _failures.clear(); Assert.assertFalse(_validator.isValidItemAccesses(accesses, _failures, _serviceDef)); }
boolean isValidItemAccesses(List<RangerPolicyItemAccess> accesses, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", accesses, failures, serviceDef)); } boolean valid = true; if (CollectionUtils.isEmpty(accesses)) { LOG.debug("policy item accesses collection was null/empty!"); } else { Set<String> accessTypes = getAccessTypes(serviceDef); for (RangerPolicyItemAccess access : accesses) { if (access == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_ACCESS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item access") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else { valid = isValidPolicyItemAccess(access, failures, accessTypes) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses, failures, serviceDef, valid)); } return valid; }
RangerPolicyValidator extends RangerValidator { boolean isValidItemAccesses(List<RangerPolicyItemAccess> accesses, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", accesses, failures, serviceDef)); } boolean valid = true; if (CollectionUtils.isEmpty(accesses)) { LOG.debug("policy item accesses collection was null/empty!"); } else { Set<String> accessTypes = getAccessTypes(serviceDef); for (RangerPolicyItemAccess access : accesses) { if (access == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_ACCESS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item access") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else { valid = isValidPolicyItemAccess(access, failures, accessTypes) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses, failures, serviceDef, valid)); } return valid; } }
RangerPolicyValidator extends RangerValidator { boolean isValidItemAccesses(List<RangerPolicyItemAccess> accesses, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", accesses, failures, serviceDef)); } boolean valid = true; if (CollectionUtils.isEmpty(accesses)) { LOG.debug("policy item accesses collection was null/empty!"); } else { Set<String> accessTypes = getAccessTypes(serviceDef); for (RangerPolicyItemAccess access : accesses) { if (access == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_ACCESS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item access") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else { valid = isValidPolicyItemAccess(access, failures, accessTypes) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); }
RangerPolicyValidator extends RangerValidator { boolean isValidItemAccesses(List<RangerPolicyItemAccess> accesses, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", accesses, failures, serviceDef)); } boolean valid = true; if (CollectionUtils.isEmpty(accesses)) { LOG.debug("policy item accesses collection was null/empty!"); } else { Set<String> accessTypes = getAccessTypes(serviceDef); for (RangerPolicyItemAccess access : accesses) { if (access == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_ACCESS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item access") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else { valid = isValidPolicyItemAccess(access, failures, accessTypes) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin); }
RangerPolicyValidator extends RangerValidator { boolean isValidItemAccesses(List<RangerPolicyItemAccess> accesses, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", accesses, failures, serviceDef)); } boolean valid = true; if (CollectionUtils.isEmpty(accesses)) { LOG.debug("policy item accesses collection was null/empty!"); } else { Set<String> accessTypes = getAccessTypes(serviceDef); for (RangerPolicyItemAccess access : accesses) { if (access == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_ACCESS; failures.add(new ValidationFailureDetailsBuilder() .field("policy item access") .isMissing() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else { valid = isValidPolicyItemAccess(access, failures, accessTypes) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %b", accesses, failures, serviceDef, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin);  }