Search in sources :

Example 1 with RemoteConnectionProviderFactory

use of org.jboss.remoting3.remote.RemoteConnectionProviderFactory in project jboss-ejb-client by wildfly.

the class DummyServer method start.

public void start() throws Exception {
    logger.info("Starting " + this);
    // create a Remoting endpoint
    final OptionMap options = OptionMap.EMPTY;
    EndpointBuilder endpointBuilder = Endpoint.builder();
    endpointBuilder.setEndpointName(this.endpointName);
    endpointBuilder.buildXnioWorker(Xnio.getInstance()).populateFromOptions(options);
    endpoint = endpointBuilder.build();
    if (startTxServer) {
        final RemotingTransactionService remotingTransactionService = RemotingTransactionService.builder().setEndpoint(endpoint).setTransactionContext(LocalTransactionContext.getCurrent()).build();
        remotingTransactionService.register();
    }
    // add a connection provider factory for the URI scheme "remote"
    // endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
    final NetworkServerProvider serverProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
    // set up a security realm called default with a user called test
    final SimpleMapBackedSecurityRealm realm = new SimpleMapBackedSecurityRealm();
    realm.setPasswordMap("test", ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "test".toCharArray()));
    // set up a security domain which has realm "default"
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    // add the security realm called "default" to the security domain
    domainBuilder.addRealm("default", realm).build();
    domainBuilder.setDefaultRealmName("default");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    SecurityDomain testDomain = domainBuilder.build();
    // set up a SaslAuthenticationFactory (i.e. a SaslServerFactory)
    SaslAuthenticationFactory saslAuthenticationFactory = SaslAuthenticationFactory.builder().setSecurityDomain(testDomain).setMechanismConfigurationSelector(mechanismInformation -> {
        switch(mechanismInformation.getMechanismName()) {
            case "ANONYMOUS":
            case "PLAIN":
                {
                    return MechanismConfiguration.EMPTY;
                }
            default:
                return null;
        }
    }).setFactory(SaslFactories.getElytronSaslServerFactory()).build();
    final OptionMap serverOptions = OptionMap.create(Options.SASL_MECHANISMS, Sequence.of("ANONYMOUS"), Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE);
    final SocketAddress bindAddress = new InetSocketAddress(InetAddress.getByName(host), port);
    this.server = serverProvider.createServer(bindAddress, serverOptions, saslAuthenticationFactory, null);
    // set up an association to handle invocations, session creations and module/toopology listensrs
    // the association makes use of a module deployment repository as well a sa  cluster registry
    Association dummyAssociation = new DummyAssociationImpl(this, deploymentRepository, clusterRegistry);
    // set up a remoting transaction service
    RemotingTransactionService.Builder txnServiceBuilder = RemotingTransactionService.builder();
    txnServiceBuilder.setEndpoint(endpoint);
    txnServiceBuilder.setTransactionContext(LocalTransactionContext.getCurrent());
    RemotingTransactionService transactionService = txnServiceBuilder.build();
    // setup remote EJB service
    RemoteEJBService remoteEJBService = RemoteEJBService.create(dummyAssociation, transactionService, DEFAULT_CLASS_FILTER);
    remoteEJBService.serverUp();
    // Register an EJB channel open listener
    OpenListener channelOpenListener = remoteEJBService.getOpenListener();
    try {
        registration = endpoint.registerService("jboss.ejb", new OpenListener() {

            @Override
            public void channelOpened(Channel channel) {
                currentConnections.add(channel);
                channelOpenListener.channelOpened(channel);
            }

            @Override
            public void registrationTerminated() {
            }
        }, OptionMap.EMPTY);
    } catch (ServiceRegistrationException e) {
        throw new Exception(e);
    }
}
Also used : RemoteEJBService(org.jboss.ejb.protocol.remote.RemoteEJBService) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) InetSocketAddress(java.net.InetSocketAddress) OpenListener(org.jboss.remoting3.OpenListener) AcceptingChannel(org.xnio.channels.AcceptingChannel) Channel(org.jboss.remoting3.Channel) EndpointBuilder(org.jboss.remoting3.EndpointBuilder) RemotingTransactionService(org.wildfly.transaction.client.provider.remoting.RemotingTransactionService) ServiceRegistrationException(org.jboss.remoting3.ServiceRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) SaslAuthenticationFactory(org.wildfly.security.auth.server.SaslAuthenticationFactory) Association(org.jboss.ejb.server.Association) ServiceRegistrationException(org.jboss.remoting3.ServiceRegistrationException) OptionMap(org.xnio.OptionMap) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 2 with RemoteConnectionProviderFactory

