Search in sources :

Example 1 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebCERTTestsSecurityDomainSetup method tearDown.

@Override
public void tearDown(ManagementClient managementClient, String containerId) {
    try {
        final List<ModelNode> updates = new ArrayList<ModelNode>();
        // remove the security domains.
        ModelNode op = new ModelNode();
        op.get(OP).set(REMOVE);
        op.get(OP_ADDR).add(SUBSYSTEM, "security");
        op.get(OP_ADDR).add(Constants.SECURITY_DOMAIN, APP_SECURITY_DOMAIN);
        // Don't rollback when the AS detects the war needs the module
        op.get(OPERATION_HEADERS, ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE).set(false);
        op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        updates.add(op);
        // remove the HTTPS connector and the socket binding.
        op = new ModelNode();
        op.get(OP).set(REMOVE);
        op.get(OP_ADDR).add(SUBSYSTEM, "undertow");
        op.get(OP_ADDR).add("server", "default-server");
        op.get(OP_ADDR).add("https-listener", "testConnector");
        op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        updates.add(op);
        op = new ModelNode();
        op.get(OP).set(REMOVE);
        op.get(OP_ADDR).add("socket-binding-group", "standard-sockets");
        op.get(OP_ADDR).add("socket-binding", "https-test");
        op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        updates.add(op);
        applyUpdates(managementClient.getControllerClient(), updates);
        ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient());
        super.tearDown(managementClient, containerId);
    } catch (Exception e) {
        log.error("Failed to clean domain setup.", e);
    }
}
Also used : ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class WebCERTTestsSecurityDomainSetup method setup.

@Override
public void setup(ManagementClient managementClient, String containerId) {
    try {
        super.setup(managementClient, containerId);
        log.debug("start of the domain creation");
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        URL keystore = tccl.getResource("security/jsse.keystore");
        URL roles = getClass().getResource("cert/roles.properties");
        final List<ModelNode> updates = new ArrayList<ModelNode>();
        final ModelNode compositeOp = new ModelNode();
        compositeOp.get(OP).set(COMPOSITE);
        compositeOp.get(OP_ADDR).setEmptyList();
        final ModelNode domainSteps = compositeOp.get(STEPS);
        PathAddress address = PathAddress.pathAddress().append(SUBSYSTEM, "security").append(SECURITY_DOMAIN, APP_SECURITY_DOMAIN);
        domainSteps.add(Util.createAddOperation(address));
        address = address.append(Constants.AUTHENTICATION, Constants.CLASSIC);
        domainSteps.add(Util.createAddOperation(address));
        ModelNode loginModule = Util.createAddOperation(address.append(LOGIN_MODULE, "CertificateRoles"));
        loginModule.get(CODE).set("CertificateRoles");
        loginModule.get(FLAG).set("required");
        ModelNode moduleOptions = loginModule.get(MODULE_OPTIONS);
        moduleOptions.add("securityDomain", APP_SECURITY_DOMAIN);
        moduleOptions.add("rolesProperties", roles.getPath());
        //loginModule.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        domainSteps.add(loginModule);
        // Add the JSSE security domain.
        address = PathAddress.pathAddress().append(SUBSYSTEM, "security").append(SECURITY_DOMAIN, APP_SECURITY_DOMAIN);
        ModelNode op = Util.createAddOperation(address.append(JSSE, Constants.CLASSIC));
        op.get(TRUSTSTORE, PASSWORD).set("changeit");
        op.get(TRUSTSTORE, URL).set(keystore.getPath());
        //op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        domainSteps.add(op);
        updates.add(compositeOp);
        // Add the HTTPS socket binding.
        op = new ModelNode();
        op.get(OP).set(ADD);
        op.get(OP_ADDR).add("socket-binding-group", "standard-sockets");
        op.get(OP_ADDR).add("socket-binding", "https-test");
        op.get("interface").set("public");
        op.get("port").set(8380);
        updates.add(op);
        // Add the HTTPS connector.
        final ModelNode composite = Util.getEmptyOperation(COMPOSITE, new ModelNode());
        final ModelNode steps = composite.get(STEPS);
        op = new ModelNode();
        op.get(OP).set(ADD);
        op.get(OP_ADDR).add(SUBSYSTEM, "undertow");
        op.get(OP_ADDR).add("server", "default-server");
        op.get(OP_ADDR).add("https-listener", "testConnector");
        op.get("socket-binding").set("https-test");
        op.get("enabled").set(true);
        /*
             * op.get("protocol").set("HTTP/1.1"); op.get("scheme").set("https");
             */
        /* op.get("secure").set(true); */
        op.get("security-realm").set("ssl-cert-realm");
        op.get("verify-client").set("REQUIRED");
        steps.add(op);
        updates.add(composite);
        applyUpdates(managementClient.getControllerClient(), updates);
        log.debug("end of the domain creation");
        ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient());
    } catch (Exception e) {
        log.error("Failed to setup domain creation.", e);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) URL(java.net.URL) URL(org.jboss.as.security.Constants.URL)

