From 1318307307d7a223ff4a26c9de87e8924926e1b8 Mon Sep 17 00:00:00 2001 From: Michal Petrov Date: Tue, 23 Nov 2021 12:41:37 +0100 Subject: [PATCH 1/2] WFCORE-4041: fix attribute definitions --- .../org/wildfly/extension/elytron/LdapRealmDefinition.java | 4 +--- .../org/wildfly/extension/elytron/SaslServerDefinitions.java | 1 - .../operations/DomainControllerWriteAttributeHandler.java | 3 --- .../operations/RemoteDomainControllerAddHandler.java | 3 --- .../integration/domain/DomainControllerMigrationTestCase.java | 1 + .../domain/SimpleDomainControllerMigrationTestCase.java | 1 + .../src/test/resources/host-configs/admin-only-discovery.xml | 2 +- .../test/resources/host-configs/admin-only-no-discovery.xml | 2 +- .../resources/host-configs/host-auto-ignore-secondary.xml | 2 +- .../domain/src/test/resources/host-configs/host-failover2.xml | 2 +- .../domain/src/test/resources/host-configs/host-failover3.xml | 2 +- .../domain/src/test/resources/host-configs/host-minimal.xml | 2 +- .../test/resources/host-configs/host-secondary-auto-start.xml | 2 +- .../test/resources/host-configs/host-secondary-cacheddc.xml | 2 +- .../resources/host-configs/host-secondary-config-changes.xml | 2 +- .../host-configs/host-secondary-discovery-options.xml | 2 +- .../host-configs/host-secondary-elytron-no-legacy-realms.xml | 2 +- .../test/resources/host-configs/host-secondary-elytron.xml | 2 +- .../test/resources/host-configs/host-secondary-failure.xml | 2 +- .../host-configs/host-secondary-main-three-without-jvm.xml | 2 +- .../resources/host-configs/host-secondary-rbac-properties.xml | 2 +- .../src/test/resources/host-configs/host-secondary-rbac.xml | 2 +- .../domain/src/test/resources/host-configs/host-secondary.xml | 2 +- .../test/resources/host-configs/host-synchronization-hc1.xml | 2 +- .../test/resources/host-configs/host-synchronization-hc2.xml | 2 +- 25 files changed, 22 insertions(+), 29 deletions(-) diff --git a/elytron/src/main/java/org/wildfly/extension/elytron/LdapRealmDefinition.java b/elytron/src/main/java/org/wildfly/extension/elytron/LdapRealmDefinition.java index 447bfd43a88..2a394f60545 100644 --- a/elytron/src/main/java/org/wildfly/extension/elytron/LdapRealmDefinition.java +++ b/elytron/src/main/java/org/wildfly/extension/elytron/LdapRealmDefinition.java @@ -101,7 +101,6 @@ static class AttributeMappingObjectDefinition { static final SimpleAttributeDefinition RECURSIVE_SEARCH = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.SEARCH_RECURSIVE, ModelType.BOOLEAN, true) .setRequires(ElytronDescriptionConstants.FILTER) - .setDefaultValue(ModelNode.TRUE) .setAllowExpression(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .build(); @@ -312,7 +311,6 @@ static class IdentityMappingObjectDefinition { static final SimpleAttributeDefinition USE_RECURSIVE_SEARCH = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.USE_RECURSIVE_SEARCH, ModelType.BOOLEAN, true) .setRequires(ElytronDescriptionConstants.SEARCH_BASE_DN) - .setDefaultValue(ModelNode.FALSE) .setAllowExpression(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .build(); @@ -497,7 +495,7 @@ private void configureIdentityMapping(OperationContext context, ModelNode model, } ModelNode useRecursiveSearchNode = IdentityMappingObjectDefinition.USE_RECURSIVE_SEARCH.resolveModelAttribute(context, identityMappingNode); - if (useRecursiveSearchNode.asBoolean()) { + if (useRecursiveSearchNode.isDefined() && useRecursiveSearchNode.asBoolean()) { identityMappingBuilder.searchRecursive(); } diff --git a/elytron/src/main/java/org/wildfly/extension/elytron/SaslServerDefinitions.java b/elytron/src/main/java/org/wildfly/extension/elytron/SaslServerDefinitions.java index 23267684e3d..4a5a05e911d 100644 --- a/elytron/src/main/java/org/wildfly/extension/elytron/SaslServerDefinitions.java +++ b/elytron/src/main/java/org/wildfly/extension/elytron/SaslServerDefinitions.java @@ -131,7 +131,6 @@ class SaslServerDefinitions { static final SimpleAttributeDefinition VERSION_COMPARISON = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.VERSION_COMPARISON, ModelType.STRING, false) .setRequired(false) .setAllowExpression(true) - .setDefaultValue(new ModelNode(ElytronDescriptionConstants.LESS_THAN)) .setRequires(ElytronDescriptionConstants.PROVIDER_VERSION) .setAllowedValues(ElytronDescriptionConstants.LESS_THAN, ElytronDescriptionConstants.GREATER_THAN) .setValidator(EnumValidator.create(Comparison.class)) diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/operations/DomainControllerWriteAttributeHandler.java b/host-controller/src/main/java/org/jboss/as/host/controller/operations/DomainControllerWriteAttributeHandler.java index 673dcd118a2..475093371cc 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/operations/DomainControllerWriteAttributeHandler.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/operations/DomainControllerWriteAttributeHandler.java @@ -32,7 +32,6 @@ import org.jboss.as.host.controller.discovery.StaticDiscovery; import org.jboss.as.host.controller.ignored.IgnoredDomainResourceRegistry; import org.jboss.as.host.controller.model.host.AdminOnlyDomainConfigPolicy; -import org.jboss.as.remoting.Protocol; import org.jboss.as.repository.ContentRepository; import org.jboss.as.repository.HostFileRepository; import org.jboss.dmr.ModelNode; @@ -92,8 +91,6 @@ public abstract class DomainControllerWriteAttributeHandler extends ReloadRequir new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.PROTOCOL, ModelType.STRING) .setRequired(false) .setAllowExpression(true) - .setValidator(EnumValidator.create(Protocol.class)) - .setDefaultValue(org.jboss.as.remoting.Protocol.REMOTE.toModelNode()) .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES) .setRequires(ModelDescriptionConstants.HOST, ModelDescriptionConstants.PORT) .build(); diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/operations/RemoteDomainControllerAddHandler.java b/host-controller/src/main/java/org/jboss/as/host/controller/operations/RemoteDomainControllerAddHandler.java index 07f5eb75681..982934c89ca 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/operations/RemoteDomainControllerAddHandler.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/operations/RemoteDomainControllerAddHandler.java @@ -30,7 +30,6 @@ import org.jboss.as.controller.registry.Resource; import org.jboss.as.host.controller.descriptions.HostResolver; import org.jboss.as.host.controller.model.host.AdminOnlyDomainConfigPolicy; -import org.jboss.as.remoting.Protocol; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.wildfly.security.auth.client.AuthenticationContext; @@ -62,8 +61,6 @@ public class RemoteDomainControllerAddHandler implements OperationStepHandler { public static final SimpleAttributeDefinition PROTOCOL = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.PROTOCOL, ModelType.STRING) .setRequired(false) .setAllowExpression(true) - .setValidator(EnumValidator.create(Protocol.class)) - .setDefaultValue(Protocol.REMOTE.toModelNode()) .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES) .setRequires(ModelDescriptionConstants.HOST, ModelDescriptionConstants.PORT) .build(); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java index 9cf704429fb..a6c15854235 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/DomainControllerMigrationTestCase.java @@ -196,6 +196,7 @@ public void testDCFailover() throws Exception { changePrimaryOp.get(ModelDescriptionConstants.OP).set(RemoteDomainControllerAddHandler.OPERATION_NAME); changePrimaryOp.get(ModelDescriptionConstants.HOST).set("${jboss.test.host.secondary.address}"); changePrimaryOp.get(ModelDescriptionConstants.PORT).set(MGMT_PORTS[1]); + changePrimaryOp.get(ModelDescriptionConstants.PROTOCOL).set("remote"); changePrimaryOp.get(ModelDescriptionConstants.AUTHENTICATION_CONTEXT).set("secondaryHostAContext"); hostUtils[2].executeForResult(changePrimaryOp); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java index 251a74a537c..eacaa6f9d2a 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/SimpleDomainControllerMigrationTestCase.java @@ -194,6 +194,7 @@ public void testDCFailover() throws Exception { changePrimaryOp.get(ModelDescriptionConstants.OP).set(RemoteDomainControllerAddHandler.OPERATION_NAME); changePrimaryOp.get(ModelDescriptionConstants.HOST).set("${jboss.test.host.secondary.address}"); changePrimaryOp.get(ModelDescriptionConstants.PORT).set(MGMT_PORTS[1]); + changePrimaryOp.get(ModelDescriptionConstants.PROTOCOL).set("remote"); changePrimaryOp.get(ModelDescriptionConstants.SECURITY_REALM).set("ManagementRealm"); hostUtils[2].executeForResult(changePrimaryOp); diff --git a/testsuite/domain/src/test/resources/host-configs/admin-only-discovery.xml b/testsuite/domain/src/test/resources/host-configs/admin-only-discovery.xml index 019c4222866..bf93638c639 100644 --- a/testsuite/domain/src/test/resources/host-configs/admin-only-discovery.xml +++ b/testsuite/domain/src/test/resources/host-configs/admin-only-discovery.xml @@ -27,7 +27,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/admin-only-no-discovery.xml b/testsuite/domain/src/test/resources/host-configs/admin-only-no-discovery.xml index edbc603e980..149e8bdac6f 100644 --- a/testsuite/domain/src/test/resources/host-configs/admin-only-no-discovery.xml +++ b/testsuite/domain/src/test/resources/host-configs/admin-only-no-discovery.xml @@ -25,7 +25,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-auto-ignore-secondary.xml b/testsuite/domain/src/test/resources/host-configs/host-auto-ignore-secondary.xml index c170b7dd793..2564bc57039 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-auto-ignore-secondary.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-auto-ignore-secondary.xml @@ -30,7 +30,7 @@ - + - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-auto-start.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-auto-start.xml index ce81cfcba8f..caeb29d5240 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-auto-start.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-auto-start.xml @@ -49,7 +49,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-cacheddc.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-cacheddc.xml index 867089f0a6b..d2629c67923 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-cacheddc.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-cacheddc.xml @@ -30,7 +30,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-config-changes.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-config-changes.xml index af3cb83acd3..64ee06beffc 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-config-changes.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-config-changes.xml @@ -51,7 +51,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-discovery-options.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-discovery-options.xml index 0ee2261c508..57f5a306336 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-discovery-options.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-discovery-options.xml @@ -64,7 +64,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron-no-legacy-realms.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron-no-legacy-realms.xml index c48397b6535..be113365c64 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron-no-legacy-realms.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron-no-legacy-realms.xml @@ -49,7 +49,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron.xml index f558fa694e0..e37d339c8ab 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-elytron.xml @@ -39,7 +39,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-failure.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-failure.xml index 225109c2f89..552432b56e2 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-failure.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-failure.xml @@ -49,7 +49,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-main-three-without-jvm.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-main-three-without-jvm.xml index 1450a08f3a1..88dee93ea6e 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-main-three-without-jvm.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-main-three-without-jvm.xml @@ -50,7 +50,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac-properties.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac-properties.xml index 386df8a72d9..1783abbe70c 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac-properties.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac-properties.xml @@ -49,7 +49,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac.xml index 934ff373190..ea02bd17ecd 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary-rbac.xml @@ -49,7 +49,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-secondary.xml b/testsuite/domain/src/test/resources/host-configs/host-secondary.xml index 3a7c7dd4122..a5190467e64 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-secondary.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-secondary.xml @@ -51,7 +51,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc1.xml b/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc1.xml index ae11809a778..985c442052a 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc1.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc1.xml @@ -22,7 +22,7 @@ - + diff --git a/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc2.xml b/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc2.xml index dc9a62bbd02..ad5c981abb1 100644 --- a/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc2.xml +++ b/testsuite/domain/src/test/resources/host-configs/host-synchronization-hc2.xml @@ -22,7 +22,7 @@ - + From 100215f1e9a4d357b50c9ae2a598af369f3e63b2 Mon Sep 17 00:00:00 2001 From: Michal Petrov Date: Thu, 2 Apr 2020 17:44:24 +0200 Subject: [PATCH 2/2] WFCORE-4041: supply default values for nested attributes --- .../aesh/cmd/security/model/ElytronUtil.java | 4 +-- .../controller/ValidateModelStepHandler.java | 11 +++--- .../as/controller/operations/common/Util.java | 7 ++++ .../global/AbstractCollectionHandler.java | 2 +- .../global/ReadAttributeHandler.java | 36 +++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/cli/src/main/java/org/jboss/as/cli/impl/aesh/cmd/security/model/ElytronUtil.java b/cli/src/main/java/org/jboss/as/cli/impl/aesh/cmd/security/model/ElytronUtil.java index 8c51b590ad7..5121e2b1a05 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/aesh/cmd/security/model/ElytronUtil.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/aesh/cmd/security/model/ElytronUtil.java @@ -745,9 +745,7 @@ private static ModelNode buildUsersResource(PropertiesRealmConfiguration config) mn.get(Util.RELATIVE_TO).set(config.getRelativeTo()); } mn.get(Util.DIGEST_REALM_NAME).set(config.getExposedRealmName()); - if (config.getPlainText()) { - mn.get(Util.PLAIN_TEXT).set(config.getPlainText()); - } + mn.get(Util.PLAIN_TEXT).set(config.getPlainText()); return mn; } diff --git a/controller/src/main/java/org/jboss/as/controller/ValidateModelStepHandler.java b/controller/src/main/java/org/jboss/as/controller/ValidateModelStepHandler.java index ef8a70c2b0c..57c209ce6d5 100644 --- a/controller/src/main/java/org/jboss/as/controller/ValidateModelStepHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/ValidateModelStepHandler.java @@ -223,11 +223,12 @@ private void validateNestedAttributes(final ModelNode subModel, final ObjectType return; } - final Set keys = subModel.keys(); - final Set definedKeys = new HashSet<>(keys.size()); - for (String key : keys) { - if (subModel.hasDefined(key)) { - definedKeys.add(key); + // only top-level model contains all keys, we have to retrieve keys from the description + final AttributeDefinition[] keys = attr.getValueTypes(); + final Set definedKeys = new HashSet<>(keys.length); + for (AttributeDefinition key : keys) { + if (subModel.hasDefined(key.getName()) || key.getDefaultValue() != null) { + definedKeys.add(key.getName()); } } AttributeDefinition[] subAttrs = attr.getValueTypes(); diff --git a/controller/src/main/java/org/jboss/as/controller/operations/common/Util.java b/controller/src/main/java/org/jboss/as/controller/operations/common/Util.java index f191da994e1..72d82ef5d79 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/common/Util.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/common/Util.java @@ -9,6 +9,7 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.COMPOSITE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDE_DEFAULTS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; @@ -161,6 +162,12 @@ public static ModelNode getReadAttributeOperation(final PathAddress address, Str return createAttributeOperation(READ_ATTRIBUTE_OPERATION, address, attributeName); } + public static ModelNode getReadAttributeOperation(final PathAddress address, String attributeName, boolean includeDefaults) { + ModelNode op = getReadAttributeOperation(address, attributeName); + op.get(INCLUDE_DEFAULTS).set(includeDefaults); + return op; + } + public static ModelNode getReadResourceDescriptionOperation(final PathAddress address) { ModelNode op = createEmptyOperation(READ_RESOURCE_DESCRIPTION_OPERATION, address); return op; diff --git a/controller/src/main/java/org/jboss/as/controller/operations/global/AbstractCollectionHandler.java b/controller/src/main/java/org/jboss/as/controller/operations/global/AbstractCollectionHandler.java index 80c3189327e..266b26cbeff 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/global/AbstractCollectionHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/global/AbstractCollectionHandler.java @@ -99,7 +99,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat }, OperationContext.Stage.MODEL, true); // 1. read current attribute value - ModelNode readAttributeOperation = Util.getReadAttributeOperation(address, useEnhancedSyntax ? attributeExpression : attributeName); + ModelNode readAttributeOperation = Util.getReadAttributeOperation(address, useEnhancedSyntax ? attributeExpression : attributeName, false); context.addStep(readResponse, readAttributeOperation, ReadAttributeHandler.INSTANCE, OperationContext.Stage.MODEL, true); } else { assert attributeAccess.getStorageType() == AttributeAccess.Storage.RUNTIME; diff --git a/controller/src/main/java/org/jboss/as/controller/operations/global/ReadAttributeHandler.java b/controller/src/main/java/org/jboss/as/controller/operations/global/ReadAttributeHandler.java index 0e0f5addc07..51be88929c5 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/global/ReadAttributeHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/global/ReadAttributeHandler.java @@ -15,6 +15,9 @@ import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.ExpressionResolver; +import org.jboss.as.controller.ObjectListAttributeDefinition; +import org.jboss.as.controller.ObjectMapAttributeDefinition; +import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.OperationFailedException; @@ -276,6 +279,9 @@ static void resolveAttribute(OperationContext context, AttributeDefinition attri } else if (subModel.hasDefined(attribute.getName())) { final ModelNode result = subModel.get(attribute.getName()); context.getResult().set(result); + if (defaults) { + handleObjectAttributes(context.getResult(), attribute); + } } else if (defaults && attribute.getDefaultValue() != null) { // No defined value in the model. See if we should reply with a default from the metadata, // reply with undefined, or fail because it's a non-existent attribute name @@ -287,6 +293,36 @@ static void resolveAttribute(OperationContext context, AttributeDefinition attri } } + private static void handleObjectAttributes(ModelNode model, AttributeDefinition attribute) { + if (attribute instanceof ObjectTypeAttributeDefinition) { + readNestedDefaults(model, (ObjectTypeAttributeDefinition) attribute); + } else if (attribute instanceof ObjectListAttributeDefinition) { + ObjectTypeAttributeDefinition valueType = ((ObjectListAttributeDefinition) attribute).getValueType(); + for (int i = 0; i < model.asInt(); i++) { + readNestedDefaults(model.get(i), valueType); + } + } else if (attribute instanceof ObjectMapAttributeDefinition) { + ObjectTypeAttributeDefinition valueType = ((ObjectMapAttributeDefinition) attribute).getValueType(); + for (String key : model.keys()) { + readNestedDefaults(model.get(key), valueType); + } + } + } + + private static void readNestedDefaults(ModelNode model, ObjectTypeAttributeDefinition attribute) { + for (AttributeDefinition subAttribute : attribute.getValueTypes()) { + ModelNode defaultValue = subAttribute.getDefaultValue(); + String subAttrName = subAttribute.getName(); + if (defaultValue != null && !model.hasDefined(subAttrName)) { + model.get(subAttrName).set(defaultValue); + } + + if (model.hasDefined(subAttrName)) { + handleObjectAttributes(model.get(subAttrName), subAttribute); + } + } + } + private static class Validator extends ParametersValidator { private static final Validator RESOLVABLE = new Validator(true);