Search in sources :

Example 1 with PathAddress

use of org.jboss.as.controller.PathAddress 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 2 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class IIOPExtension method registerTransformers.

protected static void registerTransformers(final SubsystemRegistration subsystem) {
    ChainedTransformationDescriptionBuilder chained = ResourceTransformationDescriptionBuilder.Factory.createChainedSubystemInstance(CURRENT_MODEL_VERSION);
    ResourceTransformationDescriptionBuilder builder = chained.createBuilder(CURRENT_MODEL_VERSION, VERSION_1);
    builder.getAttributeBuilder().addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.SERVER_SSL_CONTEXT).addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.CLIENT_SSL_CONTEXT).addRejectCheck(RejectAttributeChecker.DEFINED, IIOPRootDefinition.AUTHENTICATION_CONTEXT).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        protected boolean rejectAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            return attributeValue.asString().equals("true");
        }

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> map) {
            return IIOPLogger.ROOT_LOGGER.serverRequiresSslNotSupportedInPreviousVersions();
        }
    }, IIOPRootDefinition.SERVER_REQUIRES_SSL).addRejectCheck(new RejectAttributeChecker.DefaultRejectAttributeChecker() {

        @Override
        protected boolean rejectAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            return attributeValue.asString().equalsIgnoreCase(Constants.ELYTRON);
        }

        @Override
        public String getRejectionLogMessage(Map<String, ModelNode> map) {
            return IIOPLogger.ROOT_LOGGER.elytronInitializerNotSupportedInPreviousVersions();
        }
    }, IIOPRootDefinition.SECURITY).setValueConverter(new AttributeConverter() {

        @Override
        public void convertOperationParameter(PathAddress pathAddress, String s, ModelNode attributeValue, ModelNode operation, TransformationContext transformationContext) {
            convert(attributeValue);
        }

        @Override
        public void convertResourceAttribute(PathAddress pathAddress, String s, ModelNode attributeValue, TransformationContext transformationContext) {
            convert(attributeValue);
        }

        private void convert(ModelNode attributeValue) {
            final boolean clientRequiresSsl = attributeValue.asBoolean();
            if (clientRequiresSsl) {
                attributeValue.set(SSLConfigValue.MUTUALAUTH.toString());
            } else {
                attributeValue.set(SSLConfigValue.NONE.toString());
            }
        }
    }, IIOPRootDefinition.CLIENT_REQUIRES_SSL);
    chained.buildAndRegister(subsystem, new ModelVersion[] { VERSION_1 });
}
Also used : ChainedTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder) TransformationContext(org.jboss.as.controller.transform.TransformationContext) AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) RejectAttributeChecker(org.jboss.as.controller.transform.description.RejectAttributeChecker) Map(java.util.Map)

Example 3 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class ChainedOperationTransformer method transformOperation.

/**
     * {@inheritDoc}
     */
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode originalOperation) throws OperationFailedException {
    String originalName = Operations.getName(originalOperation);
    PathAddress originalAddress = Operations.getPathAddress(originalOperation);
    Deque<ModelNode> preSteps = new LinkedList<>();
    Deque<ModelNode> postSteps = new LinkedList<>();
    ModelNode operation = originalOperation;
    for (OperationTransformer transformer : this.transformers) {
        operation = transformer.transformOperation(context, address, operation).getTransformedOperation();
        // If the transformed operation is a composite operation, locate the modified operation and record any pre/post operations
        if (this.collate && operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.COMPOSITE)) {
            List<ModelNode> stepList = operation.get(ModelDescriptionConstants.STEPS).asList();
            ListIterator<ModelNode> steps = stepList.listIterator();
            while (steps.hasNext()) {
                ModelNode step = steps.next();
                String operationName = Operations.getName(step);
                PathAddress operationAddress = Operations.getPathAddress(step);
                if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
                    operation = step;
                    break;
                }
                preSteps.addLast(step);
            }
            steps = stepList.listIterator(stepList.size());
            while (steps.hasPrevious()) {
                ModelNode step = steps.previous();
                String operationName = Operations.getName(step);
                PathAddress operationAddress = Operations.getPathAddress(step);
                if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
                    break;
                }
                postSteps.addFirst(step);
            }
        }
    }
    if (this.collate) {
        int count = preSteps.size() + postSteps.size() + 1;
        // If there are any pre or post steps, we need a composite operation
        if (count > 1) {
            List<ModelNode> steps = new ArrayList<>(count);
            steps.addAll(preSteps);
            steps.add(operation);
            steps.addAll(postSteps);
            operation = Operations.createCompositeOperation(steps);
        }
    }
    return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) LinkedList(java.util.LinkedList)

Example 4 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class LegacyPropertyAddOperationTransformer method transformOperation.

@Override
public ModelNode transformOperation(ModelNode operation) {
    if (operation.hasDefined(PROPERTIES)) {
        final ModelNode addOp = operation.clone();
        final ModelNode properties = addOp.remove(PROPERTIES);
        final ModelNode composite = new ModelNode();
        composite.get(OP).set(COMPOSITE);
        composite.get(OP_ADDR).setEmptyList();
        composite.get(STEPS).add(addOp);
        // Handle odd jgroups-specific legacy case, where :add operation for the protocol is :add-protocol on the parent
        PathAddress propertyAddress = Operations.getName(addOp).equals("add-protocol") ? Operations.getPathAddress(addOp).append("protocol", addOp.get("type").asString()) : Operations.getPathAddress(addOp);
        for (final Property property : properties.asPropertyList()) {
            String key = property.getName();
            ModelNode value = property.getValue();
            ModelNode propAddOp = Util.createAddOperation(propertyAddress.append(PathElement.pathElement(PROPERTY, key)));
            propAddOp.get(VALUE).set(value);
            composite.get(STEPS).add(propAddOp);
        }
        return composite;
    }
    return operation;
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 5 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class LegacyPropertyResourceTransformer method transformPropertiesToChildrenResources.

public static void transformPropertiesToChildrenResources(ModelNode properties, PathAddress address, ResourceTransformationContext parentContext) {
    if (properties.isDefined()) {
        for (final Property property : properties.asPropertyList()) {
            String key = property.getName();
            ModelNode value = property.getValue();
            Resource propertyResource = Resource.Factory.create();
            propertyResource.getModel().get(VALUE).set(value);
            PathAddress absoluteAddress = address.append(PROPERTY, key);
            parentContext.addTransformedResourceFromRoot(absoluteAddress, propertyResource);
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)644 ModelNode (org.jboss.dmr.ModelNode)492 Resource (org.jboss.as.controller.registry.Resource)70 Test (org.junit.Test)66 PathElement (org.jboss.as.controller.PathElement)63 KernelServices (org.jboss.as.subsystem.test.KernelServices)51 ServiceName (org.jboss.msc.service.ServiceName)51 OperationFailedException (org.jboss.as.controller.OperationFailedException)43 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)35 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)35 FailedOperationTransformationConfig (org.jboss.as.model.test.FailedOperationTransformationConfig)34 KernelServicesBuilder (org.jboss.as.subsystem.test.KernelServicesBuilder)33 ServiceTarget (org.jboss.msc.service.ServiceTarget)32 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)31 Map (java.util.Map)30 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)29 IOException (java.io.IOException)28 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)26 ArrayList (java.util.ArrayList)25 OperationContext (org.jboss.as.controller.OperationContext)23