Example 3 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class EjbSecurityDomainSetup method setup.

@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
    final ModelNode compositeOp = new ModelNode();
    compositeOp.get(OP).set(COMPOSITE);
    compositeOp.get(OP_ADDR).setEmptyList();
    ModelNode steps = compositeOp.get(STEPS);
    PathAddress securityDomainAddress = PathAddress.pathAddress().append(SUBSYSTEM, "security").append(SECURITY_DOMAIN, getSecurityDomainName());
    steps.add(Util.createAddOperation(securityDomainAddress));
    PathAddress authAddress = securityDomainAddress.append(AUTHENTICATION, Constants.CLASSIC);
    steps.add(Util.createAddOperation(authAddress));
    ModelNode op = Util.createAddOperation(authAddress.append(Constants.LOGIN_MODULE, "Remoting"));
    op.get(CODE).set("Remoting");
    if (isUsersRolesRequired()) {
        op.get(FLAG).set("optional");
    } else {
        op.get(FLAG).set("required");
    }
    op.get(Constants.MODULE_OPTIONS).add("password-stacking", "useFirstPass");
    steps.add(op);
    if (isUsersRolesRequired()) {
        ModelNode loginModule = Util.createAddOperation(authAddress.append(Constants.LOGIN_MODULE, "UsersRoles"));
        loginModule.get(CODE).set("UsersRoles");
        loginModule.get(FLAG).set("required");
        loginModule.get(Constants.MODULE_OPTIONS).add("password-stacking", "useFirstPass");
        loginModule.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        steps.add(loginModule);
    }
    applyUpdates(managementClient.getControllerClient(), Arrays.asList(compositeOp));
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 4 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class ManagementResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    for (final String statisticName : statistics.getNames()) {
        final ModelType modelType = getModelType(statistics.getType(statisticName));
        if (statistics.isOperation(statisticName)) {
            AttributeDefinition attributeDefinition = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            OperationStepHandler operationHandler = new AbstractMetricsHandler() {

                @Override
                void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                    Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                    if (result != null) {
                        setResponse(response, result, modelType);
                    }
                }
            };
            SimpleOperationDefinition definition = new SimpleOperationDefinition(statisticName, descriptionResolver, attributeDefinition);
            resourceRegistration.registerOperationHandler(definition, operationHandler);
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ModelType(org.jboss.dmr.ModelType) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinition(org.jboss.as.controller.SimpleOperationDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Example 5 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class ManagementResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (final String statisticName : statistics.getNames()) {
        final ModelType modelType = getModelType(statistics.getType(statisticName));
        final SimpleAttributeDefinitionBuilder simpleAttributeDefinitionBuilder = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME);
        if (statistics.isAttribute(statisticName)) {
            // WFLY-561 improves usability by using "statistics-enabled" instead of "enabled"
            if (ENABLED_ATTRIBUTE.equals(statisticName)) {
                simpleAttributeDefinitionBuilder.setDeprecated(ENABLED_ATTRIBUTE_DEPRECATED_MODEL_VERSION);
            }
            OperationStepHandler readHandler = new AbstractMetricsHandler() {

                @Override
                void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                    Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                    if (result != null) {
                        setResponse(response, result, modelType);
                    }
                }
            };
            // handle writeable attributes
            if (statistics.isWriteable(statisticName)) {
                OperationStepHandler writeHandler = new AbstractMetricsHandler() {

                    @Override
                    void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
                        Object oldSetting = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                        {
                            final ModelNode value = operation.get(ModelDescriptionConstants.VALUE).resolve();
                            if (Boolean.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asBoolean(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else if (Integer.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asInt(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else if (Long.class.equals(statistics.getType(statisticName))) {
                                statistics.setValue(statisticName, value.asLong(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            } else {
                                statistics.setValue(statisticName, value.asString(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            }
                        }
                        final Object rollBackValue = oldSetting;
                        context.completeStep(new OperationContext.RollbackHandler() {

                            @Override
                            public void handleRollback(OperationContext context, ModelNode operation) {
                                statistics.setValue(statisticName, rollBackValue, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
                            }
                        });
                    }
                };
                resourceRegistration.registerReadWriteAttribute(simpleAttributeDefinitionBuilder.build(), readHandler, writeHandler);
            } else {
                resourceRegistration.registerMetric(simpleAttributeDefinitionBuilder.build(), readHandler);
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1634 PathAddress (org.jboss.as.controller.PathAddress)351 Test (org.junit.Test)344 KernelServices (org.jboss.as.subsystem.test.KernelServices)102 Property (org.jboss.dmr.Property)92 OperationFailedException (org.jboss.as.controller.OperationFailedException)89 OperationContext (org.jboss.as.controller.OperationContext)68 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)68 ArrayList (java.util.ArrayList)58 Resource (org.jboss.as.controller.registry.Resource)54 PathElement (org.jboss.as.controller.PathElement)53 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)52 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)50 IOException (java.io.IOException)49 ServiceName (org.jboss.msc.service.ServiceName)49 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)47 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)44 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)42 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)42 Map (java.util.Map)38