use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method testFilterEntriesSimple.
@Test
public void testFilterEntriesSimple() {
HostBasedAuthentication authService = new HostBasedAuthentication(HBA_1, null, SystemDefaultDnsResolver.INSTANCE);
Optional entry;
entry = authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null));
assertThat(entry.isPresent(), is(true));
entry = authService.getEntry("cr8", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null));
assertThat(entry.isPresent(), is(false));
entry = authService.getEntry("crate", new ConnectionProperties(InetAddresses.forString("10.0.0.1"), Protocol.POSTGRES, null));
assertThat(entry.isPresent(), is(false));
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method test_filter_entries_hostname.
@Test
public void test_filter_entries_hostname() {
HostBasedAuthentication authService = new HostBasedAuthentication(HBA_5, null, inMemoryResolver);
Optional entry = authService.getEntry("crate", new ConnectionProperties(InetAddresses.forString(TEST_DNS_IP), Protocol.POSTGRES, null));
assertTrue(entry.isPresent());
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method testFilterEntriesCIDR.
@Test
public void testFilterEntriesCIDR() {
Settings settings = Settings.builder().put(HBA_2).put(HBA_3).build();
HostBasedAuthentication authService = new HostBasedAuthentication(settings, null, SystemDefaultDnsResolver.INSTANCE);
Optional<Map.Entry<String, Map<String, String>>> entry;
entry = authService.getEntry("crate", new ConnectionProperties(InetAddresses.forString("123.45.67.89"), Protocol.POSTGRES, null));
assertTrue(entry.isPresent());
assertThat(entry.get().getValue().get("method"), is("fake"));
entry = authService.getEntry("cr8", new ConnectionProperties(InetAddresses.forString("127.0.0.1"), Protocol.POSTGRES, null));
assertTrue(entry.isPresent());
assertThat(entry.get().getValue().get("method"), is("md5"));
entry = authService.getEntry("cr8", new ConnectionProperties(InetAddresses.forString("123.45.67.89"), Protocol.POSTGRES, null));
assertThat(entry.isPresent(), is(false));
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (authError != null) {
ReferenceCountUtil.release(msg);
Netty4TcpChannel tcpChannel = ctx.channel().attr(Netty4Transport.CHANNEL_KEY).get();
CloseableChannel.closeChannel(tcpChannel, true);
throw authError;
}
Channel channel = ctx.channel();
InetAddress remoteAddress = Netty4HttpServerTransport.getRemoteAddress(channel);
ConnectionProperties connectionProperties = new ConnectionProperties(remoteAddress, Protocol.TRANSPORT, SSL.getSession(channel));
String userName = User.CRATE_USER.name();
var authMethod = authentication.resolveAuthenticationType(userName, connectionProperties);
if (authMethod == null) {
ReferenceCountUtil.release(msg);
authError = new AuthenticationException("No valid auth.host_based entry found for: " + remoteAddress);
Netty4TcpChannel tcpChannel = ctx.channel().attr(Netty4Transport.CHANNEL_KEY).get();
CloseableChannel.closeChannel(tcpChannel, true);
throw authError;
}
try {
authMethod.authenticate(userName, null, connectionProperties);
ctx.pipeline().remove(this);
super.channelRead(ctx, msg);
} catch (Exception e) {
ReferenceCountUtil.release(msg);
authError = e;
Netty4TcpChannel tcpChannel = ctx.channel().attr(Netty4Transport.CHANNEL_KEY).get();
CloseableChannel.closeChannel(tcpChannel, true);
throw e;
}
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class ClientCertAuthTest method setUpSsl.
@Before
public void setUpSsl() throws Exception {
var notBefore = new Date(System.currentTimeMillis() - 86400000L * 365);
var notAfter = new Date(253402300799000L);
SelfSignedCertificate ssc = new SelfSignedCertificate("example.com", notBefore, notAfter, "RSA", 2048);
sslSession = mock(SSLSession.class);
when(sslSession.getPeerCertificates()).thenReturn(new Certificate[] { ssc.cert() });
sslConnWithCert = new ConnectionProperties(InetAddresses.forString("127.0.0.1"), Protocol.POSTGRES, sslSession);
}
Aggregations