Search in sources :

Example 26 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class EJBDefaultSecurityDomainProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
    if (eeModuleDescription == null) {
        return;
    }
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    if (componentDescriptions == null || componentDescriptions.isEmpty()) {
        return;
    }
    final String defaultSecurityDomain;
    if (eeModuleDescription.getDefaultSecurityDomain() == null) {
        defaultSecurityDomain = this.defaultSecurityDomainName;
    } else {
        defaultSecurityDomain = eeModuleDescription.getDefaultSecurityDomain();
    }
    String knownSecurityDomainName = null;
    boolean gotKnownSecurityDomain = false;
    for (ComponentDescription componentDescription : componentDescriptions) {
        if (componentDescription instanceof EJBComponentDescription) {
            EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
            ejbComponentDescription.setDefaultSecurityDomain(defaultSecurityDomain);
            ejbComponentDescription.setKnownSecurityDomainFunction(knownSecurityDomain);
            ejbComponentDescription.setOutflowSecurityDomainsConfigured(outflowSecurityDomainsConfigured);
            // Ensure the EJB components within a deployment are associated with at most one Elytron security domain
            if (ejbComponentDescription.isSecurityDomainKnown()) {
                if (!gotKnownSecurityDomain) {
                    knownSecurityDomainName = ejbComponentDescription.getSecurityDomain();
                    gotKnownSecurityDomain = true;
                } else if (!knownSecurityDomainName.equals(ejbComponentDescription.getSecurityDomain())) {
                    throw EjbLogger.ROOT_LOGGER.multipleSecurityDomainsDetected();
                }
            }
        }
    }
    // If this EJB deployment is associated with an Elytron security domain, set up the security domain mapping
    if (knownSecurityDomainName != null && !knownSecurityDomainName.isEmpty()) {
        final EJBSecurityDomainService ejbSecurityDomainService = new EJBSecurityDomainService(deploymentUnit);
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
        ServiceName serviceName = deploymentUnit.getServiceName().append(EJBSecurityDomainService.SERVICE_NAME);
        final ServiceBuilder<Void> builder = phaseContext.getServiceTarget().addService(serviceName, ejbSecurityDomainService).addDependency(support.getCapabilityServiceName(ApplicationSecurityDomainDefinition.APPLICATION_SECURITY_DOMAIN_CAPABILITY, knownSecurityDomainName), ApplicationSecurityDomain.class, ejbSecurityDomainService.getApplicationSecurityDomainInjector());
        builder.install();
        for (final ComponentDescription componentDescription : componentDescriptions) {
            if (componentDescription instanceof EJBComponentDescription) {
                componentDescription.getConfigurators().add((context, description, configuration) -> configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(serviceName)));
            }
        }
    }
}
Also used : CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) EE_MODULE_DESCRIPTION(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Collection(java.util.Collection) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) Function(java.util.function.Function) ApplicationSecurityDomainConfig(org.jboss.as.ejb3.security.ApplicationSecurityDomainConfig) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) BooleanSupplier(java.util.function.BooleanSupplier) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBSecurityDomainService(org.jboss.as.ejb3.deployment.EJBSecurityDomainService) ApplicationSecurityDomainDefinition(org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainDefinition) EjbLogger(org.jboss.as.ejb3.logging.EjbLogger) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnitProcessor(org.jboss.as.server.deployment.DeploymentUnitProcessor) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ApplicationSecurityDomain(org.jboss.as.ejb3.subsystem.ApplicationSecurityDomainService.ApplicationSecurityDomain) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) EJBSecurityDomainService(org.jboss.as.ejb3.deployment.EJBSecurityDomainService) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 27 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class EJBComponentDescription method addTransactionManagerDependencies.

/**
     * Sets up a {@link ComponentConfigurator} which then sets up the relevant dependencies on the transaction manager services for the {@link EJBComponentCreateService}
     */
