Search in sources :

Example 1 with ConnectionDefinition

use of org.jboss.jca.common.api.metadata.spec.ConnectionDefinition in project wildfly by wildfly.

the class DirectConnectionFactoryActivatorService method start.

@Override
public void start(org.jboss.msc.service.StartContext context) throws org.jboss.msc.service.StartException {
    ROOT_LOGGER.debugf("started DirectConnectionFactoryActivatorService %s", context.getController().getName());
    String cfInterface = null;
    try {
        Connector cmd = mdr.getValue().getResourceAdapter(raId);
        ResourceAdapter ra = cmd.getResourceadapter();
        if (ra.getOutboundResourceadapter() != null) {
            for (ConnectionDefinition cd : ra.getOutboundResourceadapter().getConnectionDefinitions()) {
                if (cd.getConnectionFactoryInterface().getValue().equals(interfaceName))
                    cfInterface = cd.getConnectionFactoryInterface().getValue();
            }
        }
        if (cfInterface == null || !cfInterface.equals(interfaceName)) {
            throw ConnectorLogger.ROOT_LOGGER.invalidConnectionFactory(cfInterface, resourceAdapter, jndiName);
        }
        Map<String, String> raConfigProperties = new HashMap<String, String>();
        Map<String, String> mcfConfigProperties = new HashMap<String, String>();
        String securitySetting = null;
        String securitySettingDomain = null;
        boolean elytronEnabled = false;
        if (properties != null) {
            for (Map.Entry<String, String> prop : properties.entrySet()) {
                String key = prop.getKey();
                String value = prop.getValue();
                if (key.equals("ironjacamar.security")) {
                    securitySetting = value;
                } else if (key.equals("ironjacamar.security.elytron") && value.equals("true")) {
                    elytronEnabled = true;
                } else if (key.equals("ironjacamar.security.elytron-authentication-context")) {
                    securitySettingDomain = value;
                    elytronEnabled = true;
                } else if (key.equals("ironjacamar.security.domain")) {
                    securitySettingDomain = value;
                } else {
                    if (key.startsWith("ra.")) {
                        raConfigProperties.put(key.substring(3), value);
                    } else if (key.startsWith("mcf.")) {
                        mcfConfigProperties.put(key.substring(4), value);
                    } else {
                        mcfConfigProperties.put(key, value);
                    }
                }
            }
        }
        String mcfClass = null;
        if (ra.getOutboundResourceadapter() != null) {
            for (ConnectionDefinition cd : ra.getOutboundResourceadapter().getConnectionDefinitions()) {
                if (cd.getConnectionFactoryInterface().getValue().equals(cfInterface))
                    mcfClass = cd.getManagedConnectionFactoryClass().getValue();
            }
        }
        Security security = null;
        if (securitySetting != null) {
            if ("".equals(securitySetting)) {
                security = new SecurityImpl(null, null, false, false);
            } else if ("application".equals(securitySetting)) {
                security = new SecurityImpl(null, null, true, false);
            } else if ("domain".equals(securitySetting) && securitySettingDomain != null) {
                security = new SecurityImpl(securitySettingDomain, null, false, elytronEnabled);
            } else if ("domain-and-application".equals(securitySetting) && securitySettingDomain != null) {
                security = new SecurityImpl(null, securitySettingDomain, false, elytronEnabled);
            }
        }
        if (security == null) {
            SUBSYSTEM_RA_LOGGER.noSecurityDefined(jndiName);
        }
        Pool pool = null;
        Boolean isXA = Boolean.FALSE;
        if (transactionSupport == TransactionSupport.TransactionSupportLevel.XATransaction) {
            pool = new XaPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : minPoolSize, Defaults.INITIAL_POOL_SIZE, maxPoolSize < 0 ? Defaults.MAX_POOL_SIZE : maxPoolSize, Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, null, Defaults.FAIR, Defaults.IS_SAME_RM_OVERRIDE, Defaults.INTERLEAVING, Defaults.PAD_XID, Defaults.WRAP_XA_RESOURCE, Defaults.NO_TX_SEPARATE_POOL);
            isXA = Boolean.TRUE;
        } else {
            pool = new PoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : minPoolSize, Defaults.INITIAL_POOL_SIZE, maxPoolSize < 0 ? Defaults.MAX_POOL_SIZE : maxPoolSize, Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, null, Defaults.FAIR);
        }
        TransactionSupportEnum transactionSupportValue = TransactionSupportEnum.NoTransaction;
        if (transactionSupport == TransactionSupport.TransactionSupportLevel.XATransaction) {
            transactionSupportValue = TransactionSupportEnum.XATransaction;
        } else if (transactionSupport == TransactionSupport.TransactionSupportLevel.LocalTransaction) {
            transactionSupportValue = TransactionSupportEnum.LocalTransaction;
        }
        org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition cd = new org.jboss.jca.common.metadata.resourceadapter.ConnectionDefinitionImpl(mcfConfigProperties, mcfClass, jndiName, poolName(cfInterface), Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Defaults.CONNECTABLE, Defaults.TRACKING, Defaults.MCP, Defaults.ENLISTMENT_TRACE, pool, null, null, security, null, isXA);
        Activation activation = new ActivationImpl(null, null, transactionSupportValue, Collections.singletonList(cd), Collections.<AdminObject>emptyList(), raConfigProperties, Collections.<String>emptyList(), null, null);
        String serviceName = jndiName;
        serviceName = serviceName.replace(':', '_');
        serviceName = serviceName.replace('/', '_');
        ResourceAdapterActivatorService activator = new ResourceAdapterActivatorService(cmd, activation, module.getClassLoader(), serviceName);
        activator.setCreateBinderService(false);
        activator.setBindInfo(bindInfo);
        org.jboss.msc.service.ServiceTarget serviceTarget = context.getChildTarget();
        org.jboss.msc.service.ServiceName activatorServiceName = ConnectorServices.RESOURCE_ADAPTER_ACTIVATOR_SERVICE.append(serviceName);
        org.jboss.msc.service.ServiceBuilder connectionFactoryServiceBuilder = serviceTarget.addService(activatorServiceName, activator).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, activator.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, activator.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, activator.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, activator.getRegistryInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, activator.getConfigInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, activator.getCcmInjector()).addDependency(NamingService.SERVICE_NAME).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, activator.getTxIntegrationInjector()).addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default"));
        if (ActivationSecurityUtil.isLegacySecurityRequired(security)) {
            connectionFactoryServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, activator.getSubjectFactoryInjector()).addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, activator.getServerSecurityManager());
        }
        connectionFactoryServiceBuilder.setInitialMode(org.jboss.msc.service.ServiceController.Mode.ACTIVE).install();
    } catch (Exception e) {
        throw new org.jboss.msc.service.StartException(e);
    }
}
Also used : Connector(org.jboss.jca.common.api.metadata.spec.Connector) ConnectionDefinition(org.jboss.jca.common.api.metadata.spec.ConnectionDefinition) SubjectFactory(org.jboss.security.SubjectFactory) HashMap(java.util.HashMap) JcaSubsystemConfiguration(org.jboss.as.connector.subsystems.jca.JcaSubsystemConfiguration) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) Security(org.jboss.as.connector.metadata.api.common.Security) XaPoolImpl(org.jboss.jca.common.metadata.common.XaPoolImpl) PoolImpl(org.jboss.jca.common.metadata.common.PoolImpl) SecurityImpl(org.jboss.as.connector.metadata.common.SecurityImpl) ActivationImpl(org.jboss.jca.common.metadata.resourceadapter.ActivationImpl) XaPoolImpl(org.jboss.jca.common.metadata.common.XaPoolImpl) ResourceAdapter(org.jboss.jca.common.api.metadata.spec.ResourceAdapter) Pool(org.jboss.jca.common.api.metadata.common.Pool) AS7MetadataRepository(org.jboss.as.connector.services.mdr.AS7MetadataRepository) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) TransactionSupportEnum(org.jboss.jca.common.api.metadata.common.TransactionSupportEnum) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Security (org.jboss.as.connector.metadata.api.common.Security)1 SecurityImpl (org.jboss.as.connector.metadata.common.SecurityImpl)1 AS7MetadataRepository (org.jboss.as.connector.services.mdr.AS7MetadataRepository)1 JcaSubsystemConfiguration (org.jboss.as.connector.subsystems.jca.JcaSubsystemConfiguration)1 Pool (org.jboss.jca.common.api.metadata.common.Pool)1 TransactionSupportEnum (org.jboss.jca.common.api.metadata.common.TransactionSupportEnum)1 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)1 ConnectionDefinition (org.jboss.jca.common.api.metadata.spec.ConnectionDefinition)1 Connector (org.jboss.jca.common.api.metadata.spec.Connector)1 ResourceAdapter (org.jboss.jca.common.api.metadata.spec.ResourceAdapter)1 PoolImpl (org.jboss.jca.common.metadata.common.PoolImpl)1 XaPoolImpl (org.jboss.jca.common.metadata.common.XaPoolImpl)1 ActivationImpl (org.jboss.jca.common.metadata.resourceadapter.ActivationImpl)1 ManagementRepository (org.jboss.jca.core.api.management.ManagementRepository)1 SubjectFactory (org.jboss.security.SubjectFactory)1