use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.
the class RangerPolicyServiceBase method mapEntityToViewBean.
@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
XXService xService = daoMgr.getXXService().getById(xObj.getService());
vObj.setGuid(xObj.getGuid());
vObj.setVersion(xObj.getVersion());
vObj.setService(xService.getName());
vObj.setName(StringUtils.trim(xObj.getName()));
vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType());
vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority());
vObj.setDescription(xObj.getDescription());
vObj.setResourceSignature(xObj.getResourceSignature());
vObj.setIsEnabled(xObj.getIsEnabled());
vObj.setIsAuditEnabled(xObj.getIsAuditEnabled());
Map<String, Object> options = JsonUtils.jsonToObject(xObj.getOptions(), Map.class);
if (MapUtils.isNotEmpty(options)) {
String optionPolicyValiditySchedule = (String) options.remove(OPTION_POLICY_VALIDITY_SCHEDULES);
if (StringUtils.isNotBlank(optionPolicyValiditySchedule)) {
List<RangerValiditySchedule> validitySchedules = JsonUtils.jsonToRangerValiditySchedule(optionPolicyValiditySchedule);
vObj.setValiditySchedules(validitySchedules);
}
}
vObj.setOptions(options);
return vObj;
}
use of org.apache.ranger.plugin.model.RangerValiditySchedule 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);
}
use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.
the class RangerPolicyValidator method isValidValiditySchedule.
boolean isValidValiditySchedule(RangerPolicy policy, final List<ValidationFailureDetails> failures, Action action) {
boolean valid = true;
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerPolicyValidator.isValidValiditySchedule(%s, %s, %s)", policy, failures, action));
}
List<RangerValiditySchedule> validitySchedules = policy.getValiditySchedules();
List<RangerValiditySchedule> normalizedValiditySchedules = null;
for (RangerValiditySchedule entry : validitySchedules) {
RangerValidityScheduleValidator validator = new RangerValidityScheduleValidator(entry);
RangerValiditySchedule normalizedValiditySchedule = validator.validate(failures);
if (normalizedValiditySchedule == null) {
valid = false;
if (LOG.isDebugEnabled()) {
LOG.debug("Invalid Validity-Schedule:[" + entry + "]");
}
} else {
if (normalizedValiditySchedules == null) {
normalizedValiditySchedules = new ArrayList<>();
}
normalizedValiditySchedules.add(normalizedValiditySchedule);
}
}
if (valid && CollectionUtils.isNotEmpty(normalizedValiditySchedules)) {
policy.setValiditySchedules(normalizedValiditySchedules);
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerPolicyValidator.isValidValiditySchedule(%s, %s, %s): %s", policy, failures, action, valid));
}
return valid;
}
use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.
the class RangerAtlasEntityWithTags method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (entity != null) {
sb.append("{entity=").append(entity).append(", ");
}
sb.append(", classifications={");
if (CollectionUtils.isNotEmpty(tags)) {
for (EntityNotificationWrapper.RangerAtlasClassification tag : tags) {
sb.append("classificationName=").append(tag.getName());
sb.append(", attributes={");
for (Map.Entry<String, String> attribute : tag.getAttributes().entrySet()) {
sb.append("{attributeName=").append(attribute.getKey());
sb.append(",attributeValue=").append(attribute.getValue());
sb.append("}");
}
sb.append("}");
sb.append(", validityPeriods={");
if (CollectionUtils.isNotEmpty(tag.getValidityPeriods())) {
for (RangerValiditySchedule period : tag.getValidityPeriods()) {
sb.append("{").append(period).append("}");
}
}
sb.append("}");
}
}
sb.append("}");
sb.append("}");
return sb.toString();
}
Aggregations