Search in sources :

Example 1 with TomlTable

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()));
        }
    });
}
Also used : TomlTable(org.apache.tuweni.toml.TomlTable) User(io.vertx.ext.auth.User) IOException(java.io.IOException) TomlParseResult(org.apache.tuweni.toml.TomlParseResult)

Example 2 with TomlTable

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);
}
Also used : TomlTable(org.apache.tuweni.toml.TomlTable) HashicorpKeyConfig(tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig) ConnectionParameters(tech.pegasys.signers.hashicorp.config.ConnectionParameters) HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) KeyDefinition(tech.pegasys.signers.hashicorp.config.KeyDefinition) TomlParseResult(org.apache.tuweni.toml.TomlParseResult)

Aggregations

TomlParseResult (org.apache.tuweni.toml.TomlParseResult)2 TomlTable (org.apache.tuweni.toml.TomlTable)2 User (io.vertx.ext.auth.User)1 IOException (java.io.IOException)1 HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 ConnectionParameters (tech.pegasys.signers.hashicorp.config.ConnectionParameters)1 HashicorpKeyConfig (tech.pegasys.signers.hashicorp.config.HashicorpKeyConfig)1 KeyDefinition (tech.pegasys.signers.hashicorp.config.KeyDefinition)1