org.jboss.msc.service.ServiceTarget Java Examples

The following examples show how to use org.jboss.msc.service.ServiceTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmptyResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {

ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<?> runtimeCapability = this.runtimeCapability.fromBaseCapability(context.getCurrentAddressValue());
ServiceName componentName = runtimeCapability.getCapabilityServiceName(valueType);

TrivialService<T> componentService = new TrivialService<T>(valueSupplier);

ServiceBuilder<T> componentBuilder = serviceTarget.addService(componentName, componentService);

commonDependencies(componentBuilder)
    .setInitialMode(Mode.LAZY)
    .install();
}
 
Example #2
Source File: RemoveNotEsistingResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRemoveNonExistingResource() throws Exception {
    container = ServiceContainer.Factory.create("test");
    ServiceTarget target = container.subTarget();
    TestModelControllerService svc = new InterleavedSubsystemModelControllerService();
    target.addService(ServiceName.of("ModelController")).setInstance(svc).install();
    svc.awaitStartup(30, TimeUnit.SECONDS);
    ModelController controller = svc.getValue();

    final PathAddress attributePath = PathAddress.pathAddress(PathElement.pathElement("subsystem", "a"))
            .append(PathElement.pathElement(SUBMODEL_NAME, "nonExisting"));
    final ModelNode op = Util.createEmptyOperation(REMOVE, attributePath);
    ModelNode result = controller.execute(op, null, null, null);

    Assert.assertEquals("failed", result.get("outcome").asString());
}
 
Example #3
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<CallbackHandlerService> addPropertiesAuthenticationService(OperationContext context, ModelNode properties, String realmName,
                                                ServiceTarget serviceTarget, ServiceBuilder<?> realmBuilder) throws OperationFailedException {

    final ServiceName propsServiceName = PropertiesCallbackHandler.ServiceUtil.createServiceName(realmName);
    final String path = PropertiesAuthenticationResourceDefinition.PATH.resolveModelAttribute(context, properties).asString();
    final ModelNode relativeToNode = PropertiesAuthenticationResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, properties);
    final boolean plainText = PropertiesAuthenticationResourceDefinition.PLAIN_TEXT.resolveModelAttribute(context, properties).asBoolean();
    final String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;

    final ServiceBuilder<?> builder = serviceTarget.addService(propsServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(propsServiceName);
    Supplier<PathManager> pmSupplier = null;
    if (relativeTo != null) {
        pmSupplier = builder.requires(context.getCapabilityServiceName(PATH_MANAGER_CAPABILITY, PathManager.class));
        builder.requires(pathName(relativeTo));
    }
    builder.setInstance(new PropertiesCallbackHandler(chsConsumer, pmSupplier, realmName, path, relativeTo, plainText));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, propsServiceName);
}
 
Example #4
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<CallbackHandlerFactory> addSecretService(OperationContext context, ModelNode secret, String realmName, ServiceTarget serviceTarget,
                              ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName secretServiceName = SecretIdentityService.ServiceUtil.createServiceName(realmName);
    final ModelNode resolvedValueNode = SecretServerIdentityResourceDefinition.VALUE.resolveModelAttribute(context, secret);
    boolean base64 = secret.get(SecretServerIdentityResourceDefinition.VALUE.getName()).getType() != ModelType.EXPRESSION;
    final ServiceBuilder<?> builder = serviceTarget.addService(secretServiceName);
    final Consumer<CallbackHandlerFactory> chfConsumer = builder.provides(secretServiceName);
    ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        String keySuffix = SERVER_IDENTITY + KEY_DELIMITER + SECRET;
        credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, SecretServerIdentityResourceDefinition.CREDENTIAL_REFERENCE, secret, builder, keySuffix);
    }
    SecretIdentityService sis;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), false);
    } else {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), base64);
    }
    builder.setInstance(sis);
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerFactory.ServiceUtil.requires(realmBuilder, secretServiceName);
}
 
