Search in sources :

Example 6 with SecureHash

use of io.crate.user.SecureHash in project crate by crate.

the class UserDefinitions method getSecureHash.

private static SecureHash getSecureHash(String password) {
    SecureHash hash = null;
    try {
        hash = SecureHash.of(new SecureString(password.toCharArray()));
    } catch (GeneralSecurityException e) {
    // do nothing;
    }
    assertNotNull(hash);
    return hash;
}
Also used : SecureHash(io.crate.user.SecureHash) GeneralSecurityException(java.security.GeneralSecurityException) SecureString(org.elasticsearch.common.settings.SecureString)

Example 7 with SecureHash

use of io.crate.user.SecureHash in project crate by crate.

the class SecureHashTest method testVerifyHash.

@Test
public void testVerifyHash() throws Exception {
    SecureHash hash = SecureHash.of(PASSWORD);
    assertTrue(hash.verifyHash(PASSWORD));
    assertFalse(hash.verifyHash(INVALID_PASSWORD));
}
Also used : SecureHash(io.crate.user.SecureHash) Test(org.junit.Test)

Example 8 with SecureHash

use of io.crate.user.SecureHash in project crate by crate.

the class UsersMetadataTest method testUsersMetadataFromLegacyXContent.

@Test
public void testUsersMetadataFromLegacyXContent() throws IOException {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    // Generate legacy (v1) XContent of UsersMetadata
    // { "users": [ "Ford", "Arthur" ] }
    builder.startObject();
    builder.startArray("users");
    builder.value("Ford");
    builder.value("Arthur");
    builder.endArray();
    builder.endObject();
    HashMap<String, SecureHash> expectedUsers = new HashMap<>();
    expectedUsers.put("Ford", null);
    expectedUsers.put("Arthur", null);
    XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, Strings.toString(builder));
    // start object
    parser.nextToken();
    UsersMetadata users = UsersMetadata.fromXContent(parser);
    assertEquals(users, new UsersMetadata(expectedUsers));
    // a metadata custom must consume the surrounded END_OBJECT token, no token must be left
    assertThat(parser.nextToken(), nullValue());
}
Also used : SecureHash(io.crate.user.SecureHash) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) Test(org.junit.Test)

Aggregations

SecureHash (io.crate.user.SecureHash)8 Test (org.junit.Test)4 SecureString (org.elasticsearch.common.settings.SecureString)3 Row (io.crate.data.Row)2 Row1 (io.crate.data.Row1)2 RowConsumer (io.crate.data.RowConsumer)2 OneRowActionListener (io.crate.execution.support.OneRowActionListener)2 DependencyCarrier (io.crate.planner.DependencyCarrier)2 Plan (io.crate.planner.Plan)2 PlannerContext (io.crate.planner.PlannerContext)2 SubQueryResults (io.crate.planner.operators.SubQueryResults)2 UserActions (io.crate.user.UserActions)2 UserManager (io.crate.user.UserManager)2 AnalyzedAlterUser (io.crate.analyze.AnalyzedAlterUser)1 AnalyzedCreateUser (io.crate.analyze.AnalyzedCreateUser)1 User (io.crate.user.User)1 GeneralSecurityException (java.security.GeneralSecurityException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 HashMap (java.util.HashMap)1