Java Code Examples for org.jboss.msc.service.ServiceBuilder#setInitialMode()

The following examples show how to use org.jboss.msc.service.ServiceBuilder#setInitialMode() . 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: ManagementRemotingServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the services to create a channel listener. This assumes that an endpoint service called {@code endpointName} exists.
 *  @param serviceTarget the service target to install the services into
 * @param endpointName the name of the endpoint to install a channel listener into
 * @param channelName the name of the channel
 * @param operationHandlerName the name of the operation handler to handle request for this channel
 * @param options the remoting options
 * @param onDemand whether to install the services on demand
 */
public static void installManagementChannelOpenListenerService(
        final ServiceTarget serviceTarget,
        final ServiceName endpointName,
        final String channelName,
        final ServiceName operationHandlerName,
        final OptionMap options,
        final boolean onDemand) {

    final ServiceName serviceName = RemotingServices.channelServiceName(endpointName, channelName);
    final ServiceBuilder<?> builder = serviceTarget.addService(serviceName);
    final Supplier<ManagementChannelInitialization> ohfSupplier = builder.requires(operationHandlerName);
    final Supplier<ExecutorService> esSupplier = builder.requires(SHUTDOWN_EXECUTOR_NAME);
    final Supplier<Endpoint> eSupplier = builder.requires(endpointName);
    final Supplier<ManagementChannelRegistryService> rSupplier = builder.requires(ManagementChannelRegistryService.SERVICE_NAME);
    builder.setInstance(new ManagementChannelOpenListenerService(ohfSupplier, esSupplier, eSupplier, rSupplier, channelName, options));
    builder.setInitialMode(onDemand ? ON_DEMAND : ACTIVE);
    builder.install();
}
 
Example 2
Source File: RemotingHttpUpgradeService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void installServices(final OperationContext context, final String remotingConnectorName,
                                   final String httpConnectorName, final ServiceName endpointName,
                                   final OptionMap connectorPropertiesOptionMap, final String securityRealm,
                                   final String saslAuthenticationFactory) {
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ServiceName serviceName = UPGRADE_SERVICE_NAME.append(remotingConnectorName);
    final ServiceBuilder<?> sb = serviceTarget.addService(serviceName);
    final Consumer<RemotingHttpUpgradeService> serviceConsumer = sb.provides(serviceName);
    final Supplier<ChannelUpgradeHandler> urSupplier = sb.requires(HTTP_UPGRADE_REGISTRY.append(httpConnectorName));
    final Supplier<ListenerRegistry> lrSupplier = sb.requires(RemotingServices.HTTP_LISTENER_REGISTRY);
    final Supplier<Endpoint> eSupplier = sb.requires(endpointName);
    final Supplier<org.jboss.as.domain.management.SecurityRealm> srSupplier = securityRealm != null ? sb.requires(org.jboss.as.domain.management.SecurityRealm.ServiceUtil.createServiceName(securityRealm)) : null;
    final Supplier<SaslAuthenticationFactory> safSupplier = saslAuthenticationFactory != null ? sb.requires(context.getCapabilityServiceName(SASL_AUTHENTICATION_FACTORY_CAPABILITY, saslAuthenticationFactory, SaslAuthenticationFactory.class)) : null;
    sb.setInstance(new RemotingHttpUpgradeService(serviceConsumer, urSupplier, lrSupplier, eSupplier, srSupplier, safSupplier, httpConnectorName, endpointName.getSimpleName(), connectorPropertiesOptionMap));
    sb.setInitialMode(ServiceController.Mode.PASSIVE);
    sb.install();
}
 
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> 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 4
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 5
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<SubjectSupplementalService> addPropertiesAuthorizationService(OperationContext context, ModelNode properties,
                                               String realmName, ServiceTarget serviceTarget, ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName propsServiceName = PropertiesSubjectSupplemental.ServiceUtil.createServiceName(realmName);
    final String path = PropertiesAuthorizationResourceDefinition.PATH.resolveModelAttribute(context, properties).asString();
    final ModelNode relativeToNode = PropertiesAuthorizationResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, properties);
    final String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;

    final ServiceBuilder<?> builder = serviceTarget.addService(propsServiceName);
    final Consumer<SubjectSupplementalService> sssConsumer = 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 PropertiesSubjectSupplemental(sssConsumer, pmSupplier, realmName, path, relativeTo));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return SubjectSupplementalService.ServiceUtil.requires(realmBuilder, propsServiceName);
}
 
