use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.
the class JMSSaslExternalTest method testOutbound.
@Test
public void testOutbound() throws Exception {
final Map<String, Object> config = new LinkedHashMap<>();
config.put(TransportConstants.HOST_PROP_NAME, "localhost");
config.put(TransportConstants.PORT_PROP_NAME, String.valueOf(61616));
config.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "client_not_revoked.jks");
config.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "changeit");
config.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "truststore.jks");
config.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "changeit");
config.put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true);
config.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
final AtomicBoolean connectionOpened = new AtomicBoolean();
final AtomicBoolean authFailed = new AtomicBoolean();
EventHandler eventHandler = new EventHandler() {
@Override
public void onRemoteOpen(org.apache.qpid.proton.engine.Connection connection) throws Exception {
connectionOpened.set(true);
}
@Override
public void onAuthFailed(ProtonHandler protonHandler, org.apache.qpid.proton.engine.Connection connection) {
authFailed.set(true);
}
};
final ClientSASLFactory clientSASLFactory = new ClientSASLFactory() {
@Override
public ClientSASL chooseMechanism(String[] availableMechanims) {
ExternalMechanism externalMechanism = new ExternalMechanism();
return new ClientSASL() {
@Override
public String getName() {
return externalMechanism.getName();
}
@Override
public byte[] getInitialResponse() {
return externalMechanism.getInitialResponse();
}
@Override
public byte[] getResponse(byte[] challenge) {
return new byte[0];
}
};
}
};
ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, "myid", Collections.singletonMap(Symbol.getSymbol("myprop"), "propvalue"), 5000), Optional.of(eventHandler), clientSASLFactory);
ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server);
NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager);
connector.start();
connector.createConnection();
try {
Wait.assertEquals(1, server::getConnectionCount);
Wait.assertTrue(connectionOpened::get);
Wait.assertFalse(authFailed::get);
lifeCycleListener.stop();
Wait.assertEquals(0, server::getConnectionCount);
} finally {
lifeCycleListener.stop();
}
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.
the class JMSSaslGssapiTest method testOutboundWithSlowMech.
@Test
public void testOutboundWithSlowMech() throws Exception {
final Map<String, Object> config = new LinkedHashMap<>();
config.put(TransportConstants.HOST_PROP_NAME, "localhost");
config.put(TransportConstants.PORT_PROP_NAME, String.valueOf(AMQP_PORT));
final ClientSASLFactory clientSASLFactory = new ClientSASLFactory() {
@Override
public ClientSASL chooseMechanism(String[] availableMechanims) {
GssapiMechanism gssapiMechanism = new GssapiMechanism();
return new ClientSASL() {
@Override
public String getName() {
return gssapiMechanism.getName();
}
@Override
public byte[] getInitialResponse() {
gssapiMechanism.setUsername("client");
gssapiMechanism.setServerName("localhost");
try {
return gssapiMechanism.getInitialResponse();
} catch (Exception e) {
e.printStackTrace();
}
return new byte[0];
}
@Override
public byte[] getResponse(byte[] challenge) {
try {
// simulate a slow client
TimeUnit.SECONDS.sleep(4);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
return gssapiMechanism.getChallengeResponse(challenge);
} catch (Exception e) {
e.printStackTrace();
}
return new byte[0];
}
};
}
};
final AtomicBoolean connectionOpened = new AtomicBoolean();
final AtomicBoolean authFailed = new AtomicBoolean();
EventHandler eventHandler = new EventHandler() {
@Override
public void onRemoteOpen(org.apache.qpid.proton.engine.Connection connection) throws Exception {
connectionOpened.set(true);
}
@Override
public void onAuthFailed(ProtonHandler protonHandler, org.apache.qpid.proton.engine.Connection connection) {
authFailed.set(true);
}
};
ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, "myid", Collections.singletonMap(Symbol.getSymbol("myprop"), "propvalue"), 5000), Optional.of(eventHandler), clientSASLFactory);
ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server);
NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager);
connector.start();
connector.createConnection();
try {
Wait.assertEquals(1, server::getConnectionCount);
Wait.assertTrue(connectionOpened::get);
Wait.assertFalse(authFailed::get);
lifeCycleListener.stop();
Wait.assertEquals(0, server::getConnectionCount);
} finally {
lifeCycleListener.stop();
}
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.
the class NettyConnectorTest method testBadProtocol.
@Test
public void testBadProtocol() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
params.put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "myBadProtocol");
NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
connector.start();
Assert.assertTrue(connector.isStarted());
Assert.assertNull(connector.createConnection());
connector.close();
Assert.assertFalse(connector.isStarted());
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.
the class NettyConnectorTest method testJavaSystemPropertyOverrides.
@Test
public void testJavaSystemPropertyOverrides() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "bad path");
params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "bad password");
params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "bad path");
params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "bad password");
NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
System.setProperty(NettyConnector.JAVAX_KEYSTORE_PATH_PROP_NAME, "client-side-keystore.jks");
System.setProperty(NettyConnector.JAVAX_KEYSTORE_PASSWORD_PROP_NAME, "secureexample");
System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PATH_PROP_NAME, "client-side-truststore.jks");
System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample");
connector.start();
Assert.assertTrue(connector.isStarted());
connector.close();
Assert.assertFalse(connector.isStarted());
}
use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.
the class NettyConnectorTest method testBadCipherSuite.
@Test
public void testBadCipherSuite() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
params.put(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME, "myBadCipherSuite");
NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
connector.start();
Assert.assertTrue(connector.isStarted());
Assert.assertNull(connector.createConnection());
connector.close();
Assert.assertFalse(connector.isStarted());
}
Aggregations