Example #5
Source File: TopologyWebAppActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    if (!topologyWebAppFractionInstance.isUnsatisfied()) {
        serviceNames = topologyWebAppFractionInstance.get().proxiedServiceMappings().keySet();
    }

    TopologyProxyService proxyService = new TopologyProxyService(serviceNames);
    ServiceBuilder<TopologyProxyService> serviceBuilder = target
            .addService(TopologyProxyService.SERVICE_NAME, proxyService)
            .addDependency(DefaultNamespaceContextSelectorService.SERVICE_NAME)
            .addDependency(TopologyManagerActivator.CONNECTOR_SERVICE_NAME)
            .addDependency(NamingService.SERVICE_NAME);

    for (String serviceName : serviceNames) {
        serviceBuilder.addDependency(proxyService.mscServiceNameForServiceProxy(serviceName),
                                     HttpHandler.class, proxyService.getHandlerInjectorFor(serviceName));
    }
    serviceBuilder.install();
}
 
Example #6
Source File: HostPathManagerService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ServiceController<?> addService(ServiceTarget serviceTarget, HostPathManagerService service, HostControllerEnvironment hostEnvironment) {
    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(AbstractControllerService.PATH_MANAGER_CAPABILITY.getCapabilityServiceName(), service).addAliases(SERVICE_NAME);

    // Add resources and capabilities for the always-present paths
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.HOME_DIR, hostEnvironment.getHomeDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.DOMAIN_BASE_DIR, hostEnvironment.getDomainConfigurationDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.DOMAIN_CONFIG_DIR, hostEnvironment.getDomainConfigurationDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.DOMAIN_DATA_DIR, hostEnvironment.getDomainDataDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.DOMAIN_LOG_DIR, hostEnvironment.getDomainLogDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.DOMAIN_TEMP_DIR, hostEnvironment.getDomainTempDir().getAbsolutePath());
    service.addHardcodedAbsolutePath(serviceTarget, HostControllerEnvironment.CONTROLLER_TEMP_DIR, hostEnvironment.getDomainTempDir().getAbsolutePath());

    // Registering the actual standard server path capabilities so server config resources can reference them
    //TODO look if those registrations could be moved to ServerService/DomainModelControllerService.initModel
    registerServerPathCapability(service.localCapRegRef, ServerEnvironment.SERVER_BASE_DIR);
    registerServerPathCapability(service.localCapRegRef, ServerEnvironment.SERVER_CONFIG_DIR);
    registerServerPathCapability(service.localCapRegRef, ServerEnvironment.SERVER_DATA_DIR);
    registerServerPathCapability(service.localCapRegRef, ServerEnvironment.SERVER_LOG_DIR);
    registerServerPathCapability(service.localCapRegRef, ServerEnvironment.SERVER_TEMP_DIR);

    return serviceBuilder.install();
}
 
Example #7
Source File: ContextCreateHandlerRegistryService.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
ContextCreateHandlerRegistryImpl(final ServiceContainer serviceContainer, final ServiceTarget serviceTarget) {

            // Setup the default handlers
            addContextCreateHandler(null, new ModuleClassLoaderAssociationHandler());
            addContextCreateHandler(null, new ClassResolverAssociationHandler());
            addContextCreateHandler(null, new ComponentResolverAssociationHandler(subsystemState));

            subsystemState.processExtensions(new Consumer<CamelSubsytemExtension>() {
                @Override
                public void accept(CamelSubsytemExtension plugin) {
                    ContextCreateHandler handler = plugin.getContextCreateHandler(serviceContainer, serviceTarget, subsystemState);
                    if (handler != null) {
                        addContextCreateHandler(null, handler);
                    }
                }
            });
        }
 
Example #8
Source File: MetricsRegistrationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ManagementResourceRegistration setupController(ProcessType processType, TestResourceDefinition resourceDefinition) throws InterruptedException {

        System.out.println("=========  New Test \n");
        container = ServiceContainer.Factory.create(TEST_METRIC);
        ServiceTarget target = container.subTarget();
        ModelControllerService svc = new ModelControllerService(processType, resourceDefinition);
        target.addService(ServiceName.of("ModelController")).setInstance(svc).install();
        svc.awaitStartup(30, TimeUnit.SECONDS);
        controller = svc.getValue();
        ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
        controller.execute(setup, null, null, null);

        client = controller.createClient(executor);

        return svc.managementControllerResource;
    }
 
