use of org.apache.tuweni.toml.TomlTable in project besu by hyperledger.
the class TomlAuth method authenticate.
@Override
public void authenticate(final JsonObject authInfo, final Handler<AsyncResult<User>> resultHandler) {
final String username = authInfo.getString("username");
if (username == null) {
resultHandler.handle(Future.failedFuture("No username provided"));
return;
}
final String password = authInfo.getString("password");
if (password == null) {
resultHandler.handle(Future.failedFuture("No password provided"));
return;
}
vertx.executeBlocking(f -> {
TomlParseResult parseResult;
try {
parseResult = Toml.parse(options.getTomlPath());
} catch (IOException e) {
f.fail(e);
return;
}
final TomlTable userData = parseResult.getTableOrEmpty("Users." + username);
if (userData.isEmpty()) {
f.fail("User not found");
return;
}
final TomlUser tomlUser = readTomlUserFromTable(username, userData);
if ("".equals(tomlUser.getPassword())) {
f.fail("No password set for user");
return;
}
checkPasswordHash(password, tomlUser.getPassword(), rs -> {
if (rs.succeeded()) {
f.complete(tomlUser);
} else {
f.fail(rs.cause());
}
});
}, false, res -> {
if (res.succeeded()) {
resultHandler.handle(Future.succeededFuture((User) res.result()));
} else {
resultHandler.handle(Future.failedFuture(res.cause()));
}
});
}
use of org.apache.tuweni.toml.TomlTable in project signers by ConsenSys.
the class TomlConfigLoader method parse.
public HashicorpKeyConfig parse(final String tableName) {
final TomlParser tomlParser = new TomlParser();
final TomlParseResult tomlResult = tomlParser.getTomlParseResult(fileToParse);
TomlTable tableToParse = tomlResult;
if (tableName != null) {
tableToParse = tomlResult.getTable(tableName);
}
if (tableToParse == null) {
final String error = String.format("Toml table %s is missing", tableName);
throw new HashicorpException(constructErrorMessage(error));
}
final KeyDefinition keyDefinition = loadKeyDefinition(tableToParse);
final ConnectionParameters connectionsParams = loadConnectionParams(tableToParse);
return new HashicorpKeyConfig(connectionsParams, keyDefinition);
}
Aggregations