use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo.
private void doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo(Supplier<ConnectionFactory> supplier) throws Exception {
ConnectionFactory connectionFactory = supplier.get();
connectionFactory.useBlockingIo();
SslContextFactory sslContextFactory = sslContextFactory();
connectionFactory.setSslContextFactory(sslContextFactory);
SSLContext contextAcceptAll = sslContextFactory.create("connection01");
connectionFactory.setSocketFactory(contextAcceptAll.getSocketFactory());
Connection connection = connectionFactory.newConnection("connection01");
TestUtils.close(connection);
connection = connectionFactory.newConnection("connection02");
TestUtils.close(connection);
}
use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method doTestSetSslContextFactory.
private void doTestSetSslContextFactory(Supplier<ConnectionFactory> supplier) throws Exception {
ConnectionFactory connectionFactory = supplier.get();
SslContextFactory sslContextFactory = sslContextFactory();
connectionFactory.setSslContextFactory(sslContextFactory);
Connection connection = connectionFactory.newConnection("connection01");
TestUtils.close(connection);
try {
connectionFactory.newConnection("connection02");
fail("The SSL context of this client should not trust the server");
} catch (SSLHandshakeException e) {
// OK
}
}
use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.
the class SslContextFactoryTest method sslContextFactory.
private SslContextFactory sslContextFactory() throws Exception {
SSLContext contextAcceptAll = SSLContext.getInstance(tlsProtocol());
contextAcceptAll.init(null, new TrustManager[] { new TrustEverythingTrustManager() }, null);
SSLContext contextRejectAll = SSLContext.getInstance(tlsProtocol());
contextRejectAll.init(null, new TrustManager[] { new TrustNothingTrustManager() }, null);
Map<String, SSLContext> sslContexts = new HashMap<>();
sslContexts.put("connection01", contextAcceptAll);
sslContexts.put("connection02", contextRejectAll);
SslContextFactory sslContextFactory = name -> sslContexts.get(name);
return sslContextFactory;
}
Aggregations