Search in sources :

Example 1 with SecureHash

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

the class AlterUserPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
    SecureHash newPassword = UserActions.generateSecureHash(alterUser.properties(), params, plannerContext.transactionContext(), plannerContext.nodeContext());
    userManager.alterUser(alterUser.userName(), newPassword).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) AnalyzedAlterUser(io.crate.analyze.AnalyzedAlterUser) UserActions(io.crate.user.UserActions) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) UserManager(io.crate.user.UserManager) SubQueryResults(io.crate.planner.operators.SubQueryResults) SecureHash(io.crate.user.SecureHash) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) SecureHash(io.crate.user.SecureHash)

Example 2 with SecureHash

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

the class CreateUserPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
    SecureHash newPassword = UserActions.generateSecureHash(createUser.properties(), params, plannerContext.transactionContext(), plannerContext.nodeContext());
    userManager.createUser(createUser.userName(), newPassword).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) UserActions(io.crate.user.UserActions) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) UserManager(io.crate.user.UserManager) SubQueryResults(io.crate.planner.operators.SubQueryResults) SecureHash(io.crate.user.SecureHash) AnalyzedCreateUser(io.crate.analyze.AnalyzedCreateUser) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) SecureHash(io.crate.user.SecureHash)

Example 3 with SecureHash

use of io.crate.user.SecureHash 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 4 with SecureHash

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

the class SecureHashTest method testSamePasswordsGenerateDifferentHash.

@Test
public void testSamePasswordsGenerateDifferentHash() throws Exception {
    SecureHash hash1 = SecureHash.of(PASSWORD);
    SecureHash hash2 = SecureHash.of(PASSWORD);
    assertNotEquals(hash1, hash2);
}
Also used : SecureHash(io.crate.user.SecureHash) Test(org.junit.Test)

Example 5 with SecureHash

use of io.crate.user.SecureHash 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

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