Search in sources :

Example 16 with SecureString

use of org.elasticsearch.common.settings.SecureString in project crate by crate.

the class PostgresWireProtocolTest method testPasswordMessageAuthenticationProcess.

@Test
public void testPasswordMessageAuthenticationProcess() throws Exception {
    PostgresWireProtocol ctx = new PostgresWireProtocol(mock(SQLOperations.class), sessionContext -> AccessControl.DISABLED, new Authentication() {

        @Override
        public AuthenticationMethod resolveAuthenticationType(String user, ConnectionProperties connectionProperties) {
            return new AuthenticationMethod() {

                @Nullable
                @Override
                public User authenticate(String userName, @Nullable SecureString passwd, ConnectionProperties connProperties) {
                    return null;
                }

                @Override
                public String name() {
                    return "password";
                }
            };
        }
    }, null);
    channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
    ByteBuf respBuf;
    ByteBuf buffer = Unpooled.buffer();
    ClientMessages.sendStartupMessage(buffer, "doc");
    channel.writeInbound(buffer);
    respBuf = channel.readOutbound();
    try {
        // AuthenticationCleartextPassword
        assertThat((char) respBuf.readByte(), is('R'));
    } finally {
        respBuf.release();
    }
    buffer = Unpooled.buffer();
    ClientMessages.sendPasswordMessage(buffer, "pw");
    channel.writeInbound(buffer);
    respBuf = channel.readOutbound();
    try {
        // Auth OK
        assertThat((char) respBuf.readByte(), is('R'));
    } finally {
        respBuf.release();
    }
}
Also used : User(io.crate.user.User) Authentication(io.crate.auth.Authentication) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SecureString(org.elasticsearch.common.settings.SecureString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticationMethod(io.crate.auth.AuthenticationMethod) ByteBuf(io.netty.buffer.ByteBuf) SQLOperations(io.crate.action.sql.SQLOperations) Nullable(javax.annotation.Nullable) SecureString(org.elasticsearch.common.settings.SecureString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 17 with SecureString

use of org.elasticsearch.common.settings.SecureString in project crate by crate.

the class UserAuthenticationMethodTest method testPasswordAuthenticationForNonExistingUser.

@Test
public void testPasswordAuthenticationForNonExistingUser() throws Exception {
    PasswordAuthenticationMethod pwAuth = new PasswordAuthenticationMethod(this::userLookup);
    expectedException.expectMessage("password authentication failed for user \"cr8\"");
    pwAuth.authenticate("cr8", new SecureString("pw".toCharArray()), null);
}
Also used : SecureString(org.elasticsearch.common.settings.SecureString) Test(org.junit.Test)

Example 18 with SecureString

use of org.elasticsearch.common.settings.SecureString in project crate by crate.

the class UserAuthenticationMethodTest method testPasswordAuthentication.

public void testPasswordAuthentication() throws Exception {
    PasswordAuthenticationMethod pwAuth = new PasswordAuthenticationMethod(this::userLookup);
    assertThat(pwAuth.name(), is("password"));
    assertThat(pwAuth.authenticate("crate", new SecureString("pw".toCharArray()), null).name(), is("crate"));
}
Also used : SecureString(org.elasticsearch.common.settings.SecureString)

Aggregations

SecureString (org.elasticsearch.common.settings.SecureString)18 Test (org.junit.Test)7 Symbol (io.crate.expression.symbol.Symbol)4 GenericProperties (io.crate.sql.tree.GenericProperties)4 SecureHash (io.crate.user.SecureHash)3 User (io.crate.user.User)3 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 Tuple (io.crate.common.collections.Tuple)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Nullable (javax.annotation.Nullable)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 Settings (org.elasticsearch.common.settings.Settings)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 Protocol (com.amazonaws.Protocol)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 SQLOperations (io.crate.action.sql.SQLOperations)1 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)1 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)1