Example #9
Source File: CamelEndpointDeploymentSchedulerProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    List<DeploymentUnit> subDeployments = deploymentUnit
            .getAttachmentList(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS);
    if (subDeployments != null && !subDeployments.isEmpty()) {
        /* do not install CamelEndpointDeploymentSchedulerService for ears */
        return;
    }

    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ServiceController<CamelEndpointDeploymentSchedulerService> serviceController = CamelEndpointDeploymentSchedulerService
            .addService(deploymentUnit.getServiceName(), deploymentUnit.getName(), serviceTarget);
    phaseContext.addDeploymentDependency(serviceController.getName(),
            CamelConstants.CAMEL_ENDPOINT_DEPLOYMENT_SCHEDULER_REGISTRY_KEY);
}
 
Example #10
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<CallbackHandlerService> addLocalService(OperationContext context, ModelNode local, String realmName, ServiceTarget serviceTarget,
                             ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    ServiceName localServiceName = LocalCallbackHandlerService.ServiceUtil.createServiceName(realmName);
    ModelNode node = LocalAuthenticationResourceDefinition.DEFAULT_USER.resolveModelAttribute(context, local);
    String defaultUser = node.isDefined() ? node.asString() : null;
    node = LocalAuthenticationResourceDefinition.ALLOWED_USERS.resolveModelAttribute(context, local);
    String allowedUsers = node.isDefined() ? node.asString() : null;
    node = LocalAuthenticationResourceDefinition.SKIP_GROUP_LOADING.resolveModelAttribute(context, local);
    boolean skipGroupLoading = node.asBoolean();

    final ServiceBuilder<?> builder = serviceTarget.addService(localServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(localServiceName);
    builder.setInstance(new LocalCallbackHandlerService(chsConsumer, defaultUser, allowedUsers, skipGroupLoading));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, localServiceName);
}
 
Example #11
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #12
Source File: SecureServerDefinition.java    From keycloak with Apache License 2.0 6 votes vote down vote up
static void installCapability(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress pathAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    String factoryName = pathAddress.getLastElement().getValue();
    ServiceName serviceName = context.getCapabilityServiceName(HTTP_SERVER_AUTHENTICATION_CAPABILITY, factoryName, HttpServerAuthenticationMechanismFactory.class);
    boolean publicClient = SecureServerDefinition.PUBLIC_CLIENT.resolveModelAttribute(context, operation).asBoolean(false);

    if (!publicClient) {
        throw new OperationFailedException("Only public clients are allowed to have their configuration exposed through the management interface");
    }

    KeycloakHttpAuthenticationFactoryService service = new KeycloakHttpAuthenticationFactoryService(factoryName);
    ServiceTarget serviceTarget = context.getServiceTarget();
    InjectedValue<ExtensibleHttpManagement> injectedValue = new InjectedValue<>();
    serviceTarget.addService(serviceName.append("http-management-context"), createHttpManagementConfigContextService(factoryName, injectedValue))
            .addDependency(context.getCapabilityServiceName(HTTP_MANAGEMENT_HTTP_EXTENSIBLE_CAPABILITY, ExtensibleHttpManagement.class), ExtensibleHttpManagement.class, injectedValue).setInitialMode(Mode.ACTIVE).install();
    serviceTarget.addService(serviceName, service).setInitialMode(Mode.ACTIVE).install();
}
 
Example #13
Source File: EmbeddedHostControllerBootstrap.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public FutureServiceContainer bootstrap(PropertyChangeListener processStateListener) throws Exception {
    try {
        final HostRunningModeControl runningModeControl = environment.getRunningModeControl();
        final ControlledProcessState processState = new ControlledProcessState(true);
        shutdownHook.setControlledProcessState(processState);
        ServiceTarget target = serviceContainer.subTarget();

        final ProcessStateNotifier processStateNotifier = ControlledProcessStateService.addService(target, processState).getValue();
        processStateNotifier.addPropertyChangeListener(processStateListener);
        RunningStateJmx.registerMBean(processStateNotifier, null, runningModeControl, false);
        final HostControllerService hcs = new HostControllerService(environment, runningModeControl, authCode, processState, futureContainer);
        target.addService(HostControllerService.HC_SERVICE_NAME, hcs).install();
        return futureContainer;
    } catch (RuntimeException | Error e) {
        shutdownHook.run();
        throw e;
    }
}
 
