use of org.eclipse.hono.auth.HonoUser in project hono by eclipse.
the class AuthenticationServerClient method verifyPlain.
/**
* Verifies username/password credentials with a remote authentication server using SASL PLAIN.
*
* @param authzid The identity to act as.
* @param authcid The username.
* @param password The password.
* @param authenticationResultHandler The handler to invoke with the authentication result. On successful authentication,
* the result contains a JWT with the authenticated user's claims.
*/
public void verifyPlain(final String authzid, final String authcid, final String password, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) {
ProtonClientOptions options = new ProtonClientOptions();
options.setReconnectAttempts(3).setReconnectInterval(50);
options.addEnabledSaslMechanism(AuthenticationConstants.MECHANISM_PLAIN);
factory.connect(options, authcid, password, null, null, conAttempt -> {
if (conAttempt.failed()) {
authenticationResultHandler.handle(Future.failedFuture("cannot connect to Authentication service"));
} else {
final ProtonConnection openCon = conAttempt.result();
final Future<HonoUser> userTracker = Future.future();
userTracker.setHandler(s -> {
if (s.succeeded()) {
authenticationResultHandler.handle(Future.succeededFuture(s.result()));
} else {
authenticationResultHandler.handle(Future.failedFuture(s.cause()));
}
ProtonConnection con = conAttempt.result();
if (con != null) {
LOG.debug("closing connection to Authentication service");
con.close();
}
});
vertx.setTimer(5000, tid -> {
if (!userTracker.isComplete()) {
userTracker.fail("time out reached while waiting for token from Authentication service");
}
});
getToken(openCon, userTracker);
}
});
}
Aggregations