protected void addTransactionManagerDependencies() {
    this.getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration componentConfiguration) throws DeploymentUnitProcessingException {
            componentConfiguration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final EJBComponentCreateService ejbComponentCreateService) throws DeploymentUnitProcessingException {
                    // add dependency on transaction manager
                    serviceBuilder.addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER, TransactionManager.class, ejbComponentCreateService.getTransactionManagerInjector());
                    // add dependency on UserTransaction
                    serviceBuilder.addDependency(TxnServices.JBOSS_TXN_USER_TRANSACTION, UserTransaction.class, ejbComponentCreateService.getUserTransactionInjector());
                    // add dependency on TransactionSynchronizationRegistry
                    serviceBuilder.addDependency(TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY, TransactionSynchronizationRegistry.class, ejbComponentCreateService.getTransactionSynchronizationRegistryInjector());
                }
            });
        }
    });
}
Also used : ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 28 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class RemotingProfileAdd method installServices.

protected void installServices(final OperationContext context, final PathAddress address, final ModelNode profileNode) throws OperationFailedException {
    try {
        final String profileName = address.getLastElement().getValue();
        final ServiceName profileServiceName = RemotingProfileService.BASE_SERVICE_NAME.append(profileName);
        final ModelNode staticEjbDiscoery = StaticEJBDiscoveryDefinition.INSTANCE.resolveModelAttribute(context, profileNode);
        List<StaticEJBDiscoveryDefinition.StaticEjbDiscovery> discoveryList = StaticEJBDiscoveryDefinition.createStaticEjbList(context, staticEjbDiscoery);
        final List<ServiceURL> urls = new ArrayList<>();
        for (StaticEJBDiscoveryDefinition.StaticEjbDiscovery resource : discoveryList) {
            ServiceURL.Builder builder = new ServiceURL.Builder();
            builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss").setUri(new URI(resource.getUrl()));
            String distinctName = resource.getDistinct() == null ? "" : resource.getDistinct();
            String appName = resource.getApp() == null ? "" : resource.getApp();
            String moduleName = resource.getModule();
            if (distinctName.isEmpty()) {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + "/" + moduleName));
                }
            } else {
                if (appName.isEmpty()) {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + "/" + distinctName));
                } else {
                    builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + "/" + moduleName + "/" + distinctName));
                }
            }
            urls.add(builder.create());
        }
        final Map<String, RemotingProfileService.ConnectionSpec> map = new HashMap<>();
        final RemotingProfileService profileService = new RemotingProfileService(urls, map);
        // populating the map after the fact is cheating, but it works thanks to the MSC start service "fence"
        final ServiceBuilder<RemotingProfileService> builder = context.getServiceTarget().addService(profileServiceName, profileService);
        if (profileNode.hasDefined(EJB3SubsystemModel.REMOTING_EJB_RECEIVER)) {
            for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTING_EJB_RECEIVER).asPropertyList()) {
                final ModelNode receiverNode = receiverProperty.getValue();
                final String connectionRef = RemotingEjbReceiverDefinition.OUTBOUND_CONNECTION_REF.resolveModelAttribute(context, receiverNode).asString();
                final long timeout = RemotingEjbReceiverDefinition.CONNECT_TIMEOUT.resolveModelAttribute(context, receiverNode).asLong();
                final ServiceName connectionDependencyService = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef);
                final InjectedValue<AbstractOutboundConnectionService> connectionInjector = new InjectedValue<AbstractOutboundConnectionService>();
                builder.addDependency(connectionDependencyService, AbstractOutboundConnectionService.class, connectionInjector);
                final ModelNode channelCreationOptionsNode = receiverNode.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
                OptionMap channelCreationOptions = createChannelOptionMap(context, channelCreationOptionsNode);
                map.put(connectionRef, new RemotingProfileService.ConnectionSpec(connectionRef, connectionInjector, channelCreationOptions, timeout));
            }
        }
        final boolean isLocalReceiverExcluded = RemotingProfileResourceDefinition.EXCLUDE_LOCAL_RECEIVER.resolveModelAttribute(context, profileNode).asBoolean();
        // service
        if (!isLocalReceiverExcluded) {
            final ModelNode passByValueNode = RemotingProfileResourceDefinition.LOCAL_RECEIVER_PASS_BY_VALUE.resolveModelAttribute(context, profileNode);
            if (passByValueNode.isDefined()) {
                final ServiceName localTransportProviderServiceName = passByValueNode.asBoolean() == true ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
                builder.addDependency(localTransportProviderServiceName, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            } else {
                // setup a dependency on the default local ejb receiver service configured at the subsystem level
                builder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            }
        }
        builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (IllegalArgumentException | URISyntaxException e) {
        throw new OperationFailedException(e.getLocalizedMessage());
    }
}
Also used : AbstractOutboundConnectionService(org.jboss.as.remoting.AbstractOutboundConnectionService) InjectedValue(org.jboss.msc.value.InjectedValue) HashMap(java.util.HashMap) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ServiceURL(org.wildfly.discovery.ServiceURL) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) Property(org.jboss.dmr.Property) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Example 29 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronKeyStoreResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible key store that can be exported by a JSSE-enabled domain
     * in the legacy security subsystem.
     *
     * To export the key store the resource uses a {@code BasicAddHandler} implementation that registers the elytron key-store
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to obtain a {@code JSSESecurityDomain}. If such domain is found, its configured key
     * store is obtained and returned.
     *
     * The {@code ValueSupplier} implementation throws an exception if the referenced legacy domain is not a JSSE-enabled
     * domain or if the domain doesn't contain a key store configuration.
     */