Example #14
Source File: CamelEndpointDeployerService.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
public static ServiceController<CamelEndpointDeployerService> addService(DeploymentUnit deploymentUnit,
        ServiceTarget serviceTarget, ServiceName deploymentInfoServiceName, ServiceName hostServiceName) {

    CamelEndpointDeployerService service = new CamelEndpointDeployerService();
    ServiceBuilder<CamelEndpointDeployerService> sb = serviceTarget
            .addService(deployerServiceName(deploymentUnit.getServiceName()), service);
    sb.addDependency(hostServiceName, Host.class, service.hostSupplier);
    sb.addDependency(deploymentInfoServiceName, DeploymentInfo.class, service.deploymentInfoSupplier);
    sb.addDependency(
            CamelEndpointDeploymentSchedulerService.deploymentSchedulerServiceName(deploymentUnit.getServiceName()),
            CamelEndpointDeploymentSchedulerService.class, service.deploymentSchedulerServiceSupplier);
    sb.addDependency(UndertowService.SERVLET_CONTAINER.append("default"), ServletContainerService.class, service.servletContainerServiceSupplier);

    final EEModuleConfiguration moduleConfiguration = deploymentUnit
            .getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_CONFIGURATION);
    if (moduleConfiguration != null) {
        for (final ComponentConfiguration c : moduleConfiguration.getComponentConfigurations()) {
            sb.addDependency(c.getComponentDescription().getStartServiceName());
        }
    }
    return sb.install();
}
 
Example #15
Source File: MetricsUndefinedValueUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ManagementResourceRegistration setupController(TestResourceDefinition resourceDefinition) throws InterruptedException {

        // restore default
        blockObject = new CountDownLatch(1);
        latch = new CountDownLatch(1);

        System.out.println("=========  New Test \n");
        container = ServiceContainer.Factory.create(TEST_METRIC);
        ServiceTarget target = container.subTarget();
        ModelControllerService svc = new ModelControllerService(resourceDefinition);
        target.addService(ServiceName.of("ModelController")).setInstance(svc).install();
        svc.awaitStartup(30, TimeUnit.SECONDS);
        controller = svc.getValue();
        ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
        controller.execute(setup, null, null, null);

        client = controller.createClient(executor);

        return svc.managementControllerResource;
    }
 
Example #16
Source File: ManagementRemotingServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Installs a remoting stream server for a domain instance
 *  @param serviceTarget the service target to install the services into
 * @param endpointName the name of the endpoint to install the stream server into
 * @param networkInterfaceBinding the network interface binding
 * @param port the port
 * @param securityRealm the security real name
 * @param options the remoting options
 */
public static void installDomainConnectorServices(final OperationContext context,
                                                  final ServiceTarget serviceTarget,
                                                  final ServiceName endpointName,
                                                  final ServiceName networkInterfaceBinding,
                                                  final int port,
                                                  final OptionMap options,
                                                  final ServiceName securityRealm,
                                                  final ServiceName saslAuthenticationFactory,
                                                  final ServiceName sslContext) {
    String sbmCap = "org.wildfly.management.socket-binding-manager";
    ServiceName sbmName = context.hasOptionalCapability(sbmCap, NATIVE_MANAGEMENT_RUNTIME_CAPABILITY.getName(), null)
            ? context.getCapabilityServiceName(sbmCap, SocketBindingManager.class) : null;
    installConnectorServicesForNetworkInterfaceBinding(serviceTarget, endpointName, MANAGEMENT_CONNECTOR,
            networkInterfaceBinding, port, options, securityRealm, saslAuthenticationFactory, sslContext, sbmName);
}
 
