use of org.apache.ranger.plugin.model.validation.ValidationFailureDetails in project ranger by apache.
the class TagDBStore method validateTag.
private RangerTag validateTag(RangerTag tag) throws Exception {
List<RangerValiditySchedule> validityPeriods = tag.getValidityPeriods();
if (CollectionUtils.isNotEmpty(validityPeriods)) {
List<RangerValiditySchedule> normalizedValidityPeriods = new ArrayList<>();
List<ValidationFailureDetails> failures = new ArrayList<>();
for (RangerValiditySchedule validityPeriod : validityPeriods) {
RangerValidityScheduleValidator validator = new RangerValidityScheduleValidator(validityPeriod);
RangerValiditySchedule normalizedValidityPeriod = validator.validate(failures);
if (normalizedValidityPeriod != null && CollectionUtils.isEmpty(failures)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Normalized ValidityPeriod:[" + normalizedValidityPeriod + "]");
}
normalizedValidityPeriods.add(normalizedValidityPeriod);
} else {
String error = "Incorrect time-specification:[" + Arrays.asList(failures) + "]";
LOG.error(error);
throw new Exception(error);
}
}
tag.setValidityPeriods(normalizedValidityPeriods);
}
return tag;
}
use of org.apache.ranger.plugin.model.validation.ValidationFailureDetails in project ranger by apache.
the class TestPolicyEngine method runValiditySchedulerTests.
private void runValiditySchedulerTests(String resourceName) {
TimeZone defaultTZ = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
List<ValiditySchedulerTestCase> testCases = null;
InputStream inStream = this.getClass().getResourceAsStream(resourceName);
InputStreamReader reader = new InputStreamReader(inStream);
try {
Type listType = new TypeToken<List<ValiditySchedulerTestCase>>() {
}.getType();
testCases = gsonBuilder.fromJson(reader, listType);
} catch (Exception e) {
assertFalse("Exception in reading validity-scheduler test cases.", true);
}
assertNotNull("TestCases are null!", testCases);
if (CollectionUtils.isNotEmpty(testCases)) {
for (ValiditySchedulerTestCase testCase : testCases) {
boolean isValid = true;
List<ValidationFailureDetails> validationFailures = new ArrayList<>();
boolean isApplicable = false;
List<RangerValiditySchedule> validatedSchedules = new ArrayList<>();
for (RangerValiditySchedule validitySchedule : testCase.validitySchedules) {
RangerValidityScheduleValidator validator = new RangerValidityScheduleValidator(validitySchedule);
RangerValiditySchedule validatedSchedule = validator.validate(validationFailures);
isValid = isValid && validatedSchedule != null;
if (isValid) {
validatedSchedules.add(validatedSchedule);
}
}
if (isValid) {
for (RangerValiditySchedule validSchedule : validatedSchedules) {
isApplicable = new RangerValidityScheduleEvaluator(validSchedule).isApplicable(testCase.accessTime.getTime());
if (isApplicable) {
break;
}
}
}
assertTrue(testCase.name, isValid == testCase.result.isValid);
assertTrue(testCase.name, isApplicable == testCase.result.isApplicable);
assertTrue(testCase.name + ", [" + validationFailures + "]", validationFailures.size() == testCase.result.validationFailureCount);
}
}
TimeZone.setDefault(defaultTZ);
}
Aggregations