Search in sources :

Example 6 with SecureString

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

the class UserAuthenticationMethodTest method testPasswordAuthenticationWrongPassword.

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

Example 7 with SecureString

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

the class UserAuthenticationMethodTest method userLookup.

private User userLookup(String userName) {
    if (userName.equals("crate")) {
        User user = null;
        try {
            SecureHash pwHash = SecureHash.of(new SecureString("pw".toCharArray()));
            user = User.of("crate", Collections.emptySet(), pwHash);
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        // do nothing
        }
        assertNotNull(user);
        return user;
    }
    return null;
}
Also used : User(io.crate.user.User) SecureHash(io.crate.user.SecureHash) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SecureString(org.elasticsearch.common.settings.SecureString)

Example 8 with SecureString

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

the class UserActionsTest method testNoPasswordIfPropertyIsNull.

@Test
public void testNoPasswordIfPropertyIsNull() throws Exception {
    GenericProperties<Symbol> properties = new GenericProperties<>(Map.of("password", Literal.of(DataTypes.UNDEFINED, null)));
    SecureString password = UserActions.getUserPasswordProperty(properties, Row.EMPTY, txnCtx, nodeCtx);
    assertNull(password);
}
Also used : Symbol(io.crate.expression.symbol.Symbol) GenericProperties(io.crate.sql.tree.GenericProperties) SecureString(org.elasticsearch.common.settings.SecureString) Test(org.junit.Test)

Example 9 with SecureString

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

the class UserActionsTest method testUserPasswordProperty.

@Test
public void testUserPasswordProperty() throws Exception {
    GenericProperties<Symbol> properties = new GenericProperties<>(Map.of("password", Literal.of("my-pass")));
    SecureString password = UserActions.getUserPasswordProperty(properties, Row.EMPTY, txnCtx, nodeCtx);
    assertEquals(new SecureString("my-pass".toCharArray()), password);
}
Also used : Symbol(io.crate.expression.symbol.Symbol) GenericProperties(io.crate.sql.tree.GenericProperties) SecureString(org.elasticsearch.common.settings.SecureString) Test(org.junit.Test)

Example 10 with SecureString

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

the class SecureHashTest method testNonAsciiChars.

@Test
public void testNonAsciiChars() throws InvalidKeySpecException, NoSuchAlgorithmException {
    SecureString pw = new SecureString("ฯ€รค๐Ÿ˜‰ู€ุต".toCharArray());
    SecureHash hash = SecureHash.of(pw);
    assertTrue(hash.verifyHash(pw));
}
Also used : SecureHash(io.crate.user.SecureHash) SecureString(org.elasticsearch.common.settings.SecureString) Test(org.junit.Test)

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