Example #17
Source File: VirtualSecurityDomainProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null || !isVirtualDomainRequired(deploymentUnit)) {
        return;  // Only interested in installation if this is really the root deployment.
    }

    ServiceName virtualDomainName = virtualDomainName(deploymentUnit);
    ServiceTarget serviceTarget = phaseContext.getServiceTarget();

    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(virtualDomainName);

    final SecurityDomain virtualDomain = SecurityDomain.builder().build();
    final Consumer<SecurityDomain> consumer = serviceBuilder.provides(virtualDomainName);

    serviceBuilder.setInstance(Service.newInstance(consumer, virtualDomain));
    serviceBuilder.setInitialMode(Mode.ON_DEMAND);
    serviceBuilder.install();
}
 
Example #18
Source File: ModelControllerImplUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Before
public void setupController() throws InterruptedException {

    container = ServiceContainer.Factory.create("test");
    ServiceTarget target = container.subTarget();
    ModelControllerService svc = new ModelControllerService();
    target.addService(ServiceName.of("ModelController")).setInstance(svc).install();
    sharedState = svc.getSharedState();
    svc.awaitStartup(30, TimeUnit.SECONDS);
    controller = svc.getValue();
    ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
    controller.execute(setup, null, null, null);
    notificationHandler = new ServiceNotificationHandler();
    controller.getNotificationRegistry().registerNotificationHandler(PathAddress.pathAddress(CORE_SERVICE, MANAGEMENT).append(SERVICE, MANAGEMENT_OPERATIONS), notificationHandler, notificationHandler);
    assertEquals(ControlledProcessState.State.RUNNING, svc.getCurrentProcessState());
}
 
Example #19
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #20
Source File: ModuleResolvePhaseService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void installService(final ServiceTarget serviceTarget, final ModuleIdentifier moduleIdentifier, int phaseNumber, final Set<ModuleDependency> nextPhaseIdentifiers, final Set<ModuleIdentifier> nextAlreadySeen) {
    final ModuleResolvePhaseService nextPhaseService = new ModuleResolvePhaseService(moduleIdentifier, nextAlreadySeen, phaseNumber);
    ServiceBuilder<ModuleResolvePhaseService> builder = serviceTarget.addService(moduleSpecServiceName(moduleIdentifier, phaseNumber), nextPhaseService);
    for (ModuleDependency module : nextPhaseIdentifiers) {
        builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(module.getIdentifier()), ModuleDefinition.class, new Injector<ModuleDefinition>() {

            ModuleDefinition definition;

            @Override
            public synchronized void inject(final ModuleDefinition o) throws InjectionException {
                nextPhaseService.getModuleSpecs().add(o);
                this.definition = o;
            }

            @Override
            public synchronized void uninject() {
                nextPhaseService.getModuleSpecs().remove(definition);
                this.definition = null;
            }
        });
    }
    builder.install();
}
 
Example #21
Source File: ContentCleanerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void addService(final ServiceTarget serviceTarget, final ServiceName clientFactoryService, final ServiceName scheduledExecutorServiceName) {
    final ServiceBuilder<?> builder = serviceTarget.addService(SERVICE_NAME);
    final Supplier<ModelControllerClientFactory> mccfSupplier = builder.requires(clientFactoryService);
    final Supplier<ProcessStateNotifier> cpsnSupplier = builder.requires(ControlledProcessStateService.INTERNAL_SERVICE_NAME);
    final Supplier<ScheduledExecutorService> sesSupplier = builder.requires(scheduledExecutorServiceName);
    final Supplier<ExecutorService> esSupplier = Services.requireServerExecutor(builder);
    builder.setInstance(new ContentCleanerService(true, mccfSupplier, cpsnSupplier, sesSupplier, esSupplier));
    builder.install();
}
 
