Search in sources :

Example 11 with HonoUser

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);
        }
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) HonoUser(org.eclipse.hono.auth.HonoUser) ProtonClientOptions(io.vertx.proton.ProtonClientOptions)

Aggregations

HonoUser (org.eclipse.hono.auth.HonoUser)11 ProtonConnection (io.vertx.proton.ProtonConnection)4 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)4 Future (io.vertx.core.Future)2 Vertx (io.vertx.core.Vertx)2 JsonObject (io.vertx.core.json.JsonObject)2 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)2 ProtonReceiver (io.vertx.proton.ProtonReceiver)2 Objects (java.util.Objects)2 Source (org.apache.qpid.proton.amqp.transport.Source)2 Message (org.apache.qpid.proton.message.Message)2 MessageHelper (org.eclipse.hono.util.MessageHelper)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AsyncResult (io.vertx.core.AsyncResult)1 Handler (io.vertx.core.Handler)1 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 DecodeException (io.vertx.core.json.DecodeException)1 ProtonDelivery (io.vertx.proton.ProtonDelivery)1 ProtonHelper (io.vertx.proton.ProtonHelper)1 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)1