Example 6
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 7
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 8
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 9
Source File: ModuleLoadService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ServiceName install(final ServiceTarget target, final ModuleIdentifier identifier, ModuleLoadService service) {
    final ServiceName serviceName = ServiceModuleLoader.moduleServiceName(identifier);
    final ServiceBuilder<Module> builder = target.addService(serviceName, service);

    builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoader());
    builder.addDependency(ServiceModuleLoader.moduleSpecServiceName(identifier), ModuleDefinition.class, service.getModuleDefinitionInjectedValue());
    builder.requires(ServiceModuleLoader.moduleResolvedServiceName(identifier)); //don't attempt to load until all dependent module specs are up, even transitive ones
    builder.setInitialMode(Mode.ON_DEMAND);

    builder.install();
    return serviceName;
}
 
Example 10
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 11
Source File: DomainManagedServerCallbackHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void install(final ServiceTarget serviceTarget) {
    final ServiceBuilder<?> builder = serviceTarget.addService(DomainManagedServerCallbackHandler.SERVICE_NAME);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(DomainManagedServerCallbackHandler.SERVICE_NAME);
    builder.setInstance(new DomainManagedServerCallbackHandler(chsConsumer));
    builder.setInitialMode(ON_DEMAND);
    builder.install();
}
 
Example 12
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addUsersService(OperationContext context, ModelNode users, String realmName, ServiceTarget serviceTarget,
                             ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName usersServiceName = UserDomainCallbackHandler.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> builder = serviceTarget.addService(usersServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(usersServiceName);
    builder.setInstance(new UserDomainCallbackHandler(chsConsumer, unmaskUsersCredentials(context, builder, users.clone()), realmName, unmaskUsersPasswords(context, users)));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, usersServiceName);
}
 
Example 13
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addLdapService(OperationContext context, ModelNode ldap, String realmName, ServiceTarget serviceTarget,
                            ServiceBuilder<?> realmBuilder, boolean shareConnection) throws OperationFailedException {
    ServiceName ldapServiceName = UserLdapCallbackHandler.ServiceUtil.createServiceName(realmName);

    final String baseDn = LdapAuthenticationResourceDefinition.BASE_DN.resolveModelAttribute(context, ldap).asString();
    ModelNode node = LdapAuthenticationResourceDefinition.USERNAME_FILTER.resolveModelAttribute(context, ldap);
    final String usernameAttribute = node.isDefined() ? node.asString() : null;
    node = LdapAuthenticationResourceDefinition.ADVANCED_FILTER.resolveModelAttribute(context, ldap);
    final String advancedFilter = node.isDefined() ? node.asString() : null;
    node = LdapAuthenticationResourceDefinition.USERNAME_LOAD.resolveModelAttribute(context, ldap);
    final String usernameLoad = node.isDefined() ? node.asString() : null;
    final boolean recursive = LdapAuthenticationResourceDefinition.RECURSIVE.resolveModelAttribute(context, ldap).asBoolean();
    final boolean allowEmptyPasswords = LdapAuthenticationResourceDefinition.ALLOW_EMPTY_PASSWORDS.resolveModelAttribute(context, ldap).asBoolean();
    final String userDn = LdapAuthenticationResourceDefinition.USER_DN.resolveModelAttribute(context, ldap).asString();

    final LdapSearcher<LdapEntry, String> userSearcher;
    if (usernameAttribute != null) {
        userSearcher = LdapUserSearcherFactory.createForUsernameFilter(baseDn, recursive, userDn, usernameAttribute, usernameLoad);
    } else {
        userSearcher = LdapUserSearcherFactory.createForAdvancedFilter(baseDn, recursive, userDn, advancedFilter, usernameLoad);
    }

    final ServiceName userSearcherCacheName = LdapSearcherCache.ServiceUtil.createServiceName(true, true, realmName);
    final ServiceBuilder<?> userSearchCacheBuilder = serviceTarget.addService(userSearcherCacheName);
    final Consumer<LdapSearcherCache<LdapEntry, String>> lscConsumer = userSearchCacheBuilder.provides(userSearcherCacheName);
    userSearchCacheBuilder.setInstance(createCacheService(lscConsumer, context, userSearcher, ldap.get(CACHE)));
    userSearchCacheBuilder.setInitialMode(ON_DEMAND);
    userSearchCacheBuilder.install();

    final ServiceBuilder<?> builder = serviceTarget.addService(ldapServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(ldapServiceName);
    final String connectionManager = LdapAuthenticationResourceDefinition.CONNECTION.resolveModelAttribute(context, ldap).asString();
    final Supplier<LdapConnectionManager> lcmSupplier = LdapConnectionManagerService.ServiceUtil.requires(builder, connectionManager);
    final Supplier<LdapSearcherCache<LdapEntry, String>> uscSupplier = LdapSearcherCache.ServiceUtil.requires(builder, true, true, realmName);
    builder.setInstance(new UserLdapCallbackHandler(chsConsumer, lcmSupplier, uscSupplier, allowEmptyPasswords, shareConnection));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, ldapServiceName);
}
 
