use of org.apache.ranger.plugin.errors.ValidationErrorCode in project ranger by apache.
the class RangerServiceDefValidator method isValidAccessTypes.
boolean isValidAccessTypes(final List<RangerAccessTypeDef> accessTypeDefs, final List<ValidationFailureDetails> failures) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.isValidAccessTypes(%s, %s)", accessTypeDefs, failures));
}
boolean valid = true;
if (CollectionUtils.isEmpty(accessTypeDefs)) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_MISSING_FIELD;
failures.add(new ValidationFailureDetailsBuilder().field("access types").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("access types")).build());
valid = false;
} else {
List<RangerAccessTypeDef> defsWithImpliedGrants = new ArrayList<>();
Set<String> accessNames = new HashSet<>();
Set<Long> ids = new HashSet<>();
for (RangerAccessTypeDef def : accessTypeDefs) {
String name = def.getName();
valid = isUnique(name, accessNames, "access type name", "access types", failures) && valid;
valid = isUnique(def.getItemId(), ids, "access type itemId", "access types", failures) && valid;
if (CollectionUtils.isNotEmpty(def.getImpliedGrants())) {
defsWithImpliedGrants.add(def);
}
}
// validate implied grants
for (RangerAccessTypeDef def : defsWithImpliedGrants) {
Collection<String> impliedGrants = getImpliedGrants(def);
Set<String> unknownAccessTypes = Sets.difference(Sets.newHashSet(impliedGrants), accessNames);
if (!unknownAccessTypes.isEmpty()) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_IMPLIED_GRANT_UNKNOWN_ACCESS_TYPE;
failures.add(new ValidationFailureDetailsBuilder().field("implied grants").subField(// we return just on item here. Message has all unknow items
unknownAccessTypes.iterator().next()).isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(impliedGrants, unknownAccessTypes)).build());
valid = false;
}
// implied grant should not imply itself!
// note: this name could be null/blank/empty!
String name = def.getName();
if (impliedGrants.contains(name)) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_IMPLIED_GRANT_IMPLIES_ITSELF;
failures.add(new ValidationFailureDetailsBuilder().field("implied grants").subField(name).isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(impliedGrants, name)).build());
valid = false;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.isValidAccessTypes(%s, %s): %s", accessTypeDefs, failures, valid));
}
return valid;
}
use of org.apache.ranger.plugin.errors.ValidationErrorCode in project ranger by apache.
the class RangerServiceDefValidator method isValidEnumElements.
boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures));
}
boolean valid = true;
if (CollectionUtils.isEmpty(enumElementsDefs)) {
LOG.debug("Enum elements list passed in was null/empty!");
} else {
// enum element names should be valid and distinct
Set<String> elementNames = new HashSet<>();
Set<Long> ids = new HashSet<>();
for (RangerEnumElementDef elementDef : enumElementsDefs) {
if (elementDef == null) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT;
failures.add(new ValidationFailureDetailsBuilder().field("enum element").subField(enumName).isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage(enumName)).build());
valid = false;
} else {
valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid;
valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid));
}
return valid;
}
use of org.apache.ranger.plugin.errors.ValidationErrorCode in project ranger by apache.
the class RangerServiceDefValidator method isValidConfigType.
boolean isValidConfigType(String type, String configName, List<ValidationFailureDetails> failures) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigType(%s, %s, %s)", type, configName, failures));
}
boolean valid = true;
Set<String> validTypes = ImmutableSet.of("bool", "enum", "int", "string", "password", "path");
if (StringUtils.isBlank(type)) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_CONFIG_DEF_MISSING_TYPE;
failures.add(new ValidationFailureDetailsBuilder().field("config def type").subField(configName).isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage(configName)).build());
valid = false;
} else if (!validTypes.contains(type)) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_CONFIG_DEF_INVALID_TYPE;
failures.add(new ValidationFailureDetailsBuilder().field("config def type").subField(configName).isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(type, configName, validTypes)).build());
valid = false;
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigType(%s, %s, %s): %s", type, configName, failures, valid));
}
return valid;
}
use of org.apache.ranger.plugin.errors.ValidationErrorCode in project ranger by apache.
the class RangerServiceDefValidator method isValidServiceDefId.
boolean isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures));
}
boolean valid = true;
if (action == Action.UPDATE) {
// id is ignored for CREATE
if (id == null) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID;
failures.add(new ValidationFailureDetailsBuilder().field("id").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage()).build());
valid = false;
} else if (getServiceDef(id) == null) {
ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID;
failures.add(new ValidationFailureDetailsBuilder().field("id").isSemanticallyIncorrect().errorCode(error.getErrorCode()).becauseOf(error.getMessage(id)).build());
valid = false;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", id, action, failures, valid));
}
return valid;
}
use of org.apache.ranger.plugin.errors.ValidationErrorCode 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;
}
Aggregations