/** * Validates the operation against the description providers in the model controller * * @param operation the operation to validate */ @Override public void validateOperation(ModelNode operation) { operationValidator.validateOperation(operation); }
throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.noOperationEntry(name, address)); throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.noOperationHandler(name, address)); final DescriptionProvider provider = getDescriptionProvider(operation); final ModelNode description = provider.getModelDescription(null); final Map<String, ModelNode> describedProperties = getDescribedRequestProperties(operation, description); final Map<String, ModelNode> actualParams = getActualRequestProperties(operation); checkActualOperationParamsAreDescribed(operation, describedProperties, actualParams); checkAllRequiredPropertiesArePresent(description, operation, describedProperties, actualParams); checkParameterTypes(description, operation, describedProperties, actualParams);
private void checkParameterTypes(final ModelNode description, final ModelNode operation, final Map<String, ModelNode> describedProperties, final Map<String, ModelNode> actualParams) { for (String paramName : actualParams.keySet()) { final ModelNode value = actualParams.get(paramName); if(!value.isDefined()) { continue; } if(value.getType() == ModelType.OBJECT && value.keys().isEmpty()) { return; } final ModelNode typeNode = describedProperties.get(paramName).get(TYPE); if (!typeNode.isDefined()) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionNoParamTypeInDescription(paramName, getPathAddress(operation), description)); return; } final ModelType modelType; try { modelType = Enum.valueOf(ModelType.class, typeNode.asString()); } catch (Exception e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionInvalidParamTypeInDescription(paramName, getPathAddress(operation), description)); return; } try { checkType(modelType, value); } catch (IllegalArgumentException e) { throw MESSAGES.validationFailedCouldNotConvertParamToType(paramName, modelType, formatOperationForMessage(operation)); } checkRange(operation, description, paramName, modelType, describedProperties.get(paramName), value); checkList(operation, paramName, modelType, describedProperties.get(paramName), value); } }
private DescriptionProvider getDescriptionProvider(final ModelNode operation) { if (!operation.hasDefined(OP)) { throw MESSAGES.validationFailedOperationHasNoField(OP, formatOperationForMessage(operation)); } if (!operation.hasDefined(OP_ADDR)) { throw MESSAGES.validationFailedOperationHasNoField(OP_ADDR, formatOperationForMessage(operation)); } final String name = operation.get(OP).asString(); if (name == null || name.trim().length() == 0) { throw MESSAGES.validationFailedOperationHasANullOrEmptyName(formatOperationForMessage(operation)); } final PathAddress addr = getPathAddress(operation); final DescriptionProvider provider = root.getOperationDescription(addr, name); if (provider == null) { throw MESSAGES.validationFailedNoOperationFound(name, addr, formatOperationForMessage(operation)); } return provider; }
@Override protected boolean boot(List<ModelNode> bootOperations, boolean rollbackOnRuntimeFailure) throws ConfigurationPersistenceException { try { preBoot(bootOperations, rollbackOnRuntimeFailure); // See what we need to validate, but defer doing it to after super.boot to allow // initModel to run first and given tests a chance to set things up List<ModelNode> validationList = new ArrayList<>(); for (ModelNode op : bootOperations) { ModelNode toValidate = validateOpsFilter.adjustForValidation(op.clone()); if (toValidate != null) { validationList.add(toValidate); } } bootSuccess = super.boot(persister.getBootOperations(), rollbackOnRuntimeFailure); // Ok, now we can validate OperationValidator validator = new OperationValidator(rootRegistration); for (ModelNode op : validationList) { validator.validateOperation(op); } return bootSuccess; } catch (Exception e) { error = e; } catch (Throwable t) { error = new Exception(t); } finally { postBoot(); } return false; }
if (described.hasDefined(REQUIRED)) { if (ModelType.BOOLEAN != described.get(REQUIRED).getType()) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.invalidDescriptionRequiredFlagIsNotABoolean(paramName, getPathAddress(operation), description)); required = false; } else { final String alternative = hasAlternative(actualParams.keySet(), alternatives); final boolean alternativeExist = alternative != null && actualParams.get(alternative).isDefined(); if (required) { if(!exist && !alternativeExist) { throw ControllerLogger.ROOT_LOGGER.validationFailedRequiredParameterNotPresent(paramName, formatOperationForMessage(operation)); throw ControllerLogger.ROOT_LOGGER.validationFailedRequiredParameterPresentAsWellAsAlternative(alternative, paramName, formatOperationForMessage(operation));
min = describedProperty.get(MIN).asBigDecimal(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.BIG_DECIMAL, getPathAddress(operation), description)); return; throw ControllerLogger.ROOT_LOGGER.validationFailedValueIsSmallerThanMin(value.asBigDecimal(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asBigInteger(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.BIG_INTEGER, getPathAddress(operation), description)); return; throw ControllerLogger.ROOT_LOGGER.validationFailedValueIsSmallerThanMin(value.asBigInteger(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asDouble(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.DOUBLE, getPathAddress(operation), description)); return; throw ControllerLogger.ROOT_LOGGER.validationFailedValueIsSmallerThanMin(value.asDouble(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asInt(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(ControllerLogger.ROOT_LOGGER.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.INT, getPathAddress(operation), description)); return; throw ControllerLogger.ROOT_LOGGER.validationFailedValueIsSmallerThanMin(value.asInt(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asLong();
new OperationValidator(svc.getRootRegistration()), mainSubsystemName, controllerExtensionRegistry, legacyModelVersion, svc.isSuccessfulBoot(), svc.getBootError(), registerTransformers) : new LegacyKernelServicesImpl(container, svc, persister, svc.getRootRegistration(), new OperationValidator(svc.getRootRegistration()), mainSubsystemName, controllerExtensionRegistry, legacyModelVersion, svc.isSuccessfulBoot(), svc.getBootError(), registerTransformers);
private void checkList(final ModelNode operation, final String paramName, final ModelNode describedProperty, final ModelNode value) { if (describedProperty.get(TYPE).asType() == ModelType.LIST) { if (describedProperty.hasDefined(VALUE_TYPE) && describedProperty.get(VALUE_TYPE).getType() == ModelType.TYPE) { ModelType elementType = describedProperty.get(VALUE_TYPE).asType(); for (ModelNode element : value.asList()) { try { checkType(elementType, element); } catch (IllegalArgumentException e) { throw ControllerLogger.ROOT_LOGGER.validationFailedInvalidElementType(paramName, elementType, formatOperationForMessage(operation)); } } } } }
private void checkActualOperationParamsAreDescribed(final ModelNode description, final ModelNode operation, final Map<String, ModelNode> describedProperties, final Map<String, ModelNode> actualParams) { for (String paramName : actualParams.keySet()) { final ModelNode param = actualParams.get(paramName); if(! param.isDefined()) { continue; } if(param.getType() == ModelType.OBJECT && param.keys().isEmpty()) { return; } if (!describedProperties.containsKey(paramName)) { throw MESSAGES.validationFailedActualParameterNotDescribed(paramName, describedProperties.keySet(), formatOperationForMessage(operation)); } } }
} else { try { new OperationValidator(context.getResourceRegistration(), false, false).validateOperation(op); } catch (IllegalArgumentException e) { context.getFailureDescription().set(e.getMessage());
if (described.hasDefined(REQUIRED)) { if (ModelType.BOOLEAN != described.get(REQUIRED).getType()) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionRequiredFlagIsNotABoolean(paramName, getPathAddress(operation), description)); required = false; } else { final String alternative = hasAlternative(actualParams.keySet(), alternatives); final boolean alternativeExist = alternative != null && actualParams.get(alternative).isDefined(); if (required) { if(!exist && !alternativeExist) { throw MESSAGES.validationFailedRequiredParameterNotPresent(paramName, formatOperationForMessage(operation)); throw MESSAGES.validationFailedRequiredParameterPresentAsWellAsAlternative(alternative, paramName, formatOperationForMessage(operation));
min = describedProperty.get(MIN).asBigDecimal(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.BIG_DECIMAL, getPathAddress(operation), description)); return; throw MESSAGES.validationFailedValueIsSmallerThanMin(value.asBigDecimal(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asBigInteger(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.BIG_INTEGER, getPathAddress(operation), description)); return; throw MESSAGES.validationFailedValueIsSmallerThanMin(value.asBigInteger(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asDouble(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.DOUBLE, getPathAddress(operation), description)); return; throw MESSAGES.validationFailedValueIsSmallerThanMin(value.asDouble(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asInt(); } catch (IllegalArgumentException e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionMinMaxForParameterHasWrongType(MIN, paramName, ModelType.INT, getPathAddress(operation), description)); return; throw MESSAGES.validationFailedValueIsSmallerThanMin(value.asInt(), paramName, min, formatOperationForMessage(operation)); min = describedProperty.get(MIN).asLong();
new OperationValidator(svc.getRootRegistration()), legacyModelVersion, svc.isSuccessfulBoot(), svc.getBootError(), extensionRegistry) : new LegacyKernelServicesImpl(container, svc, persister, svc.getRootRegistration(), new OperationValidator(svc.getRootRegistration()), legacyModelVersion, svc.isSuccessfulBoot(), svc.getBootError(), extensionRegistry, ContentRepository.Factory.create(repositoryFile));
private void checkList(final ModelNode operation, final String paramName, final ModelType modelType, final ModelNode describedProperty, final ModelNode value) { if (describedProperty.get(TYPE).asType() == ModelType.LIST) { if (describedProperty.hasDefined(VALUE_TYPE) && describedProperty.get(VALUE_TYPE).getType() == ModelType.TYPE) { ModelType elementType = describedProperty.get(VALUE_TYPE).asType(); for (ModelNode element : value.asList()) { try { checkType(elementType, element); } catch (IllegalArgumentException e) { throw MESSAGES.validationFailedInvalidElementType(paramName, elementType, formatOperationForMessage(operation)); } } } } }
private DescriptionProvider getDescriptionProvider(final ModelNode operation) { if (!operation.hasDefined(OP)) { throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasNoField(OP, formatOperationForMessage(operation)); } if (!operation.hasDefined(OP_ADDR)) { throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasNoField(OP_ADDR, formatOperationForMessage(operation)); } final String name = operation.get(OP).asString(); if (name == null || name.trim().length() == 0) { throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasANullOrEmptyName(formatOperationForMessage(operation)); } final PathAddress addr = getPathAddress(operation); final DescriptionProvider provider = root.getOperationDescription(addr, name); if (provider == null) { throw ControllerLogger.ROOT_LOGGER.validationFailedNoOperationFound(name, addr, formatOperationForMessage(operation)); } return provider; }
private void checkActualOperationParamsAreDescribed(final ModelNode operation, final Map<String, ModelNode> describedProperties, final Map<String, ModelNode> actualParams) { for (String paramName : actualParams.keySet()) { final ModelNode param = actualParams.get(paramName); if(! param.isDefined()) { continue; } if(param.getType() == ModelType.OBJECT && param.keys().isEmpty()) { return; } if (!describedProperties.containsKey(paramName)) { throw ControllerLogger.ROOT_LOGGER.validationFailedActualParameterNotDescribed(paramName, describedProperties.keySet(), formatOperationForMessage(operation)); } } }
throwOrWarnAboutDescriptorProblem(MESSAGES.noOperationEntry(name, address)); throwOrWarnAboutDescriptorProblem(MESSAGES.noOperationHandler(name, address)); final DescriptionProvider provider = getDescriptionProvider(operation); final ModelNode description = provider.getModelDescription(null); final Map<String, ModelNode> describedProperties = getDescribedRequestProperties(operation, description); final Map<String, ModelNode> actualParams = getActualRequestProperties(operation); checkActualOperationParamsAreDescribed(description, operation, describedProperties, actualParams); checkAllRequiredPropertiesArePresent(description, operation, describedProperties, actualParams); checkParameterTypes(description, operation, describedProperties, actualParams);
private void checkParameterTypes(final ModelNode description, final ModelNode operation, final Map<String, ModelNode> describedProperties, final Map<String, ModelNode> actualParams) { for (String paramName : actualParams.keySet()) { final ModelNode value = actualParams.get(paramName); if(!value.isDefined()) { continue; } if(value.getType() == ModelType.OBJECT && value.keys().isEmpty()) { return; } final ModelNode typeNode = describedProperties.get(paramName).get(TYPE); if (!typeNode.isDefined()) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionNoParamTypeInDescription(paramName, getPathAddress(operation), description)); return; } final ModelType modelType; try { modelType = Enum.valueOf(ModelType.class, typeNode.asString()); } catch (Exception e) { throwOrWarnAboutDescriptorProblem(MESSAGES.invalidDescriptionInvalidParamTypeInDescription(paramName, getPathAddress(operation), description)); return; } try { checkType(modelType, value); } catch (IllegalArgumentException e) { throw MESSAGES.validationFailedCouldNotConvertParamToType(paramName, modelType, formatOperationForMessage(operation)); } checkRange(operation, description, paramName, modelType, describedProperties.get(paramName), value); checkList(operation, paramName, modelType, describedProperties.get(paramName), value); } }
context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.managementResourceNotFoundMessage(addr)); } else { new OperationValidator(context, context.getResourceRegistration(), false, false, true).validateOperation(op);