Search in sources :

Example 71 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class SAMLResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
            if (serviceController != null) {
                SAMLService service = serviceController.getValue();
                ModelNode samlNode;
                if (!rollback) {
                    samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    samlNode = rc.getModel();
                }
                service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Example 72 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class ElementMaxOccurrenceValidationStepHandler method validateOccurrence.

protected void validateOccurrence(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    PathAddress parentAddress = Util.getParentAddressByKey(address, this.parentElement.getName());
    Resource parentResource = context.readResourceFromRoot(parentAddress);
    Set<String> elements = parentResource.getChildrenNames(this.element.getName());
    if (elements.size() > this.maxOccurs) {
        throw ROOT_LOGGER.invalidChildTypeOccurrence(parentAddress.getLastElement().toString(), this.maxOccurs, this.element.getName());
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 73 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class RequiredChildValidationStepHandler method validateRequiredChild.

protected void validateRequiredChild(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    Set<ResourceEntry> children = resource.getChildren(this.childElement.getName());
    if (children.isEmpty()) {
        throw ROOT_LOGGER.requiredChild(pathAddress.getLastElement().toString(), this.childElement.getName());
    }
}
Also used : ResourceEntry(org.jboss.as.controller.registry.Resource.ResourceEntry) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 74 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class UniqueTypeValidationStepHandler method validateType.

protected void validateType(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String elementName = pathAddress.getLastElement().getValue();
    ModelNode typeNode = context.readResource(EMPTY_ADDRESS, false).getModel();
    String type = getType(context, typeNode);
    PathAddress parentAddress = pathAddress.subAddress(0, pathAddress.size() - 1);
    Resource parentResource = context.readResourceFromRoot(parentAddress);
    Set<Resource.ResourceEntry> children = parentResource.getChildren(this.element.getName());
    for (Resource.ResourceEntry child : children) {
        String existingResourceName = child.getName();
        String existingType = getType(context, child.getModel());
        if (!elementName.equals(existingResourceName) && (type.equals(existingType))) {
            throw ROOT_LOGGER.typeAlreadyDefined(type);
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 75 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
            if (serviceController != null) {
                KeyStoreProviderService service = serviceController.getValue();
                ModelNode keyStoreProviderNode;
                if (!rollback) {
                    keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    keyStoreProviderNode = rc.getModel();
                }
                ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
                String relativeTo = null;
                if (relativeToNode.isDefined()) {
                    relativeTo = relativeToNode.asString();
                }
                String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
                service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) KeyStoreProviderService(org.wildfly.extension.picketlink.federation.service.KeyStoreProviderService)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4