private static DescribedOp getDescribedOp( OperationContext context, String operationName, ModelNode operation, boolean lenient) throws OperationFailedException { DescribedOp result = null; OperationEntry operationEntry; // First try to get the current resource registration to give authz a chance to reject this // request ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); if (registry != null) { operationEntry = registry.getOperationEntry(PathAddress.EMPTY_ADDRESS, operationName); } else { // We know the user is authorized to read this address. // There's no MRR at that address, but see if the MRR tree can resolve an operation entry // (e.g. an inherited one) operationEntry = context .getRootResourceRegistration() .getOperationEntry(context.getCurrentAddress(), operationName); } if (operationEntry != null) { Locale locale = GlobalOperationHandlers.getLocale(context, operation); result = new DescribedOp(operationEntry, locale); } else if (lenient) { // For wildcard elements, check specific registrations where the same OSH is used // for all such registrations PathAddress address = context.getCurrentAddress(); if (address.size() > 0) { PathElement pe = address.getLastElement(); if (pe.isWildcard()) { ImmutableManagementResourceRegistration rootRegistration = context.getRootResourceRegistration(); String type = pe.getKey(); PathAddress parent = address.subAddress(0, address.size() - 1); Set<PathElement> children = rootRegistration.getChildAddresses(parent); if (children != null) { Locale locale = GlobalOperationHandlers.getLocale(context, operation); DescribedOp found = null; for (PathElement child : children) { if (type.equals(child.getKey())) { OperationEntry oe = rootRegistration.getOperationEntry(parent.append(child), operationName); DescribedOp describedOp = oe == null ? null : new DescribedOp(oe, locale); if (describedOp == null || (found != null && !found.equals(describedOp))) { // Not all children have the same handler; give up found = null; break; } // We have a candidate OSH found = describedOp; } } result = found; } } } } return result; }
protected void populateModel( final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { if (requiresRuntime(context)) { final DeploymentScannerService scannerService = new DeploymentScannerService(config); ModelNode op = scannerService.prepareDeploymentModel(); final ModelNode result = new ModelNode(); final PathAddress opPath = PathAddress.pathAddress(op.get(OP_ADDR)); final OperationStepHandler handler = context.getRootResourceRegistration().getOperationHandler(opPath, op.get(OP).asString()); context.addStep(result, op, handler, OperationContext.Stage.MODEL); } }