Java Code Examples for org.jboss.msc.service.ServiceBuilder#addDependency()
The following examples show how to use
org.jboss.msc.service.ServiceBuilder#addDependency() .
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: TopologyWebAppActivator.java From thorntail with Apache License 2.0 | 6 votes |
@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 2
Source File: ModuleResolvePhaseService.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
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 3
Source File: RemoteDomainConnectionService.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static Future<MasterDomainControllerClient> install(final ServiceTarget serviceTarget, final ModelController controller, final ExtensionRegistry extensionRegistry, final LocalHostControllerInfo localHostControllerInfo, final ServiceName authenticationContext, final String securityRealm, final RemoteFileRepository remoteFileRepository, final ContentRepository contentRepository, final IgnoredDomainResourceRegistry ignoredDomainResourceRegistry, final HostControllerRegistrationHandler.OperationExecutor operationExecutor, final DomainController domainController, final HostControllerEnvironment hostControllerEnvironment, final ExecutorService executor, final RunningMode currentRunningMode, final Map<String, ProxyController> serverProxies, final AtomicBoolean domainConfigAvailable) { RemoteDomainConnectionService service = new RemoteDomainConnectionService(controller, extensionRegistry, localHostControllerInfo, remoteFileRepository, contentRepository, ignoredDomainResourceRegistry, operationExecutor, domainController, hostControllerEnvironment, executor, currentRunningMode, serverProxies, domainConfigAvailable); ServiceBuilder<MasterDomainControllerClient> builder = serviceTarget.addService(MasterDomainControllerClient.SERVICE_NAME, service) .addDependency(ManagementRemotingServices.MANAGEMENT_ENDPOINT, Endpoint.class, service.endpointInjector) .addDependency(ServerInventoryService.SERVICE_NAME, ServerInventory.class, service.serverInventoryInjector) .addDependency(HostControllerService.HC_SCHEDULED_EXECUTOR_SERVICE_NAME, ScheduledExecutorService.class, service.scheduledExecutorInjector) .setInitialMode(ServiceController.Mode.ACTIVE); if (authenticationContext != null) { builder.addDependency(authenticationContext, AuthenticationContext.class, service.authenticationContextInjector); } if (securityRealm != null) { SecurityRealm.ServiceUtil.addDependency(builder, service.securityRealmInjector, securityRealm); } builder.install(); return service.futureClient; }
Example 4
Source File: LdapRealmDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void configureDirContext(OperationContext context, ModelNode model, LdapSecurityRealmBuilder realmBuilder, ServiceBuilder<SecurityRealm> serviceBuilder) throws OperationFailedException { String dirContextName = DIR_CONTEXT.resolveModelAttribute(context, model).asStringOrNull(); String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(DIR_CONTEXT_CAPABILITY, dirContextName); ServiceName dirContextServiceName = context.getCapabilityServiceName(runtimeCapability, DirContextSupplier.class); final InjectedValue<DirContextSupplier> dirContextInjector = new InjectedValue<>(); serviceBuilder.addDependency(dirContextServiceName, DirContextSupplier.class, dirContextInjector); realmBuilder.setDirContextSupplier(() -> { ExceptionSupplier<DirContext, NamingException> supplier = dirContextInjector.getValue(); return supplier.get(); }); }
Example 5
Source File: AuthenticationFactoryDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void injectRealmMapper(SimpleAttributeDefinition realmMapperAttribute, ServiceBuilder<?> serviceBuilder, OperationContext context, ModelNode model, Injector<RealmMapper> realmMapperInjector) throws OperationFailedException { String realmMapper = realmMapperAttribute.resolveModelAttribute(context, model).asStringOrNull(); if (realmMapper != null) { serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(REALM_MAPPER_CAPABILITY, realmMapper), RealmMapper.class), RealmMapper.class, realmMapperInjector); } }
Example 6
Source File: AuthenticationFactoryDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void injectSecurityFactory(SimpleAttributeDefinition securityFactoryAttribute, ServiceBuilder<?> serviceBuilder, OperationContext context, ModelNode model, Injector<SecurityFactory> securityFactoryInjector) throws OperationFailedException { String securityFactory = securityFactoryAttribute.resolveModelAttribute(context, model).asStringOrNull(); if (securityFactory != null) { serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(SECURITY_FACTORY_CREDENTIAL_CAPABILITY, securityFactory), SecurityFactory.class), SecurityFactory.class, securityFactoryInjector); } }
Example 7
Source File: SSLDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static <T> InjectedValue<T> addDependency(String baseName, SimpleAttributeDefinition attribute, Class<T> type, ServiceBuilder<SSLContext> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { String dynamicNameElement = attribute.resolveModelAttribute(context, model).asStringOrNull(); InjectedValue<T> injectedValue = new InjectedValue<>(); if (dynamicNameElement != null) { serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(baseName, dynamicNameElement), type), type, injectedValue); } return injectedValue; }
Example 8
Source File: TestHostCapableExtension.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { boolean hasSocketBinding = resource.getModel().hasDefined(SOCKET_BINDING.getName()); TestService service = new TestService(hasSocketBinding); ServiceBuilder<TestService> serviceBuilder = context.getServiceTarget().addService(createServiceName(context.getCurrentAddress()), service); if (hasSocketBinding) { final String socketName = SOCKET_BINDING.resolveModelAttribute(context, resource.getModel()).asString(); final ServiceName socketBindingName = context.getCapabilityServiceName(RootResourceDefinition.SOCKET_CAPABILITY_NAME, socketName, SocketBinding.class); serviceBuilder.addDependency(socketBindingName, SocketBinding.class, service.socketBindingInjector); } serviceBuilder.install(); }
Example 9
Source File: RealmMapperDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { ServiceTarget serviceTarget = context.getServiceTarget(); RuntimeCapability<Void> runtimeCapability = REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue()); ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class); final String pattern = PATTERN_CAPTURE_GROUP.resolveModelAttribute(context, model).asString(); String delegateRealmMapper = DELEGATE_REALM_MAPPER.resolveModelAttribute(context, model).asStringOrNull(); final InjectedValue<RealmMapper> delegateRealmMapperInjector = new InjectedValue<RealmMapper>(); TrivialService<RealmMapper> realmMapperService = new TrivialService<RealmMapper>(() -> { RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue(); Pattern compiledPattern = Pattern.compile(pattern); if (delegate == null) { return new SimpleRegexRealmMapper(compiledPattern); } else { return new SimpleRegexRealmMapper(compiledPattern, delegate); } }); ServiceBuilder<RealmMapper> realmMapperBuilder = serviceTarget.addService(realmMapperName, realmMapperService); if (delegateRealmMapper != null) { String delegateCapabilityName = RuntimeCapability.buildDynamicCapabilityName(REALM_MAPPER_CAPABILITY, delegateRealmMapper); ServiceName delegateServiceName = context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class); realmMapperBuilder.addDependency(delegateServiceName, RealmMapper.class, delegateRealmMapperInjector); } commonDependencies(realmMapperBuilder) .setInitialMode(Mode.LAZY) .install(); }
Example 10
Source File: PermissionMapperDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static ResourceDefinition getConstantPermissionMapper() { final AttributeDefinition[] attributes = new AttributeDefinition[] { PERMISSIONS, PERMISSION_SETS }; TrivialAddHandler<PermissionMapper> add = new TrivialAddHandler<PermissionMapper>(PermissionMapper.class, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY) { @Override protected ValueSupplier<PermissionMapper> getValueSupplier(ServiceBuilder<PermissionMapper> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { List<Permission> permissions = new ArrayList<>(); if (model.hasDefined(ElytronDescriptionConstants.PERMISSIONS)) { for (ModelNode permission : model.require(ElytronDescriptionConstants.PERMISSIONS).asList()) { permissions.add(new Permission(CLASS_NAME.resolveModelAttribute(context, permission).asString(), MODULE.resolveModelAttribute(context, permission).asStringOrNull(), TARGET_NAME.resolveModelAttribute(context, permission).asStringOrNull(), ACTION.resolveModelAttribute(context, permission).asStringOrNull())); } } List<InjectedValue<Permissions>> permissionSetInjectors = new ArrayList<>(); if (model.hasDefined(ElytronDescriptionConstants.PERMISSION_SETS)) { for (ModelNode permissionSet : model.require(ElytronDescriptionConstants.PERMISSION_SETS).asList()) { InjectedValue<Permissions> permissionSetInjector = new InjectedValue<>(); String permissionSetName = PERMISSION_SET_NAME.resolveModelAttribute(context, permissionSet).asString(); String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(PERMISSION_SET_CAPABILITY, permissionSetName); ServiceName permissionSetServiceName = context.getCapabilityServiceName(runtimeCapability, Permissions.class); serviceBuilder.addDependency(permissionSetServiceName, Permissions.class, permissionSetInjector); permissionSetInjectors.add(permissionSetInjector); } } return () -> createConstantPermissionMapper(permissions, permissionSetInjectors); } }; return new TrivialResourceDefinition(ElytronDescriptionConstants.CONSTANT_PERMISSION_MAPPER, add, attributes, PERMISSION_MAPPER_RUNTIME_CAPABILITY); }
Example 11
Source File: MonitorServiceActivator.java From thorntail with Apache License 2.0 | 5 votes |
@Override public void activate(ServiceActivatorContext context) throws ServiceRegistryException { Optional<String> securityRealm = Optional.empty(); if (!monitorFractionInstance.isUnsatisfied()) { securityRealm = monitorFractionInstance.get().securityRealm(); } ServiceTarget target = context.getServiceTarget(); MonitorService service = new MonitorService(securityRealm); ServiceBuilder<MonitorService> monitorServiceServiceBuilder = target.addService(MonitorService.SERVICE_NAME, service); ServiceBuilder<MonitorService> serviceBuilder = monitorServiceServiceBuilder .addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.getServerEnvironmentInjector()) .addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getModelControllerInjector()); if (securityRealm.isPresent()) { // configured through the fraction interface serviceBuilder.addDependency( createRealmName(securityRealm.get()), SecurityRealm.class, service.getSecurityRealmInjector() ); } serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE) .install(); BinderService binderService = new BinderService(Monitor.JNDI_NAME, null, true); target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Monitor.JNDI_NAME), binderService) .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()) .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(service)) .setInitialMode(ServiceController.Mode.ACTIVE) .install(); }
Example 12
Source File: AuthenticationClientDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static ResourceDefinition getAuthenticationContextDefinition() { AttributeDefinition[] attributes = new AttributeDefinition[] { CONTEXT_EXTENDS, MATCH_RULES }; TrivialAddHandler<AuthenticationContext> add = new TrivialAddHandler<AuthenticationContext>(AuthenticationContext.class, attributes, AUTHENTICATION_CONTEXT_RUNTIME_CAPABILITY) { @Override protected ValueSupplier<AuthenticationContext> getValueSupplier(ServiceBuilder<AuthenticationContext> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { String parent = CONTEXT_EXTENDS.resolveModelAttribute(context, model).asStringOrNull(); Supplier<AuthenticationContext> parentSupplier; if (parent != null) { InjectedValue<AuthenticationContext> parentInjector = new InjectedValue<>(); serviceBuilder.addDependency(context.getCapabilityServiceName( RuntimeCapability.buildDynamicCapabilityName(AUTHENTICATION_CONTEXT_CAPABILITY, parent), AuthenticationContext.class), AuthenticationContext.class, parentInjector); parentSupplier = parentInjector::getValue; } else { parentSupplier = AuthenticationContext::empty; } Function<AuthenticationContext, AuthenticationContext> authContext = Function.identity(); if (model.hasDefined(ElytronDescriptionConstants.MATCH_RULES)) { List<ModelNode> nodes = model.require(ElytronDescriptionConstants.MATCH_RULES).asList(); for (ModelNode current : nodes) { String authenticationConfiguration = AUTHENTICATION_CONFIGURATION.resolveModelAttribute(context, current).asStringOrNull(); String sslContext = SSL_CONTEXT.resolveModelAttribute(context, current).asStringOrNull(); if (authenticationConfiguration == null && sslContext == null) { continue; } Function<MatchRule, MatchRule> matchRule = ignored -> MatchRule.ALL; String abstractType = MATCH_ABSTRACT_TYPE.resolveModelAttribute(context, current).asStringOrNull(); String abstractTypeAuthority = MATCH_ABSTRACT_TYPE_AUTHORITY.resolveModelAttribute(context, current).asStringOrNull(); matchRule = abstractType != null || abstractTypeAuthority != null ? matchRule.andThen(m -> m.matchAbstractType(abstractType, abstractTypeAuthority)) : matchRule; ModelNode host = MATCH_HOST.resolveModelAttribute(context, current); matchRule = host.isDefined() ? matchRule.andThen(m -> m.matchHost(host.asString())) : matchRule; ModelNode localSecurityDomain = MATCH_LOCAL_SECURITY_DOMAIN.resolveModelAttribute(context, current); matchRule = localSecurityDomain.isDefined() ? matchRule.andThen(m -> m.matchLocalSecurityDomain(localSecurityDomain.asString())) : matchRule; ModelNode matchNoUser = MATCH_NO_USER.resolveModelAttribute(context, current); matchRule = matchNoUser.asBoolean() ? matchRule.andThen(m -> m.matchNoUser()) : matchRule; ModelNode path = MATCH_PATH.resolveModelAttribute(context, current); matchRule = path.isDefined() ? matchRule.andThen(m -> m.matchPath(path.asString())) : matchRule; ModelNode port = MATCH_PORT.resolveModelAttribute(context, current); matchRule = port.isDefined() ? matchRule.andThen(m -> m.matchPort(port.asInt())) : matchRule; ModelNode protocol = MATCH_PROTOCOL.resolveModelAttribute(context, current); matchRule = protocol.isDefined() ? matchRule.andThen(m -> m.matchProtocol(protocol.asString())) : matchRule; ModelNode urn = MATCH_URN.resolveModelAttribute(context, current); matchRule = urn.isDefined() ? matchRule.andThen(m -> m.matchUrnName(urn.asString())) : matchRule; ModelNode user = MATCH_USER.resolveModelAttribute(context, current); matchRule = user.isDefined() ? matchRule.andThen(m -> m.matchUser(user.asString())) : matchRule; final Function<MatchRule, MatchRule> finalMatchRule = matchRule; Supplier<MatchRule> matchRuleSuppler = new OneTimeSupplier<>(() -> finalMatchRule.apply(null)); if (authenticationConfiguration != null) { InjectedValue<AuthenticationConfiguration> authenticationConfigurationInjector = new InjectedValue<>(); serviceBuilder.addDependency(context.getCapabilityServiceName( RuntimeCapability.buildDynamicCapabilityName(AUTHENTICATION_CONFIGURATION_CAPABILITY, authenticationConfiguration), AuthenticationConfiguration.class), AuthenticationConfiguration.class, authenticationConfigurationInjector); authContext = authContext.andThen(a -> a.with(matchRuleSuppler.get(), authenticationConfigurationInjector.getValue())); } if (sslContext != null) { InjectedValue<SSLContext> sslContextInjector = new InjectedValue<>(); serviceBuilder.addDependency(context.getCapabilityServiceName( RuntimeCapability.buildDynamicCapabilityName(SSL_CONTEXT_CAPABILITY, sslContext), SSLContext.class), SSLContext.class, sslContextInjector); authContext = authContext.andThen(a -> a.withSsl(matchRuleSuppler.get(), sslContextInjector::getValue)); } } } final Function<AuthenticationContext, AuthenticationContext> finalContext = authContext; return () -> finalContext.apply(parentSupplier.get()); } }; return new TrivialResourceDefinition(ElytronDescriptionConstants.AUTHENTICATION_CONTEXT, add, attributes, AUTHENTICATION_CONTEXT_RUNTIME_CAPABILITY); }
Example 13
Source File: ServerService.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Add this service to the given service target. * @param serviceTarget the service target * @param configuration the bootstrap configuration */ public static void addService(final ServiceTarget serviceTarget, final Bootstrap.Configuration configuration, final ControlledProcessState processState, final BootstrapListener bootstrapListener, final RunningModeControl runningModeControl, final AbstractVaultReader vaultReader, final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier, final SuspendController suspendController) { // Install Executor services final ThreadGroup threadGroup = new ThreadGroup("ServerService ThreadGroup"); final String namePattern = "ServerService Thread Pool -- %t"; final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() { public ThreadFactory run() { return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null); } }); // TODO determine why QueuelessThreadPoolService makes boot take > 35 secs // final QueuelessThreadPoolService serverExecutorService = new QueuelessThreadPoolService(Integer.MAX_VALUE, false, new TimeSpec(TimeUnit.SECONDS, 5)); // serverExecutorService.getThreadFactoryInjector().inject(threadFactory); final boolean forDomain = ProcessType.DOMAIN_SERVER == getProcessType(configuration.getServerEnvironment()); final ServerExecutorService serverExecutorService = new ServerExecutorService(threadFactory, forDomain); serviceTarget.addService(MANAGEMENT_EXECUTOR, serverExecutorService) .addAliases(Services.JBOSS_SERVER_EXECUTOR, ManagementRemotingServices.SHUTDOWN_EXECUTOR_NAME) // Use this executor for mgmt shutdown for now .install(); final ServerScheduledExecutorService serverScheduledExecutorService = new ServerScheduledExecutorService(threadFactory); serviceTarget.addService(JBOSS_SERVER_SCHEDULED_EXECUTOR, serverScheduledExecutorService) .addAliases(JBOSS_SERVER_SCHEDULED_EXECUTOR) .addDependency(MANAGEMENT_EXECUTOR, ExecutorService.class, serverScheduledExecutorService.executorInjector) .install(); final CapabilityRegistry capabilityRegistry = configuration.getCapabilityRegistry(); ServiceBuilder<?> serviceBuilder = serviceTarget.addService(Services.JBOSS_SERVER_CONTROLLER); final boolean allowMCE = configuration.getServerEnvironment().isAllowModelControllerExecutor(); final Supplier<ExecutorService> esSupplier = allowMCE ? serviceBuilder.requires(MANAGEMENT_EXECUTOR) : null; final boolean isDomainEnv = configuration.getServerEnvironment().getLaunchType() == ServerEnvironment.LaunchType.DOMAIN; final Supplier<ControllerInstabilityListener> cilSupplier = isDomainEnv ? serviceBuilder.requires(HostControllerConnectionService.SERVICE_NAME) : null; ServerService service = new ServerService(esSupplier, cilSupplier, configuration, processState, null, bootstrapListener, new ServerDelegatingResourceDefinition(), runningModeControl, vaultReader, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, suspendController); serviceBuilder.setInstance(service); serviceBuilder.addDependency(DeploymentMountProvider.SERVICE_NAME,DeploymentMountProvider.class, service.injectedDeploymentRepository); serviceBuilder.addDependency(ContentRepository.SERVICE_NAME, ContentRepository.class, service.injectedContentRepository); serviceBuilder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.injectedModuleLoader); serviceBuilder.addDependency(EXTERNAL_MODULE_CAPABILITY.getCapabilityServiceName(), ExternalModule.class, service.injectedExternalModule); serviceBuilder.addDependency(PATH_MANAGER_CAPABILITY.getCapabilityServiceName(), PathManager.class, service.injectedPathManagerService); serviceBuilder.requires(CONSOLE_AVAILABILITY_CAPABILITY.getCapabilityServiceName()); serviceBuilder.install(); ExternalManagementRequestExecutor.install(serviceTarget, threadGroup, EXECUTOR_CAPABILITY.getCapabilityServiceName(), service.getStabilityMonitor()); }
Example 14
Source File: AuditResourceDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static ResourceDefinition getFileAuditLogResourceDefinition() { AttributeDefinition[] attributes = new AttributeDefinition[] { PATH, RELATIVE_TO, AUTOFLUSH, SYNCHRONIZED, FORMAT }; AbstractAddStepHandler add = new TrivialAddHandler<SecurityEventListener>(SecurityEventListener.class, attributes, SECURITY_EVENT_LISTENER_RUNTIME_CAPABILITY) { @Override protected ValueSupplier<SecurityEventListener> getValueSupplier( ServiceBuilder<SecurityEventListener> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { final boolean synv = SYNCHRONIZED.resolveModelAttribute(context, model).asBoolean(); final boolean autoflush = AUTOFLUSH.resolveModelAttribute(context, model).asBoolean(synv); final Format format = Format.valueOf(FORMAT.resolveModelAttribute(context, model).asString()); final InjectedValue<PathManager> pathManager = new InjectedValue<PathManager>(); final String path = PATH.resolveModelAttribute(context, model).asString(); final String relativeTo = RELATIVE_TO.resolveModelAttribute(context, model).asStringOrNull(); if (relativeTo != null) { serviceBuilder.addDependency(PathManagerService.SERVICE_NAME, PathManager.class, pathManager); serviceBuilder.requires(pathName(relativeTo)); } return new EndpointClosingEventListenerSupplier() { @Override public SecurityEventListener get() throws StartException { PathResolver pathResolver = pathResolver(); pathResolver.path(path); if (relativeTo != null) { pathResolver.relativeTo(relativeTo, pathManager.getValue()); } File resolvedPath = pathResolver.resolve(); final Supplier<DateTimeFormatter> dateTimeFormatterSupplier = () -> DateTimeFormatter.ofPattern(DATE_FORMAT).withZone(ZoneId.systemDefault()); final SecurityEventVisitor<?, String> formatter = Format.JSON == format ? JsonSecurityEventFormatter.builder().setDateTimeFormatterSupplier(dateTimeFormatterSupplier).build() : SimpleSecurityEventFormatter.builder().setDateTimeFormatterSupplier(dateTimeFormatterSupplier).build(); try { endpoint = FileAuditEndpoint.builder().setLocation(resolvedPath.toPath()) .setSyncOnAccept(synv) .setFlushOnAccept(autoflush) .setDateTimeFormatterSupplier(dateTimeFormatterSupplier).build(); } catch (IOException e) { throw ROOT_LOGGER.unableToStartService(e); } return SecurityEventListener.from(AuditLogger.builder() .setPriorityMapper(m -> EventPriority.WARNING) .setMessageFormatter(m -> m.accept(formatter, null)) .setAuditEndpoint(endpoint) .build()); } }; } }; return new TrivialResourceDefinition(FILE_AUDIT_LOG, add, attributes, SECURITY_EVENT_LISTENER_RUNTIME_CAPABILITY); }
Example 15
Source File: AuthenticationFactoryDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static ResourceDefinition getSaslAuthenticationFactory() { SimpleAttributeDefinition securityDomainAttribute = new SimpleAttributeDefinitionBuilder(BASE_SECURITY_DOMAIN_REF) .setCapabilityReference(SECURITY_DOMAIN_CAPABILITY, SASL_AUTHENTICATION_FACTORY_CAPABILITY) .setRestartAllServices() .build(); AttributeDefinition mechanismConfigurationAttribute = getMechanismConfiguration(SASL_AUTHENTICATION_FACTORY_CAPABILITY); AttributeDefinition[] attributes = new AttributeDefinition[] { securityDomainAttribute, SASL_SERVER_FACTORY, mechanismConfigurationAttribute }; AbstractAddStepHandler add = new TrivialAddHandler<SaslAuthenticationFactory>(SaslAuthenticationFactory.class, ServiceController.Mode.ACTIVE, ServiceController.Mode.PASSIVE, attributes, SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY) { @Override protected ValueSupplier<SaslAuthenticationFactory> getValueSupplier( ServiceBuilder<SaslAuthenticationFactory> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException { String securityDomain = securityDomainAttribute.resolveModelAttribute(context, model).asString(); String saslServerFactory = SASL_SERVER_FACTORY.resolveModelAttribute(context, model).asString(); final InjectedValue<SecurityDomain> securityDomainInjector = new InjectedValue<SecurityDomain>(); final InjectedValue<SaslServerFactory> saslServerFactoryInjector = new InjectedValue<SaslServerFactory>(); serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(SECURITY_DOMAIN_CAPABILITY, securityDomain), SecurityDomain.class), SecurityDomain.class, securityDomainInjector); serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(SASL_SERVER_FACTORY_CAPABILITY, saslServerFactory), SaslServerFactory.class), SaslServerFactory.class, saslServerFactoryInjector); final Set<String> supportedMechanisms = getConfiguredMechanismNames(mechanismConfigurationAttribute, context, model); final List<ResolvedMechanismConfiguration> resolvedMechanismConfigurations = getResolvedMechanismConfiguration(mechanismConfigurationAttribute, serviceBuilder, context, model); return () -> { SaslServerFactory serverFactory = saslServerFactoryInjector.getValue(); if (! supportedMechanisms.isEmpty()) { // filter non-configured mechanisms out (when we are sure they are not configured) serverFactory = new FilterMechanismSaslServerFactory(serverFactory, true, supportedMechanisms); // sort mechanisms using the configured order serverFactory = new SortedMechanismSaslServerFactory(serverFactory, supportedMechanisms.toArray(new String[supportedMechanisms.size()])); } else { // no mechanisms were configured, sort mechanisms by strength serverFactory = new SortedMechanismSaslServerFactory(serverFactory, AuthenticationFactoryDefinitions::compareSasl); } SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder() .setSecurityDomain(securityDomainInjector.getValue()) .setFactory(serverFactory); buildMechanismConfiguration(resolvedMechanismConfigurations, builder); return builder.build(); }; } }; return wrap(new TrivialResourceDefinition(ElytronDescriptionConstants.SASL_AUTHENTICATION_FACTORY, add, attributes, SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY), AuthenticationFactoryDefinitions::getAvailableSaslMechanisms); }
Example 16
Source File: SecurityRealm.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * @deprecated use {@link #requires(ServiceBuilder, String)} method instead */ @Deprecated public static ServiceBuilder<?> addDependency(ServiceBuilder<?> sb, Injector<SecurityRealm> injector, String realmName) { return sb.addDependency(createServiceName(realmName), SecurityRealm.class, injector); }
Example 17
Source File: ThreadPoolManagementUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static <T> void installThreadPoolService(final Service<T> threadPoolService, final String threadPoolName, final RuntimeCapability<Void> cap, final PathAddress address, final ServiceName serviceNameBase, final String threadFactoryName, final ThreadFactoryResolver threadFactoryResolver, final Injector<ThreadFactory> threadFactoryInjector, final String handoffExecutorName, final HandoffExecutorResolver handoffExecutorResolver, final Injector<Executor> handoffExecutorInjector, final ServiceTarget target) { final ServiceName threadPoolServiceName; final ServiceName aliasServiceName; if(cap != null) { threadPoolServiceName = cap.getCapabilityServiceName(address); if(serviceNameBase != null) { aliasServiceName = serviceNameBase.append(threadPoolName); } else { aliasServiceName = null; } } else { threadPoolServiceName = serviceNameBase.append(threadPoolName); aliasServiceName = null; } final ServiceBuilder<?> serviceBuilder = target.addService(threadPoolServiceName, threadPoolService); if(aliasServiceName != null) { serviceBuilder.addAliases(aliasServiceName); } final ServiceName threadFactoryServiceName = threadFactoryResolver.resolveThreadFactory(threadFactoryName, threadPoolName, threadPoolServiceName, target); serviceBuilder.addDependency(threadFactoryServiceName, ThreadFactory.class, threadFactoryInjector); if (handoffExecutorInjector != null) { ServiceName handoffServiceName = handoffExecutorResolver.resolveHandoffExecutor(handoffExecutorName, threadPoolName, threadPoolServiceName, target); if (handoffServiceName != null) { serviceBuilder.addDependency(handoffServiceName, Executor.class, handoffExecutorInjector); } } serviceBuilder.install(); }
Example 18
Source File: ServiceUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
ServiceBuilder<?> addInjection(ServiceBuilder<?> sb, Injector<T> injector, ServiceName serviceName) { sb.addDependency(serviceName, clazz, injector); return sb; }
Example 19
Source File: ServerStartTask.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public AsyncFuture<ServiceContainer> run(final List<ServiceActivator> runServices) { final Bootstrap bootstrap = Bootstrap.Factory.newInstance(); final ProductConfig productConfig = ProductConfig.fromFilesystemSlot(Module.getBootModuleLoader(), home, properties); // Create server environment on the server, so that the system properties are getting initialized on the right side final ServerEnvironment providedEnvironment = new ServerEnvironment(hostControllerName, properties, WildFlySecurityManager.getSystemEnvironmentPrivileged(), null, null, ServerEnvironment.LaunchType.DOMAIN, RunningMode.NORMAL, productConfig, Module.getStartTime(), suspend, null, null, null); DomainServerCommunicationServices.updateOperationID(initialOperationID); // TODO perhaps have ConfigurationPersisterFactory as a Service final List<ServiceActivator> services = new ArrayList<ServiceActivator>(startServices); final ServerBootOperationsService service = new ServerBootOperationsService(); // ModelController.boot() will block on this future in order to get the boot updates. final Future<ModelNode> bootOperations = service.getFutureResult(); final ServiceActivator activator = new ServiceActivator() { @Override public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException { final ServiceTarget target = serviceActivatorContext.getServiceTarget(); final ServiceBuilder sb = target.addService(ServiceName.JBOSS.append("server-boot-operations"), service); sb.requires(Services.JBOSS_AS); sb.addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getServerController()); sb.addDependency(HostControllerConnectionService.SERVICE_NAME, HostControllerClient.class, service.getClientInjector()); sb.addDependency(Services.JBOSS_SERVER_EXECUTOR, Executor.class, service.getExecutorInjector()); sb.install(); } }; services.add(activator); final Bootstrap.Configuration configuration = new Bootstrap.Configuration(providedEnvironment); final ExtensionRegistry extensionRegistry = configuration.getExtensionRegistry(); final Bootstrap.ConfigurationPersisterFactory configurationPersisterFactory = new Bootstrap.ConfigurationPersisterFactory() { @Override public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) { ExtensibleConfigurationPersister persister = new AbstractConfigurationPersister(new StandaloneXml(configuration.getModuleLoader(), executorService, extensionRegistry)) { private final PersistenceResource pr = new PersistenceResource() { @Override public void commit() { } @Override public void rollback() { } }; @Override public PersistenceResource store(final ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException { return pr; } @Override public List<ModelNode> load() throws ConfigurationPersistenceException { try { final ModelNode operations = bootOperations.get(); return operations.asList(); } catch (Exception e) { throw new ConfigurationPersistenceException(e); } } }; extensionRegistry.setWriterRegistry(persister); return persister; } }; configuration.setConfigurationPersisterFactory(configurationPersisterFactory); return bootstrap.bootstrap(configuration, services); }
Example 20
Source File: DomainModelControllerService.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static void addService(final ServiceTarget serviceTarget, final HostControllerEnvironment environment, final HostRunningModeControl runningModeControl, final ControlledProcessState processState, final BootstrapListener bootstrapListener, final PathManagerService pathManager, final CapabilityRegistry capabilityRegistry, final ThreadGroup threadGroup) { final ConcurrentMap<String, ProxyController> hostProxies = new ConcurrentHashMap<String, ProxyController>(); final Map<String, ProxyController> serverProxies = new ConcurrentHashMap<String, ProxyController>(); final LocalHostControllerInfoImpl hostControllerInfo = new LocalHostControllerInfoImpl(processState, environment); final AbstractVaultReader vaultReader = loadVaultReaderService(); ROOT_LOGGER.debugf("Using VaultReader %s", vaultReader); final ContentRepository contentRepository = ContentRepository.Factory.create(environment.getDomainContentDir(), environment.getDomainTempDir()); ContentRepository.Factory.addService(serviceTarget, contentRepository); final IgnoredDomainResourceRegistry ignoredRegistry = new IgnoredDomainResourceRegistry(hostControllerInfo); final ManagedAuditLogger auditLogger = createAuditLogger(environment); final DelegatingConfigurableAuthorizer authorizer = new DelegatingConfigurableAuthorizer(); final ManagementSecurityIdentitySupplier securityIdentitySupplier = new ManagementSecurityIdentitySupplier(); final RuntimeHostControllerInfoAccessor hostControllerInfoAccessor = new DomainHostControllerInfoAccessor(hostControllerInfo); final ProcessType processType = environment.getProcessType(); final ExtensionRegistry hostExtensionRegistry = new ExtensionRegistry(processType, runningModeControl, auditLogger, authorizer, securityIdentitySupplier, hostControllerInfoAccessor); final ExtensionRegistry extensionRegistry = new ExtensionRegistry(processType, runningModeControl, auditLogger, authorizer, securityIdentitySupplier, hostControllerInfoAccessor); final PrepareStepHandler prepareStepHandler = new PrepareStepHandler(hostControllerInfo, hostProxies, serverProxies, ignoredRegistry, extensionRegistry); final ExpressionResolver expressionResolver = new RuntimeExpressionResolver(vaultReader); final DomainHostExcludeRegistry domainHostExcludeRegistry = new DomainHostExcludeRegistry(); HostControllerEnvironmentService.addService(environment, serviceTarget); final ServiceBuilder<?> sb = serviceTarget.addService(SERVICE_NAME); final Supplier<ExecutorService> esSupplier = sb.requires(HC_EXECUTOR_SERVICE_NAME); final DomainModelControllerService service = new DomainModelControllerService(esSupplier, environment, runningModeControl, processState, hostControllerInfo, contentRepository, hostProxies, serverProxies, prepareStepHandler, vaultReader, ignoredRegistry, bootstrapListener, pathManager, expressionResolver, new DomainDelegatingResourceDefinition(), hostExtensionRegistry, extensionRegistry, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, domainHostExcludeRegistry); sb.setInstance(service); sb.addDependency(ProcessControllerConnectionService.SERVICE_NAME, ProcessControllerConnectionService.class, service.injectedProcessControllerConnection); sb.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName()); // ensure this is up service.consoleAvailabilitySupplier = sb.requires(CONSOLE_AVAILABILITY_CAPABILITY.getCapabilityServiceName()); sb.install(); ExternalManagementRequestExecutor.install(serviceTarget, threadGroup, EXECUTOR_CAPABILITY.getCapabilityServiceName(), service.getStabilityMonitor()); }