public static ResourceDefinition getElytronKeyStoreResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JSSE_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<KeyStore>(attributes, KEY_STORE_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<KeyStore> getValueSupplier(ServiceBuilder<KeyStore> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJSSEConfig = asStringIfDefined(context, LEGACY_JSSE_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJSSEConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJSSEConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                final JSSESecurityDomain jsseDomain = domainContext.getJSSE();
                if (jsseDomain == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateJSSEConfig(legacyJSSEConfig);
                }
                final KeyStore keyStore = jsseDomain.getKeyStore();
                if (keyStore == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateComponentInJSSEDomain("key store", legacyJSSEConfig);
                }
                return keyStore;
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_KEY_STORE, addHandler, attributes, KEY_STORE_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) JSSESecurityDomain(org.jboss.security.JSSESecurityDomain) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) KeyStore(java.security.KeyStore) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 30 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronRealmResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible realm that can be exported by the legacy security subsystem.
     * The constructed {@code SecurityRealm} wraps a legacy {@code SecurityDomainContext} and delegates authentication
     * decisions to that context.
     *
     * To export the realm the resource uses a {@code BasicAddHandler} implementation that registers the security-realm
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to create and return an instance of {@code SecurityDomainContextRealm}.
     */
public static ResourceDefinition getElytronRealmResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JAAS_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<SecurityRealm>(attributes, SECURITY_REALM_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<SecurityRealm> getValueSupplier(ServiceBuilder<SecurityRealm> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJAASConfig = asStringIfDefined(context, LEGACY_JAAS_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJAASConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJAASConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                return new SecurityDomainContextRealm(domainContext);
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_REALM, addHandler, attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) SecurityRealm(org.wildfly.security.auth.server.SecurityRealm) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceBuilder (org.jboss.msc.service.ServiceBuilder)34 ServiceName (org.jboss.msc.service.ServiceName)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)11 ModelNode (org.jboss.dmr.ModelNode)10 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 OperationContext (org.jboss.as.controller.OperationContext)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)7 Module (org.jboss.modules.Module)7 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 Resource (org.jboss.as.controller.registry.Resource)6 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)6 HashMap (java.util.HashMap)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)5