Example #22
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<SubjectSupplementalService> addPlugInAuthorizationService(OperationContext context, ModelNode model, String realmName,
                                           ServiceTarget serviceTarget, ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName plugInServiceName = PlugInSubjectSupplemental.ServiceUtil.createServiceName(realmName);
    final String pluginName = PlugInAuthorizationResourceDefinition.NAME.resolveModelAttribute(context, model).asString();
    final Map<String, String> properties = resolveProperties(context, model);

    final ServiceBuilder<?> builder = serviceTarget.addService(plugInServiceName);
    final Consumer<SubjectSupplementalService> sssConsumer = builder.provides(plugInServiceName);
    final Supplier<PlugInLoaderService> pilSupplier = PlugInLoaderService.ServiceUtil.requires(builder, realmName);
    builder.setInstance(new PlugInSubjectSupplemental(sssConsumer, pilSupplier, realmName, pluginName, properties));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return SubjectSupplementalService.ServiceUtil.requires(realmBuilder, plugInServiceName);
}
 
Example #23
Source File: AbstractControllerTestBase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setupController() throws InterruptedException {
    container = ServiceContainer.Factory.create("test");
    ServiceTarget target = container.subTarget();
    ModelControllerService svc = new ModelControllerService(processType, getAuditLogger());
    ServiceBuilder<ModelController> builder = target.addService(ServiceName.of("ModelController"), svc);
    builder.install();
    svc.awaitStartup(30, TimeUnit.SECONDS);
    controller = svc.getValue();
    //ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
    //controller.execute(setup, null, null, null);
}
 
Example #24
Source File: CertificateAuthorityAccountDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();
    String certificateAuthorityName = CERTIFICATE_AUTHORITY.resolveModelAttribute(context, model).asString();
    final String alias = ALIAS.resolveModelAttribute(context, model).asString();
    final String keyStoreName = KEY_STORE.resolveModelAttribute(context, model).asString();
    ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null;
    if (CREDENTIAL_REFERENCE.resolveModelAttribute(context, operation).isDefined()) {
        credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, CREDENTIAL_REFERENCE, operation, null);
    }
    final List<ModelNode> contactUrls = CONTACT_URLS.resolveModelAttribute(context, model).asListOrEmpty();
    final List<String> contactUrlsList = new ArrayList<>(contactUrls.size());
    for (ModelNode contactUrl : contactUrls) {
        contactUrlsList.add(contactUrl.asString());
    }

    AcmeAccountService acmeAccountService = new AcmeAccountService(certificateAuthorityName, contactUrlsList, alias, keyStoreName);
    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> certificateAuthorityAccountRuntimeCapability = CERTIFICATE_AUTHORITY_ACCOUNT_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName acmeAccountServiceName = certificateAuthorityAccountRuntimeCapability.getCapabilityServiceName(AcmeAccount.class);
    ServiceBuilder<AcmeAccount> acmeAccountServiceBuilder = serviceTarget.addService(acmeAccountServiceName, acmeAccountService).setInitialMode(ServiceController.Mode.ACTIVE);
    acmeAccountService.getCredentialSourceSupplierInjector().inject(credentialSourceSupplier);

    String keyStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName(KEY_STORE_CAPABILITY, keyStoreName);
    acmeAccountServiceBuilder.addDependency(context.getCapabilityServiceName(keyStoreCapabilityName, KeyStore.class), KeyStore.class, acmeAccountService.getKeyStoreInjector());
    if (certificateAuthorityName.equalsIgnoreCase(CertificateAuthority.LETS_ENCRYPT.getName())) {
        commonRequirements(acmeAccountServiceBuilder).install();
    } else {
        acmeAccountServiceBuilder.requires(CERTIFICATE_AUTHORITY_RUNTIME_CAPABILITY.getCapabilityServiceName(certificateAuthorityName));
        commonRequirements(acmeAccountServiceBuilder).install();
    }
}
 
Example #25
Source File: HandoffExecutorResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ServiceName resolveHandoffExecutor(String handoffExecutorName, String threadPoolName, ServiceName threadPoolServiceName, ServiceTarget serviceTarget) {
    ServiceName threadFactoryServiceName = null;

    if (handoffExecutorName != null) {
        threadFactoryServiceName = resolveNamedHandoffExecutor(handoffExecutorName, threadPoolName, threadPoolServiceName);
    } else {
        // Create a default
        threadFactoryServiceName = resolveDefaultHandoffExecutor(threadPoolName, threadPoolServiceName, serviceTarget);
    }
    return threadFactoryServiceName;
}
 