Example 14
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addJaasService(OperationContext context, ModelNode jaas, String realmName, ServiceTarget serviceTarget,
                            boolean injectServerManager, ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName jaasServiceName = JaasCallbackHandler.ServiceUtil.createServiceName(realmName);
    final String name = JaasAuthenticationResourceDefinition.NAME.resolveModelAttribute(context, jaas).asString();
    final boolean assignGroups = JaasAuthenticationResourceDefinition.ASSIGN_GROUPS.resolveModelAttribute(context, jaas).asBoolean();
    final ServiceBuilder<?> builder = serviceTarget.addService(jaasServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(jaasServiceName);
    final Supplier<ServerSecurityManager> smSupplier = injectServerManager ? builder.requires(ServiceName.JBOSS.append("security", "simple-security-manager")) : null;
    builder.setInstance(new JaasCallbackHandler(chsConsumer, smSupplier, realmName, name, assignGroups));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, jaasServiceName);
}
 
Example 15
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Supplier<CallbackHandlerService> addKerberosService(OperationContext context, ModelNode kerberos, String realmName, ServiceTarget serviceTarget,
        ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName kerberosServiceName = KerberosCallbackHandler.ServiceUtil.createServiceName(realmName);
    final boolean removeRealm = KerberosAuthenticationResourceDefinition.REMOVE_REALM.resolveModelAttribute(context, kerberos).asBoolean();
    final ServiceBuilder<?> builder = serviceTarget.addService(kerberosServiceName);
    final Consumer<CallbackHandlerService> chsConsumer = builder.provides(kerberosServiceName);
    builder.setInstance(new KerberosCallbackHandler(chsConsumer, removeRealm));
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerService.ServiceUtil.requires(realmBuilder, kerberosServiceName);
}
 
Example 16
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 17
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Supplier<KeytabIdentityFactoryService> addKerberosIdentityServices(OperationContext context, ModelNode kerberos, String realmName, ServiceTarget serviceTarget,
    ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    ServiceName keyIdentityName = KeytabIdentityFactoryService.ServiceUtil.createServiceName(realmName);
    final ServiceBuilder<?> kifsBuilder = serviceTarget.addService(keyIdentityName);
    final Consumer<KeytabIdentityFactoryService> kifsConsumer = kifsBuilder.provides(keyIdentityName);
    final KeytabIdentityFactoryService kifs = new KeytabIdentityFactoryService(kifsConsumer);
    kifsBuilder.setInstance(kifs);
    kifsBuilder.setInitialMode(ON_DEMAND);

    if (kerberos.hasDefined(KEYTAB)) {
        List<Property> keytabList = kerberos.get(KEYTAB).asPropertyList();
        for (Property current : keytabList) {
            String principal = current.getName();
            ModelNode keytab = current.getValue();
            String path = KeytabResourceDefinition.PATH.resolveModelAttribute(context, keytab).asString();
            ModelNode relativeToNode = KeytabResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keytab);
            String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;
            boolean debug = KeytabResourceDefinition.DEBUG.resolveModelAttribute(context, keytab).asBoolean();
            final String[] forHostsValues;
            ModelNode forHosts = KeytabResourceDefinition.FOR_HOSTS.resolveModelAttribute(context, keytab);
            if (forHosts.isDefined()) {
                List<ModelNode> list = forHosts.asList();
                forHostsValues = new String[list.size()];
                for (int i=0;i<list.size();i++) {
                    forHostsValues[i] = list.get(i).asString();
                }
            } else {
                forHostsValues = new String[0];
            }

            ServiceName keytabName = KeytabService.ServiceUtil.createServiceName(realmName, principal);

            final ServiceBuilder<?> keytabBuilder = serviceTarget.addService(keytabName);
            final Consumer<KeytabService> ksConsumer = keytabBuilder.provides(keytabName);
            Supplier<PathManager> pathManagerSupplier = null;

            if (relativeTo != null) {
                pathManagerSupplier = keytabBuilder.requires(context.getCapabilityServiceName(PATH_MANAGER_CAPABILITY, PathManager.class));
                keytabBuilder.requires(pathName(relativeTo));
            }
            keytabBuilder.setInstance(new KeytabService(ksConsumer, pathManagerSupplier, principal, path, relativeTo, forHostsValues, debug));
            keytabBuilder.setInitialMode(ON_DEMAND);
            keytabBuilder.install();
            kifs.addKeytabSupplier(KeytabService.ServiceUtil.requires(kifsBuilder, realmName, principal));
         }
     }

     kifsBuilder.install();

     return KeytabIdentityFactoryService.ServiceUtil.requires(realmBuilder, realmName);
}
 
