Search in sources :

Example 1 with RemoteWriteListener

use of org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener 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 2 with RemoteWriteListener

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

the class HeartbeatTestCase method testDisableHeartbeat.

/**
 * Test that heartbeat can be set and can be disabled by setting it to 0
 *
 * @throws Exception
 */
@Test
public void testDisableHeartbeat() 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.create(RemotingOptions.HEARTBEAT_INTERVAL, 0));
            } 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(0, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
    RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
    assertNull(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)

Aggregations

Closeable (java.io.Closeable)2 InetSocketAddress (java.net.InetSocketAddress)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 SaslServerFactory (javax.security.sasl.SaslServerFactory)2 Channel (org.jboss.remoting3.Channel)2 Connection (org.jboss.remoting3.Connection)2 Endpoint (org.jboss.remoting3.Endpoint)2 OpenListener (org.jboss.remoting3.OpenListener)2 Registration (org.jboss.remoting3.Registration)2 RemoteWriteListener (org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener)2 NetworkServerProvider (org.jboss.remoting3.spi.NetworkServerProvider)2 Test (org.junit.Test)2 SimpleMapBackedSecurityRealm (org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm)2 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)2 SaslAuthenticationFactory (org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory)2 PasswordFactory (org.wildfly.security.password.PasswordFactory)2 ClearPasswordSpec (org.wildfly.security.password.spec.ClearPasswordSpec)2 ServiceLoaderSaslServerFactory (org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory)2 FutureResult (org.xnio.FutureResult)2