| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.engine; |
| 7 |
|
| 8 |
import org.h2.security.auth.AuthenticationInfo; |
| 9 |
import org.h2.util.MathUtils; |
| 10 |
|
| 11 |
public class UserBuilder { |
| 12 |
|
| 13 |
/** |
| 14 |
* Build the database user starting from authentication informations. |
| 15 |
* |
| 16 |
* @param authenticationInfo |
| 17 |
* authentication info |
| 18 |
* @param database |
| 19 |
* target database |
| 20 |
* @param persistent |
| 21 |
* true if the user will be persisted in the database |
| 22 |
* @return user bean |
| 23 |
*/ |
| 24 |
public static User buildUser(AuthenticationInfo authenticationInfo, Database database, boolean persistent) { |
| 25 |
User user = new User(database, persistent ? database.allocateObjectId() : -1, |
| 26 |
authenticationInfo.getFullyQualifiedName(), false); |
| 27 |
// In case of external authentication fill the password hash with random |
| 28 |
// data |
| 29 |
user.setUserPasswordHash( |
| 30 |
authenticationInfo.getRealm() == null ? authenticationInfo.getConnectionInfo().getUserPasswordHash() |
| 31 |
: MathUtils.secureRandomBytes(64)); |
| 32 |
user.setTemporary(!persistent); |
| 33 |
return user; |
| 34 |
} |
| 35 |
|
| 36 |
} |