Search in sources :

Example 46 with ModelNode

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

the class ResourceAdapterParser method parseWorkManagerSecurity.

protected WorkManagerSecurity parseWorkManagerSecurity(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException {
    boolean mappingRequired = false;
    String domain = null;
    String defaultPrincipal = null;
    List<String> defaultGroups = null;
    Map<String, String> userMappings = null;
    Map<String, String> groupMappings = null;
    boolean userMappingEnabled = false;
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) {
                        return new WorkManagerSecurityImpl(mappingRequired, domain, false, defaultPrincipal, defaultGroups, userMappings, groupMappings);
                    } else {
                        if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) {
                            throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(WorkManagerSecurity.Tag.forName(reader.getLocalName())) {
                        case DEFAULT_GROUPS:
                        case MAPPINGS:
                            {
                                // Skip
                                break;
                            }
                        case MAPPING_REQUIRED:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DOMAIN:
                            {
                                String value = domain = rawElementText(reader);
                                WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case DEFAULT_PRINCIPAL:
                            {
                                String value = rawElementText(reader);
                                WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader);
                                break;
                            }
                        case GROUP:
                            {
                                String value = rawElementText(reader);
                                operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(WM_SECURITY_DEFAULT_GROUP.parse(value, reader));
                                break;
                            }
                        case USERS:
                            {
                                userMappingEnabled = true;
                                break;
                            }
                        case GROUPS:
                            {
                                userMappingEnabled = false;
                                break;
                            }
                        case MAP:
                            {
                                if (userMappingEnabled) {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object);
                                } else {
                                    String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName());
                                    if (from == null || from.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName()));
                                    String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName());
                                    if (to == null || to.trim().equals(""))
                                        throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName()));
                                    ModelNode object = new ModelNode();
                                    WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader);
                                    WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader);
                                    operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object);
                                }
                                break;
                            }
                        default:
                            throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
                    }
                    break;
                }
        }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) WorkManagerSecurityImpl(org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl) ModelNode(org.jboss.dmr.ModelNode)

Example 47 with ModelNode

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

the class ResourceAdapterResourceDefinition method registerTransformers130.

static void registerTransformers130(ResourceTransformationDescriptionBuilder parentBuilder) {
    ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PathElement.pathElement(RESOURCEADAPTER_NAME)).getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, WM_SECURITY_MAPPING_USER, WM_SECURITY_MAPPING_GROUP, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_USERS, WM_SECURITY_DEFAULT_GROUP, WM_SECURITY_DEFAULT_GROUPS, WM_SECURITY_DEFAULT_PRINCIPAL).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), WM_SECURITY, WM_SECURITY_MAPPING_REQUIRED, STATISTICS_ENABLED).setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode("other")), WM_SECURITY_DOMAIN).setDiscard(DiscardAttributeChecker.UNDEFINED, WM_ELYTRON_SECURITY_DOMAIN).addRejectCheck(RejectAttributeChecker.DEFINED, Constants.MODULE, WM_SECURITY, WM_SECURITY_MAPPING_USER, WM_SECURITY_MAPPING_GROUP, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_USERS, WM_SECURITY_DEFAULT_GROUP, WM_SECURITY_DEFAULT_GROUPS, WM_SECURITY_DEFAULT_PRINCIPAL, WM_SECURITY_MAPPING_REQUIRED, WM_SECURITY_DOMAIN, WM_ELYTRON_SECURITY_DOMAIN, STATISTICS_ENABLED).end();
    ConnectionDefinitionResourceDefinition.registerTransformer130(builder);
}
Also used : ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

Example 48 with ModelNode

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

the class CommonIronJacamarParser method parseAdminObjects.