use of org.jboss.remoting3.remote.RemoteConnectionProviderFactory in project jboss-remoting by jboss-remoting.

the class EndpointImpl method construct.

static EndpointImpl construct(final EndpointBuilder endpointBuilder) throws IOException {
    final String endpointName = endpointBuilder.getEndpointName();
    final List<ConnectionProviderFactoryBuilder> factoryBuilders = endpointBuilder.getConnectionProviderFactoryBuilders();
    final EndpointImpl endpoint;
    OptionMap defaultConnectionOptionMap = endpointBuilder.getDefaultConnectionOptionMap();
    final List<ConnectionBuilder> connectionBuilders = endpointBuilder.getConnectionBuilders();
    final Map<URI, OptionMap> connectionOptions = new HashMap<>();
    if (connectionBuilders != null)
        for (ConnectionBuilder connectionBuilder : connectionBuilders) {
            final URI destination = connectionBuilder.getDestination();
            final OptionMap.Builder optionBuilder = OptionMap.builder();
            if (connectionBuilder.getHeartbeatInterval() != -1) {
                optionBuilder.set(RemotingOptions.HEARTBEAT_INTERVAL, connectionBuilder.getHeartbeatInterval());
            } else {
                optionBuilder.set(RemotingOptions.HEARTBEAT_INTERVAL, defaultConnectionOptionMap.get(RemotingOptions.HEARTBEAT_INTERVAL));
            }
            if (connectionBuilder.getReadTimeout() != -1) {
                optionBuilder.set(Options.READ_TIMEOUT, connectionBuilder.getReadTimeout());
            } else {
                optionBuilder.set(Options.READ_TIMEOUT, defaultConnectionOptionMap.get(Options.READ_TIMEOUT));
            }
            if (connectionBuilder.getWriteTimeout() != -1) {
                optionBuilder.set(Options.WRITE_TIMEOUT, connectionBuilder.getWriteTimeout());
            } else {
                optionBuilder.set(Options.WRITE_TIMEOUT, defaultConnectionOptionMap.get(Options.WRITE_TIMEOUT));
            }
            if (connectionBuilder.getIPTrafficClass() != -1) {
                optionBuilder.set(Options.IP_TRAFFIC_CLASS, connectionBuilder.getIPTrafficClass());
            }
            if (connectionBuilder.isSetTcpKeepAlive()) {
                optionBuilder.set(Options.KEEP_ALIVE, connectionBuilder.isTcpKeepAlive());
            } else {
                optionBuilder.set(Options.KEEP_ALIVE, defaultConnectionOptionMap.get(Options.KEEP_ALIVE));
            }
            connectionOptions.put(destination, optionBuilder.getMap());
        }
    XnioWorker xnioWorker = endpointBuilder.getXnioWorker();
    if (xnioWorker == null) {
        final XnioWorker.Builder workerBuilder = endpointBuilder.getWorkerBuilder();
        if (workerBuilder == null) {
            xnioWorker = XnioWorker.getContextManager().get();
            endpoint = new EndpointImpl(xnioWorker, false, endpointName, connectionOptions, defaultConnectionOptionMap);
        } else {
            final AtomicReference<EndpointImpl> endpointRef = new AtomicReference<EndpointImpl>();
            workerBuilder.setDaemon(true);
            workerBuilder.setWorkerName(endpointName == null ? "Remoting (anonymous)" : "Remoting \"" + endpointName + "\"");
            workerBuilder.setTerminationTask(() -> {
                final EndpointImpl e = endpointRef.getAndSet(null);
                if (e != null) {
                    e.closeComplete();
                }
            });
            xnioWorker = workerBuilder.build();
            endpointRef.set(endpoint = new EndpointImpl(xnioWorker, true, endpointName, connectionOptions.isEmpty() ? Collections.emptyMap() : connectionOptions, defaultConnectionOptionMap));
        }
    } else {
        endpoint = new EndpointImpl(xnioWorker, false, endpointName, connectionOptions.isEmpty() ? Collections.emptyMap() : connectionOptions, defaultConnectionOptionMap);
    }
    boolean ok = false;
    try {
        if (factoryBuilders != null)
            for (ConnectionProviderFactoryBuilder factoryBuilder : factoryBuilders) {
                final String className = factoryBuilder.getClassName();
                final String moduleName = factoryBuilder.getModuleName();
                final ClassLoader classLoader;
                if (moduleName != null) {
                    classLoader = ModuleLoader.getClassLoaderFromModule(moduleName);
                } else if (className == null) {
                    throw new IllegalArgumentException("Either class or module name required for connection provider factory");
                } else {
                    classLoader = EndpointImpl.class.getClassLoader();
                }
                if (className == null) {
                    final ServiceLoader<ConnectionProviderFactory> loader = ServiceLoader.load(ConnectionProviderFactory.class, classLoader);
                    for (ConnectionProviderFactory factory : loader) {
                        endpoint.addConnectionProvider(factoryBuilder.getScheme(), factory, OptionMap.EMPTY);
                        for (String alias : factoryBuilder.getAliases()) {
                            endpoint.addConnectionProvider(alias, factory, OptionMap.EMPTY);
                        }
                    }
                } else
                    try {
                        final Class<? extends ConnectionProviderFactory> factoryClass = classLoader.loadClass(className).asSubclass(ConnectionProviderFactory.class);
                        final ConnectionProviderFactory factory = factoryClass.newInstance();
                        endpoint.addConnectionProvider(factoryBuilder.getScheme(), factory, OptionMap.EMPTY);
                        for (String alias : factoryBuilder.getAliases()) {
                            endpoint.addConnectionProvider(alias, factory, OptionMap.EMPTY);
                        }
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                        throw new IllegalArgumentException("Unable to load connection provider factory class '" + className + "'", e);
                    }
            }
        // remote (SSL is explicit in URL)
        final RemoteConnectionProviderFactory remoteConnectionProviderFactory = new RemoteConnectionProviderFactory();
        endpoint.addConnectionProvider("remote", remoteConnectionProviderFactory, OptionMap.create(Options.SSL_ENABLED, Boolean.TRUE, Options.SSL_STARTTLS, Boolean.TRUE));
        endpoint.addConnectionProvider("remote+tls", remoteConnectionProviderFactory, OptionMap.create(Options.SECURE, Boolean.TRUE));
        // old (SSL is config-based)
        endpoint.addConnectionProvider("remoting", remoteConnectionProviderFactory, OptionMap.create(Options.SSL_ENABLED, Boolean.TRUE, Options.SSL_STARTTLS, Boolean.TRUE));
        // http - SSL is handled by the HTTP layer
        final HttpUpgradeConnectionProviderFactory httpUpgradeConnectionProviderFactory = new HttpUpgradeConnectionProviderFactory();
        endpoint.addConnectionProvider("remote+http", httpUpgradeConnectionProviderFactory, OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE, Options.SSL_STARTTLS, Boolean.TRUE));
        endpoint.addConnectionProvider("remote+https", httpUpgradeConnectionProviderFactory, OptionMap.create(Options.SECURE, Boolean.TRUE));
        // old
        endpoint.addConnectionProvider("http-remoting", httpUpgradeConnectionProviderFactory, OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE, Options.SSL_STARTTLS, Boolean.TRUE));
        endpoint.addConnectionProvider("https-remoting", httpUpgradeConnectionProviderFactory, OptionMap.create(Options.SECURE, Boolean.TRUE));
        ok = true;
        return endpoint;
    } finally {
        if (!ok)
            endpoint.closeAsync();
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) XnioWorker(org.xnio.XnioWorker) URI(java.net.URI) ConnectionProviderFactory(org.jboss.remoting3.spi.ConnectionProviderFactory) HttpUpgradeConnectionProviderFactory(org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory) RemoteConnectionProviderFactory(org.jboss.remoting3.remote.RemoteConnectionProviderFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServiceLoader(java.util.ServiceLoader) OptionMap(org.xnio.OptionMap) RemoteConnectionProviderFactory(org.jboss.remoting3.remote.RemoteConnectionProviderFactory) HttpUpgradeConnectionProviderFactory(org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory)

Example 3 with RemoteConnectionProviderFactory

use of org.jboss.remoting3.remote.RemoteConnectionProviderFactory in project jboss-remoting by jboss-remoting.

the class CloseConnectingEndpointTestCase method test.

@Test
public void test() throws Exception {
    // create endpoint, auth provider, etc, create server
    endpoint = Endpoint.builder().setEndpointName("test").build();
    endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
    NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
    domainBuilder.addRealm("mainRealm", mainRealm).build();
    domainBuilder.setDefaultRealmName("mainRealm");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
    mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
    final SaslServerFactory saslServerFactory = new ServiceLoaderSaslServerFactory(getClass().getClassLoader());
    final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder();
    builder.setSecurityDomain(domainBuilder.build());
    builder.setFactory(saslServerFactory);
    builder.setMechanismConfigurationSelector(mechanismInformation -> SaslMechanismInformation.Names.SCRAM_SHA_256.equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null);
    final SaslAuthenticationFactory saslAuthenticationFactory = builder.build();
    networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SASL_MECHANISMS, Sequence.of("CRAM-MD5")), saslAuthenticationFactory, SSLContext.getDefault());
    // create connect and close endpoint threads
    Connect connectRunnable = new Connect(endpoint);
    Thread connectThread = new Thread(connectRunnable);
    Thread closeEndpointThread = new Thread(new CloseEndpoint(endpoint));
    // execute and run threads
    connectThread.start();
    closeEndpointThread.start();
    connectThread.join();
    closeEndpointThread.join();
    // connect runnable is supposed to have failed if race condition was safely reproduced
    // (see CloseConnectingEndpointTestCase.btm for further info)
    assertTrue(connectRunnable.hasFailed());
}
Also used : ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) SaslServerFactory(javax.security.sasl.SaslServerFactory) ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) InetSocketAddress(java.net.InetSocketAddress) ClearPasswordSpec(org.wildfly.security.password.spec.ClearPasswordSpec) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) SaslAuthenticationFactory(org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory) PasswordFactory(org.wildfly.security.password.PasswordFactory) RemoteConnectionProviderFactory(org.jboss.remoting3.remote.RemoteConnectionProviderFactory) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 RemoteConnectionProviderFactory (org.jboss.remoting3.remote.RemoteConnectionProviderFactory)2 NetworkServerProvider (org.jboss.remoting3.spi.NetworkServerProvider)2 SimpleMapBackedSecurityRealm (org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm)2 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)2 OptionMap (org.xnio.OptionMap)2 IOException (java.io.IOException)1 SocketAddress (java.net.SocketAddress)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 ServiceLoader (java.util.ServiceLoader)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SaslServerFactory (javax.security.sasl.SaslServerFactory)1 RemoteEJBService (org.jboss.ejb.protocol.remote.RemoteEJBService)1 Association (org.jboss.ejb.server.Association)1 Channel (org.jboss.remoting3.Channel)1 EndpointBuilder (org.jboss.remoting3.EndpointBuilder)1