Search in sources :

Example 11 with ConnectionProperties

use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.

the class HostBasedAuthenticationTest method testPSQLSslOption.

@Test
public void testPSQLSslOption() {
    Settings sslConfig;
    HostBasedAuthentication authService;
    sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.OPTIONAL.VALUE).build();
    authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), not(Optional.empty()));
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), not(Optional.empty()));
    sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.REQUIRED.VALUE).build();
    authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), is(Optional.empty()));
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), not(Optional.empty()));
    sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.NEVER.VALUE).build();
    authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), not(Optional.empty()));
    assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), is(Optional.empty()));
}
Also used : ConnectionProperties(io.crate.protocols.postgres.ConnectionProperties) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 12 with ConnectionProperties

use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.

the class HostBasedAuthenticationTest method testEmptyHbaConf.

@Test
public void testEmptyHbaConf() {
    HostBasedAuthentication authService = new HostBasedAuthentication(Settings.EMPTY, null, SystemDefaultDnsResolver.INSTANCE);
    AuthenticationMethod method = authService.resolveAuthenticationType("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null));
    assertNull(method);
}
Also used : ConnectionProperties(io.crate.protocols.postgres.ConnectionProperties) Test(org.junit.Test)

Example 13 with ConnectionProperties

use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.

the class HostBasedAuthenticationTest method cert_method_resolved_when_ssl_on_and_keystore_configured.

@Test
public void cert_method_resolved_when_ssl_on_and_keystore_configured() throws Exception {
    // This test makes sure that "ssl: on" from crate.yml in test resources
    // is correctly mapped to the corresponding enum value despite on yml treats "on" as "true".
    Path config = getAbsoluteFilePathFromClassPath("org/elasticsearch/node/config").toPath();
    HashMap<String, String> settings = new HashMap<>();
    settings.put("path.home", ".");
    settings.put("path.conf", config.toAbsolutePath().toString());
    settings.put("stats.enabled", "false");
    // Settings are intentionally created not by directly putting properties
    // but by using InternalSettingsPreparer.prepareEnvironment to trigger yml parsing.
    Settings finalSettings = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, settings, config, () -> "node1").settings();
    // 'on' becomes 'true' -
    assertThat(finalSettings.get("auth.host_based.config.0.ssl"), is("true"));
    HostBasedAuthentication hba = new HostBasedAuthentication(finalSettings, null, SystemDefaultDnsResolver.INSTANCE);
    AuthenticationMethod authMethod = hba.resolveAuthenticationType("crate", new ConnectionProperties(InetAddresses.forString("1.2.3.4"), Protocol.TRANSPORT, mock(SSLSession.class)));
    assertThat(authMethod, instanceOf(ClientCertAuth.class));
    AuthenticationMethod authMethod2 = hba.resolveAuthenticationType("crate", new ConnectionProperties(InetAddresses.forString("1.2.3.4"), Protocol.TRANSPORT, mock(SSLSession.class)));
    assertThat(authMethod2, instanceOf(ClientCertAuth.class));
}
Also used : Path(java.nio.file.Path) AuthenticationWithSSLIntegrationTest.getAbsoluteFilePathFromClassPath(io.crate.auth.AuthenticationWithSSLIntegrationTest.getAbsoluteFilePathFromClassPath) HashMap(java.util.HashMap) ConnectionProperties(io.crate.protocols.postgres.ConnectionProperties) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 14 with ConnectionProperties

use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.

the class ClientCertAuthTest method testMissingClientCert.

@Test
public void testMissingClientCert() throws Exception {
    SSLSession sslSession = mock(SSLSession.class);
    when(sslSession.getPeerCertificates()).thenReturn(new Certificate[0]);
    ConnectionProperties connectionProperties = new ConnectionProperties(InetAddresses.forString("127.0.0.1"), Protocol.POSTGRES, sslSession);
    ClientCertAuth clientCertAuth = new ClientCertAuth(userName -> exampleUser);
    expectedException.expectMessage("Client certificate authentication failed for user \"example.com\"");
    clientCertAuth.authenticate("example.com", null, connectionProperties);
}
Also used : ConnectionProperties(io.crate.protocols.postgres.ConnectionProperties) SSLSession(javax.net.ssl.SSLSession) Test(org.junit.Test)

Aggregations

ConnectionProperties (io.crate.protocols.postgres.ConnectionProperties)14 Test (org.junit.Test)10 Settings (org.elasticsearch.common.settings.Settings)5 SSLSession (javax.net.ssl.SSLSession)4 InetAddress (java.net.InetAddress)2 Optional (java.util.Optional)2 AuthenticationWithSSLIntegrationTest.getAbsoluteFilePathFromClassPath (io.crate.auth.AuthenticationWithSSLIntegrationTest.getAbsoluteFilePathFromClassPath)1 User (io.crate.user.User)1 Channel (io.netty.channel.Channel)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 AuthenticationException (javax.security.sasl.AuthenticationException)1 CloseableChannel (org.elasticsearch.common.network.CloseableChannel)1 SecureString (org.elasticsearch.common.settings.SecureString)1 Before (org.junit.Before)1