Example 18
Source File: ExtensionIndexService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public synchronized void start(final StartContext context) throws StartException {
    // No point in throwing away the index once it is created.
    context.getController().compareAndSetMode(ServiceController.Mode.ON_DEMAND, ServiceController.Mode.ACTIVE);
    extensions.clear();
    for (File root : extensionRoots) {
        final File[] jars = root.listFiles(new FileFilter() {
            public boolean accept(final File file) {
                return file.getName().endsWith(".jar") && !file.isDirectory();
            }
        });
        if (jars != null)
            for (File jar : jars)
                try {
                    final JarFile jarFile = new JarFile(jar);
                    try {
                        final Manifest manifest = jarFile.getManifest();
                        if (manifest == null) {
                            // jar lacks manifest file
                            continue;
                        }
                        final Attributes mainAttributes = manifest.getMainAttributes();
                        final String extensionName = mainAttributes.getValue(Attributes.Name.EXTENSION_NAME);
                        if (extensionName == null) {
                            // not an extension
                            continue;
                        }
                        final String implVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
                        final String specVersion = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
                        final String implVendorId = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR_ID);
                        jarFile.close();
                        Set<ExtensionJar> extensionJarSet = extensions.get(extensionName);
                        if (extensionJarSet == null)
                            extensions.put(extensionName, extensionJarSet = new LinkedHashSet<ExtensionJar>());

                        ModuleIdentifier moduleIdentifier = moduleIdentifier(extensionName, specVersion, implVersion,
                                implVendorId);

                        ExtensionJar extensionJar = new ExtensionJar(moduleIdentifier, implVersion, implVendorId,
                                specVersion, jar.getAbsolutePath());
                        if (extensionJarSet.contains(extensionJar)) // if the same extension is installed in two
                            // different places
                            continue;
                        // now register a module spec service for this extension
                        // this makes it available for loading
                        ExternalModuleSpecService service = new ExternalModuleSpecService(moduleIdentifier, jar);
                        ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(moduleIdentifier);
                        ServiceBuilder sb = context.getChildTarget().addService(serviceName, service);
                        sb.requires(org.jboss.as.server.deployment.Services.JBOSS_DEPLOYMENT_EXTENSION_INDEX);
                        sb.setInitialMode(Mode.ON_DEMAND);
                        sb.install();

                        ModuleLoadService.install(context.getChildTarget(), moduleIdentifier);

                        extensionJarSet.add(extensionJar);

                    } finally {
                        VFSUtils.safeClose(jarFile);
                    }
                } catch (IOException e) {
                    log.debugf("Failed to process JAR manifest for %s: %s", jar, e);
                    continue;
                }
    }
}
 