protected void parseAdminObjects(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap) throws XMLStreamException, ParserException, ValidateException {
    final ModelNode adminObjectNode = new ModelNode();
    adminObjectNode.get(OP).set(ADD);
    int attributeSize = reader.getAttributeCount();
    String poolName = null;
    String jndiName = null;
    for (int i = 0; i < attributeSize; i++) {
        AdminObject.Attribute attribute = AdminObject.Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case ENABLED:
                {
                    String value = rawAttributeText(reader, ENABLED.getXmlName());
                    if (value != null) {
                        ENABLED.parseAndSetParameter(value, adminObjectNode, reader);
                    }
                    break;
                }
            case JNDI_NAME:
                {
                    jndiName = rawAttributeText(reader, JNDINAME.getXmlName());
                    if (jndiName != null) {
                        JNDINAME.parseAndSetParameter(jndiName, adminObjectNode, reader);
                    }
                    break;
                }
            case POOL_NAME:
                {
                    poolName = rawAttributeText(reader, POOL_NAME_NAME);
                    break;
                }
            case USE_JAVA_CONTEXT:
                {
                    String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName());
                    if (value != null) {
                        USE_JAVA_CONTEXT.parseAndSetParameter(value, adminObjectNode, reader);
                    }
                    break;
                }
            case CLASS_NAME:
                {
                    String value = rawAttributeText(reader, CLASS_NAME.getXmlName());
                    if (value != null) {
                        CLASS_NAME.parseAndSetParameter(value, adminObjectNode, reader);
                    }
                    break;
                }
            default:
                throw ParseUtils.unexpectedAttribute(reader, i);
        }
    }
    if (poolName == null || poolName.trim().equals("")) {
        if (jndiName != null && jndiName.trim().length() != 0) {
            if (jndiName.contains("/")) {
                poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1);
            } else {
                poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1);
            }
        } else {
            throw ParseUtils.missingRequired(reader, EnumSet.of(AdminObject.Attribute.JNDI_NAME));
        }
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.ADMIN_OBJECT) {
                        map.put(poolName, adminObjectNode);
                        return;
                    } else {
                        if (AdminObject.Tag.forName(reader.getLocalName()) == AdminObject.Tag.UNKNOWN) {
                            throw ParseUtils.unexpectedEndElement(reader);
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(AdminObject.Tag.forName(reader.getLocalName())) {
                        case CONFIG_PROPERTY:
                            {
                                if (!configMap.containsKey(poolName)) {
                                    configMap.put(poolName, new HashMap<String, ModelNode>(0));
                                }
                                parseConfigProperties(reader, configMap.get(poolName));
                                break;
                            }
                        default:
                            throw ParseUtils.unexpectedElement(reader);
                    }
                    break;
                }
        }
    }
    throw ParseUtils.unexpectedEndElement(reader);
}
Also used : ModelNode(org.jboss.dmr.ModelNode) AdminObject(org.jboss.jca.common.api.metadata.resourceadapter.AdminObject)

Example 49 with ModelNode

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

the class ConfigPropertyAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException {
    final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString();
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String archiveName = path.getElement(path.size() - 2).getValue();
    final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue();
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, configPropertyName);
    ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ConfigPropertiesService service = new ConfigPropertiesService(configPropertyName, configPropertyValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModelNode(org.jboss.dmr.ModelNode)

Example 50 with ModelNode

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

the class ConnectionDefinitionAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = context.getCurrentAddress();
    final String jndiName = JNDINAME.resolveModelAttribute(context, operation).asString();
    final String raName = path.getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.getParent()).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    ModelNode resourceModel = resource.getModel();
    final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
    final boolean elytronRecoveryEnabled = RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
    final ModelNode credentialReference = RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, resourceModel);
    // domains should only be defined when Elytron enabled is undefined or false (default value)
    if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()) && !elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(SECURITY_DOMAIN.getName()) && elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()) && elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()) && !elytronRecoveryEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()) && elytronRecoveryEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    try {
        ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
        ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
        final ModifiableResourceAdapter ravalue = ((ModifiableResourceAdapter) context.getServiceRegistry(false).getService(raServiceName).getValue());
        boolean isXa = ravalue.getTransactionSupport() == TransactionSupportEnum.XATransaction;
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final ConnectionDefinitionService service = new ConnectionDefinitionService();
        service.getConnectionDefinitionSupplierInjector().inject(() -> RaOperationUtil.buildConnectionDefinitionObject(context, resourceModel, poolName, isXa, service.getCredentialSourceSupplier().getOptionalValue()));
        final ServiceBuilder<ModifiableConnDef> cdServiceBuilder = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector());
        // and this should be changed to use a proper capability in the future.
        if (elytronEnabled) {
            if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            } else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT_AND_APPLICATION.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            }
        }
        if (elytronRecoveryEnabled) {
            if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            }
        }
        if (credentialReference.isDefined()) {
            service.getCredentialSourceSupplier().inject(CredentialReference.getCredentialSourceSupplier(context, RECOVERY_CREDENTIAL_REFERENCE, resourceModel, cdServiceBuilder));
        }
        // Install the ConnectionDefinitionService
        cdServiceBuilder.install();
        ServiceRegistry registry = context.getServiceRegistry(true);
        final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
        Activation raxml = (Activation) RaxmlController.getValue();
        ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
        String bootStrapCtxName = DEFAULT_NAME;
        if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
            bootStrapCtxName = raxml.getBootstrapContext();
        }
        ConnectionDefinitionStatisticsService connectionDefinitionStatisticsService = new ConnectionDefinitionStatisticsService(context.getResourceRegistrationForUpdate(), jndiName, poolName, statsEnabled);
        ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), connectionDefinitionStatisticsService);
        statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), connectionDefinitionStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, connectionDefinitionStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
        PathElement peCD = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
        final Resource cdResource = new IronJacamarResource.IronJacamarRuntimeResource();
        resource.registerChild(peCD, cdResource);
        PathElement peExtended = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
        final Resource extendedResource = new IronJacamarResource.IronJacamarRuntimeResource();
        resource.registerChild(peExtended, extendedResource);
    } catch (Exception e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("ConnectionDefinition", operation, e.getLocalizedMessage())));
    }
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ConnectionDefinitionStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ConnectionDefinitionStatisticsService) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

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