Search in sources :

Example 1 with Security

use of org.jboss.as.connector.metadata.api.common.Security 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)

Example 2 with Security

use of org.jboss.as.connector.metadata.api.common.Security in project wildfly by wildfly.

the class IronJacamarResourceCreator method addConnectionDefinition.

private void addConnectionDefinition(final Resource parent, ConnectionDefinition connDef) {
    final Resource connDefResource = new IronJacamarResource.IronJacamarRuntimeResource();
    final ModelNode model = connDefResource.getModel();
    setAttribute(model, Constants.JNDINAME, connDef.getJndiName());
    if (connDef.getConfigProperties() != null) {
        for (Map.Entry<String, String> config : connDef.getConfigProperties().entrySet()) {
            addConfigProperties(connDefResource, config.getKey(), config.getValue());
        }
    }
    setAttribute(model, CLASS_NAME, connDef.getClassName());
    setAttribute(model, JNDINAME, connDef.getJndiName());
    setAttribute(model, USE_JAVA_CONTEXT, connDef.isUseJavaContext());
    setAttribute(model, ENABLED, connDef.isEnabled());
    setAttribute(model, CONNECTABLE, connDef.isConnectable());
    if (connDef.isTracking() != null) {
        setAttribute(model, TRACKING, connDef.isTracking());
    }
    setAttribute(model, USE_CCM, connDef.isUseCcm());
    setAttribute(model, SHARABLE, connDef.isSharable());
    setAttribute(model, ENLISTMENT, connDef.isEnlistment());
    final Pool pool = connDef.getPool();
    if (pool != null) {
        setAttribute(model, MAX_POOL_SIZE, pool.getMaxPoolSize());
        setAttribute(model, MIN_POOL_SIZE, pool.getMinPoolSize());
        setAttribute(model, INITIAL_POOL_SIZE, pool.getInitialPoolSize());
        if (pool.getCapacity() != null) {
            if (pool.getCapacity().getIncrementer() != null) {
                setAttribute(model, CAPACITY_INCREMENTER_CLASS, pool.getCapacity().getIncrementer().getClassName());
                if (pool.getCapacity().getIncrementer().getConfigPropertiesMap() != null) {
                    for (Map.Entry<String, String> config : pool.getCapacity().getIncrementer().getConfigPropertiesMap().entrySet()) {
                        model.get(CAPACITY_INCREMENTER_PROPERTIES.getName(), config.getKey()).set(config.getValue());
                    }
                }
            }
            if (pool.getCapacity().getDecrementer() != null) {
                setAttribute(model, CAPACITY_DECREMENTER_CLASS, pool.getCapacity().getDecrementer().getClassName());
                if (pool.getCapacity().getDecrementer().getConfigPropertiesMap() != null) {
                    for (Map.Entry<String, String> config : pool.getCapacity().getDecrementer().getConfigPropertiesMap().entrySet()) {
                        model.get(CAPACITY_DECREMENTER_PROPERTIES.getName(), config.getKey()).set(config.getValue());
                    }
                }
            }
        }
        setAttribute(model, POOL_USE_STRICT_MIN, pool.isUseStrictMin());
        if (pool.getFlushStrategy() != null)
            setAttribute(model, POOL_FLUSH_STRATEGY, pool.getFlushStrategy().name());
        setAttribute(model, POOL_PREFILL, pool.isPrefill());
        setAttribute(model, POOL_FAIR, pool.isFair());
        if (connDef.isXa()) {
            assert connDef.getPool() instanceof XaPool;
            XaPool xaPool = (XaPool) connDef.getPool();
            setAttribute(model, WRAP_XA_RESOURCE, xaPool.isWrapXaResource());
            setAttribute(model, SAME_RM_OVERRIDE, xaPool.isSameRmOverride());
            setAttribute(model, PAD_XID, xaPool.isPadXid());
            setAttribute(model, INTERLEAVING, xaPool.isInterleaving());
            setAttribute(model, NOTXSEPARATEPOOL, xaPool.isNoTxSeparatePool());
        }
    }
    final Security security = (Security) connDef.getSecurity();
    if (security != null) {
        setAttribute(model, APPLICATION, security.isApplication());
        if (security.isElytronEnabled()) {
            setAttribute(model, ELYTRON_ENABLED, true);
            setAttribute(model, AUTHENTICATION_CONTEXT, security.getSecurityDomain());
            setAttribute(model, AUTHENTICATION_CONTEXT_AND_APPLICATION, security.getSecurityDomainAndApplication());
        } else {
            setAttribute(model, SECURITY_DOMAIN, security.getSecurityDomain());
            setAttribute(model, SECURITY_DOMAIN_AND_APPLICATION, security.getSecurityDomainAndApplication());
        }
    }
    final TimeOut timeOut = connDef.getTimeOut();
    if (timeOut != null) {
        setAttribute(model, ALLOCATION_RETRY, timeOut.getAllocationRetry());
        setAttribute(model, ALLOCATION_RETRY_WAIT_MILLIS, timeOut.getAllocationRetryWaitMillis());
        setAttribute(model, BLOCKING_TIMEOUT_WAIT_MILLIS, timeOut.getBlockingTimeoutMillis());
        setAttribute(model, IDLETIMEOUTMINUTES, timeOut.getIdleTimeoutMinutes());
        setAttribute(model, XA_RESOURCE_TIMEOUT, timeOut.getXaResourceTimeout());
    }
    final Validation validation = connDef.getValidation();
    if (validation != null) {
        setAttribute(model, BACKGROUNDVALIDATIONMILLIS, validation.getBackgroundValidationMillis());
        setAttribute(model, BACKGROUNDVALIDATION, validation.isBackgroundValidation());
        setAttribute(model, USE_FAST_FAIL, validation.isUseFastFail());
        setAttribute(model, VALIDATE_ON_MATCH, validation.isValidateOnMatch());
    }
    final Recovery recovery = connDef.getRecovery();
    if (recovery != null) {
        setAttribute(model, NO_RECOVERY, recovery.getNoRecovery());
        final Extension recoverPlugin = recovery.getRecoverPlugin();
        if (recoverPlugin != null) {
            setAttribute(model, RECOVERLUGIN_CLASSNAME, recoverPlugin.getClassName());
            if (recoverPlugin.getConfigPropertiesMap() != null) {
                for (Map.Entry<String, String> config : recoverPlugin.getConfigPropertiesMap().entrySet()) {
                    model.get(RECOVERLUGIN_PROPERTIES.getName(), config.getKey()).set(config.getValue());
                }
            }
        }
        final Credential recoveryCredential = (Credential) recovery.getCredential();
        if (recoveryCredential != null) {
            setAttribute(model, RECOVERY_PASSWORD, recoveryCredential.getPassword());
            if (recoveryCredential.isElytronEnabled()) {
                setAttribute(model, RECOVERY_ELYTRON_ENABLED, true);
                setAttribute(model, RECOVERY_AUTHENTICATION_CONTEXT, recoveryCredential.getSecurityDomain());
            } else {
                setAttribute(model, RECOVERY_SECURITY_DOMAIN, recoveryCredential.getSecurityDomain());
            }
            setAttribute(model, RECOVERY_USERNAME, recoveryCredential.getUserName());
        }
    }
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    connDefResource.registerChild(PathElement.pathElement(Constants.STATISTICS_NAME, "local"), statsResource);
    final PathElement element = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME, connDef.getJndiName());
    parent.registerChild(element, connDefResource);
}
Also used : Validation(org.jboss.jca.common.api.metadata.common.Validation) XaPool(org.jboss.jca.common.api.metadata.common.XaPool) Credential(org.jboss.as.connector.metadata.api.common.Credential) TimeOut(org.jboss.jca.common.api.metadata.common.TimeOut) Resource(org.jboss.as.controller.registry.Resource) WorkManagerSecurity(org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) Security(org.jboss.as.connector.metadata.api.common.Security) Recovery(org.jboss.jca.common.api.metadata.common.Recovery) Extension(org.jboss.jca.common.api.metadata.common.Extension) PathElement(org.jboss.as.controller.PathElement) XaPool(org.jboss.jca.common.api.metadata.common.XaPool) Pool(org.jboss.jca.common.api.metadata.common.Pool) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Aggregations

Map (java.util.Map)2 Security (org.jboss.as.connector.metadata.api.common.Security)2 Pool (org.jboss.jca.common.api.metadata.common.Pool)2 HashMap (java.util.HashMap)1 Credential (org.jboss.as.connector.metadata.api.common.Credential)1 WorkManagerSecurity (org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity)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 PathElement (org.jboss.as.controller.PathElement)1 Resource (org.jboss.as.controller.registry.Resource)1 ModelNode (org.jboss.dmr.ModelNode)1 Extension (org.jboss.jca.common.api.metadata.common.Extension)1 Recovery (org.jboss.jca.common.api.metadata.common.Recovery)1 TimeOut (org.jboss.jca.common.api.metadata.common.TimeOut)1 TransactionSupportEnum (org.jboss.jca.common.api.metadata.common.TransactionSupportEnum)1 Validation (org.jboss.jca.common.api.metadata.common.Validation)1 XaPool (org.jboss.jca.common.api.metadata.common.XaPool)1 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)1 ConnectionDefinition (org.jboss.jca.common.api.metadata.spec.ConnectionDefinition)1