X-Pack create user using Java API, wrong password

Hi,
I'm trying to create a new user using X-Pack Java API:

    final PutUserRequest putUserRequest = new PutUserRequest();
    putUserRequest .enabled(true);
    putUserRequest .username("userName");
    putUserRequest .fullName("userFullName");
    putUserRequest .passwordHash("password".hashCode());
    putUserRequest .email("a@b.com");
    putUserRequest .roles("kibana_user");

    final XPackClient xPackClient = new XPackClient(transportClient);
    xPackClient.security().putUser(putUser, null);

The user is created but when I try to log in I'm getting wrong password message. I've tried multiple ways to calculate the password hash, and sizes, but still not working.

How should the passwordHash be generated?

Regards,

You should use org.elasticsearch.xpack.security.authc.support.Hasher.BCRYPT.

Hi Tim, thank you for the reply. We actually managed to make it work using PutUserRequestBuilder.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.