Example #26
Source File: ThreadFactoryResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ServiceName resolveThreadFactory(String threadFactoryName, String threadPoolName, ServiceName threadPoolServiceName, ServiceTarget serviceTarget) {
    ServiceName threadFactoryServiceName;

    if (threadFactoryName != null) {
        threadFactoryServiceName = resolveNamedThreadFactory(threadFactoryName, threadPoolName, threadPoolServiceName);
    } else {
        // Create a default
        threadFactoryServiceName = resolveDefaultThreadFactory(threadPoolName, threadPoolServiceName, serviceTarget);
    }
    return threadFactoryServiceName;
}
 
Example #27
Source File: ElytronDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
    ServiceTarget target = context.getServiceTarget();
    SecurityPropertyService securityPropertyService = context.getAttachment(SECURITY_PROPERTY_SERVICE_KEY);
    if (securityPropertyService != null) {
        installService(SecurityPropertyService.SERVICE_NAME, securityPropertyService, target);
    }
    List<String> providers = DISALLOWED_PROVIDERS.unwrap(context, model);
    installService(ProviderRegistrationService.SERVICE_NAME, new ProviderRegistrationService(providers), target);
}
 
Example #28
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addClientCertService(String realmName, ServiceTarget serviceTarget, ServiceBuilder<?> realmBuilder) {
    final ServiceName clientCertServiceName = ClientCertCallbackHandler.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> builder = serviceTarget.addService(clientCertServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(clientCertServiceName);
    builder.setInstance(new ClientCertCallbackHandler(chsConsumer));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, clientCertServiceName);
}
 
Example #29
Source File: RemotingSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AdditionalInitialization createRuntimeAdditionalInitialization() {
    return new AdditionalInitialization() {
        @Override
        protected void setupController(ControllerInitializer controllerInitializer) {
            controllerInitializer.addSocketBinding("remoting", 27258);
            controllerInitializer.addRemoteOutboundSocketBinding("dummy-outbound-socket", "localhost", 6799);
            controllerInitializer.addRemoteOutboundSocketBinding("other-outbound-socket", "localhost", 1234);
        }

        @Override
        protected void addExtraServices(ServiceTarget target) {
            //Needed for initialization of the RealmAuthenticationProviderService
            AbsolutePathService.addService(ServerEnvironment.CONTROLLER_TEMP_DIR, new File("target/temp" + System.currentTimeMillis()).getAbsolutePath(), target);
            ServiceBuilder<?> builder = target.addService(IOServices.WORKER.append("default"));
            Consumer<XnioWorker> workerConsumer = builder.provides(IOServices.WORKER.append("default"));
            builder.setInstance(new WorkerService(workerConsumer, () -> Executors.newFixedThreadPool(1), Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2)));
            builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
            builder.install();

            builder = target.addService(IOServices.WORKER.append("default-remoting"));
            workerConsumer = builder.provides(IOServices.WORKER.append("default-remoting"));
            builder.setInstance(new WorkerService(workerConsumer, () -> Executors.newFixedThreadPool(1), Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2)));
            builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
            builder.install();            }

        @Override
        protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
            super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration, capabilityRegistry);
            Map<String, Class> capabilities = new HashMap<>();
            capabilities.put(buildDynamicCapabilityName(IO_WORKER_CAPABILITY_NAME,
                    RemotingSubsystemRootResource.WORKER.getDefaultValue().asString()), XnioWorker.class);
            capabilities.put(buildDynamicCapabilityName(IO_WORKER_CAPABILITY_NAME,
                    "default-remoting"), XnioWorker.class);
            AdditionalInitialization.registerServiceCapabilities(capabilityRegistry, capabilities);
        }
    };
}
 
Example #30
Source File: ServerPathManagerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void addAbsolutePath(ServerPathManagerService service, ServiceTarget serviceTarget, String name, File path) {
    if (path == null) {
        return;
    }

    service.addHardcodedAbsolutePath(serviceTarget, name, path.getAbsolutePath());
}