Search in sources :

Example 1 with Registration

use of org.jboss.remoting3.Registration in project wildfly-core by wildfly.

the class RemoteDomainConnection method connectionOpened.

@Override
public void connectionOpened(final Connection connection) throws IOException {
    final Channel channel = openChannel(connection, CHANNEL_SERVICE_TYPE, configuration.getOptionMap());
    if (setChannel(channel)) {
        channel.receiveMessage(channelHandler.getReceiver());
        channel.addCloseHandler(channelHandler);
        try {
            if (runningMode == RunningMode.ADMIN_ONLY) {
                // Fetch the domain configuration
                channelHandler.executeRequest(new FetchDomainConfigurationRequest(), null).getResult().get();
            } else {
                // Start the registration process
                channelHandler.executeRequest(new RegisterHostControllerRequest(), null).getResult().get();
            }
        } catch (Exception e) {
            if (e.getCause() instanceof IOException) {
                throw (IOException) e.getCause();
            }
            throw new IOException(e);
        }
        // Registered
        registered();
    } else {
        channel.closeAsync();
    }
}
Also used : FutureManagementChannel(org.jboss.as.protocol.mgmt.FutureManagementChannel) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SlaveRegistrationException(org.jboss.as.domain.controller.SlaveRegistrationException)

Example 2 with Registration

use of org.jboss.remoting3.Registration in project wildfly-core by wildfly.

the class AbstractChannelOpenListenerService method start.

@Override
public synchronized void start(StartContext context) throws StartException {
    try {
        closed = false;
        RemotingLogger.ROOT_LOGGER.debugf("Registering channel listener for %s", channelName);
        final ManagementChannelRegistryService registry = this.registrySupplier.get();
        final Registration registration = endpointSupplier.get().registerService(channelName, this, optionMap);
        // Add to global registry
        registry.register(registration);
        trackerService = registry.getTrackerService();
    } catch (Exception e) {
        throw RemotingLogger.ROOT_LOGGER.couldNotStartChanelListener(e);
    }
}
Also used : ManagementChannelRegistryService(org.jboss.as.remoting.management.ManagementChannelRegistryService) Registration(org.jboss.remoting3.Registration) IOException(java.io.IOException) StartException(org.jboss.msc.service.StartException)

Example 3 with Registration

use of org.jboss.remoting3.Registration in project jboss-remoting by jboss-remoting.

the class EndpointImpl method addConnectionProvider.

public Registration addConnectionProvider(final String uriScheme, final ConnectionProviderFactory providerFactory, final OptionMap optionMap) throws IOException {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(RemotingPermission.ADD_CONNECTION_PROVIDER);
    }
    boolean ok = false;
    resourceUntick("Connection provider for " + uriScheme);
    try {
        final String saslProtocol = optionMap.get(RemotingOptions.SASL_PROTOCOL, RemotingOptions.DEFAULT_SASL_PROTOCOL);
        final ConnectionProviderContextImpl context = new ConnectionProviderContextImpl(uriScheme, saslProtocol);
        final ConnectionProvider provider = providerFactory.createInstance(context, optionMap, uriScheme);
        final ProtocolRegistration protocolRegistration = new ProtocolRegistration(provider, context);
        try {
            if (connectionProviders.putIfAbsent(uriScheme, protocolRegistration) != null) {
                safeClose(provider);
                throw new DuplicateRegistrationException("URI scheme '" + uriScheme + "' is already registered to a provider");
            }
            // add a resource count for close
            log.tracef("Adding connection provider registration named '%s': %s", uriScheme, provider);
            final Registration registration = new MapRegistration<ProtocolRegistration>(connectionProviders, uriScheme, protocolRegistration) {

                protected void closeAction() throws IOException {
                    try {
                        provider.closeAsync();
                    } finally {
                        super.closeAction();
                    }
                }
            };
            provider.addCloseHandler((closed, exception) -> {
                registration.closeAsync();
                closeTick1(closed);
            });
            ok = true;
            return registration;
        } finally {
            if (!ok) {
                provider.close();
            }
        }
    } finally {
        if (!ok) {
            closeTick1("Connection provider for " + uriScheme);
        }
    }
}
Also used : ConnectionProvider(org.jboss.remoting3.spi.ConnectionProvider)

Example 4 with Registration

use of org.jboss.remoting3.Registration in project jboss-remoting by jboss-remoting.

the class HeartbeatTestCase method testDefaultHeartbeat.

/**
 * Test that heartbeat can be set and can be disabled by setting it to 0
 *
 * @throws Exception
 */
@Test
public void testDefaultHeartbeat() throws Exception {
    Channel clientChannel = null;
    Channel serverChannel = null;
    Closeable streamServer = null;
    Connection connection = null;
    Registration serviceRegistration = null;
    final Endpoint endpoint = Endpoint.builder().setEndpointName("test").build();
    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(HeartbeatTestCase.class.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();
    streamServer = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE), saslAuthenticationFactory, SSLContext.getDefault());
    final FutureResult<Channel> passer = new FutureResult<Channel>();
    serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {

        public void channelOpened(final Channel channel) {
            passer.setResult(channel);
        }

        public void registrationTerminated() {
        }
    }, OptionMap.EMPTY);
    IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {

        public IoFuture<Connection> run() {
            try {
                return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    });
    connection = futureConnection.get();
    IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", OptionMap.EMPTY);
    clientChannel = futureChannel.get();
    serverChannel = passer.getIoFuture().get();
    assertNotNull(serverChannel);
    RemoteConnectionChannel remoteClientChannel = (RemoteConnectionChannel) clientChannel;
    assertEquals(RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
    RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
    assertNotNull(Utils.getInstanceValue(clientWriteListener, "heartKey"));
    afterTest(clientChannel, serverChannel, connection, serviceRegistration);
    destroy(endpoint, streamServer);
}
Also used : RemoteWriteListener(org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener) InetSocketAddress(java.net.InetSocketAddress) Closeable(java.io.Closeable) ClearPasswordSpec(org.wildfly.security.password.spec.ClearPasswordSpec) IoFuture(org.xnio.IoFuture) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) Endpoint(org.jboss.remoting3.Endpoint) FutureResult(org.xnio.FutureResult) Registration(org.jboss.remoting3.Registration) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) 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) OpenListener(org.jboss.remoting3.OpenListener) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) SaslAuthenticationFactory(org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory) PasswordFactory(org.wildfly.security.password.PasswordFactory) Test(org.junit.Test)

Example 5 with Registration

use of org.jboss.remoting3.Registration 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)

Aggregations

Channel (org.jboss.remoting3.Channel)5 OpenListener (org.jboss.remoting3.OpenListener)5 Registration (org.jboss.remoting3.Registration)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 InetSocketAddress (java.net.InetSocketAddress)3 URI (java.net.URI)3 StartException (org.jboss.msc.service.StartException)3 Connection (org.jboss.remoting3.Connection)3 Endpoint (org.jboss.remoting3.Endpoint)3 ServiceRegistrationException (org.jboss.remoting3.ServiceRegistrationException)3 NetworkServerProvider (org.jboss.remoting3.spi.NetworkServerProvider)3 SimpleMapBackedSecurityRealm (org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm)3 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)3 FutureResult (org.xnio.FutureResult)3 IoFuture (org.xnio.IoFuture)3 Closeable (java.io.Closeable)2 SaslServerFactory (javax.security.sasl.SaslServerFactory)2 RemoteEJBService (org.jboss.ejb.protocol.remote.RemoteEJBService)2 RemoteWriteListener (org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener)2