Example 19
Source File: SecurityRealmServiceUtilTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testSaslAuthenticationFactoryDigest() throws Exception {
    registerElytronProviders();
    try {
        File propsFile = createPropertyFile(TESTNAME + "-users.properties", "user1", "password1");
        ServiceTarget serviceTarget = container.subTarget();
        final Supplier<String> tmpDirSupplier = () -> tmpDir.toAbsolutePath().toString();

        // register a realm service with a properties file to perform a SASL DIGEST-MD5 login
        final ServiceName realmServiceName = SecurityRealm.ServiceUtil.createServiceName(TESTNAME);
        final ServiceBuilder<?> realmBuilder = serviceTarget.addService(realmServiceName);
        final Consumer<SecurityRealm> securityRealmConsumer = realmBuilder.provides(realmServiceName, SecurityRealm.ServiceUtil.createLegacyServiceName(TESTNAME));
        // create the properties service to check username/password
        final ServiceName propsServiceName = PropertiesCallbackHandler.ServiceUtil.createServiceName("PropertiesRealm");
        final ServiceBuilder<?> propsBuilder = serviceTarget.addService(propsServiceName);
        final Consumer<CallbackHandlerService> chsConsumer = propsBuilder.provides(propsServiceName);
        propsBuilder.setInstance(new PropertiesCallbackHandler(chsConsumer, null, TESTNAME, propsFile.getAbsolutePath(), null, true));
        propsBuilder.setInitialMode(ServiceController.Mode.ON_DEMAND);
        propsBuilder.install();
        final SecurityRealmService securityRealmService = new SecurityRealmService(
                securityRealmConsumer, null, null, null, null, tmpDirSupplier,
                Collections.singleton(CallbackHandlerService.ServiceUtil.requires(realmBuilder, propsServiceName)),
                TESTNAME, false);
        realmBuilder.setInstance(securityRealmService);
        realmBuilder.install();

        // wait for server stability
        container.awaitStability(60, TimeUnit.SECONDS);

        // get the sasl factory for DIGEST-MD5 and create the sasl server with it
        SaslAuthenticationFactory saslAuthFact = securityRealmService.getSaslAuthenticationFactory(new String[]{"DIGEST-MD5"}, true);
        Assert.assertNotNull("Server Sasl Factory is not null", saslAuthFact);
        SaslServer server = saslAuthFact.createMechanism("DIGEST-MD5");

        // now create a sasl client and perform the sasl dance
        final AuthenticationConfiguration authConfig = AuthenticationConfiguration.empty()
                        .useName("user1")
                        .usePassword("password1")
                        .useRealm(TESTNAME)
                        .setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism(SaslMechanismInformation.Names.DIGEST_MD5));
        AuthenticationContextConfigurationClient contextConfigurationClient = AccessController.doPrivileged(AuthenticationContextConfigurationClient.ACTION);
        SaslClient client = contextConfigurationClient.createSaslClient(new URI("unknown://server"), authConfig, Collections.singletonList("DIGEST-MD5"));
        Assert.assertNotNull("Sasl client is not null", client);
        Assert.assertFalse("Sasl client has no initial response", client.hasInitialResponse());
        byte[] message = server.evaluateResponse(new byte[0]);
        message = client.evaluateChallenge(message);
        server.evaluateResponse(message);
        Assert.assertTrue("Sasl server is complete", server.isComplete());
        Assert.assertEquals("Correct user is logged in", "user1", server.getAuthorizationID());
    } finally {
        removeElytronProviders();
    }
}
 
Example 20
Source File: ProcessEngineStartProcessor.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
protected void startProcessEngine(ProcessEngineXml processEngineXml, DeploymentPhaseContext phaseContext) {
  
  final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
  
  // transform configuration
  ManagedProcessEngineMetadata configuration = transformConfiguration(processEngineXml);
  
  // validate the configuration
  configuration.validate();
  
  // create service instance
  MscManagedProcessEngineController service = new MscManagedProcessEngineController(configuration);
  
  // get the service name for the process engine
  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngineXml.getName());
  
  // get service builder
  ServiceBuilder<ProcessEngine> serviceBuilder = serviceTarget.addService(serviceName, service);
  
  // make this service depend on the current phase -> makes sure it is removed with the phase service at undeployment
  serviceBuilder.addDependency(phaseContext.getPhaseServiceName());
  
  // add Service dependencies
  MscManagedProcessEngineController.initializeServiceBuilder(configuration, service, serviceBuilder, processEngineXml.getJobAcquisitionName());
  
  // make this start on demand
  serviceBuilder.setInitialMode(Mode.ACTIVE);
  
  // install the service
  serviceBuilder.install();
  
}