use of io.vertx.ext.auth.authentication.UsernamePasswordCredentials in project vertx-web by vert-x3.
the class FormLoginHandlerImpl method authenticate.
@Override
public void authenticate(RoutingContext context, Handler<AsyncResult<User>> handler) {
HttpServerRequest req = context.request();
if (req.method() != HttpMethod.POST) {
// Must be a POST
handler.handle(Future.failedFuture(BAD_METHOD));
} else {
if (!((RoutingContextInternal) context).seenHandler(RoutingContextInternal.BODY_HANDLER)) {
handler.handle(Future.failedFuture("BodyHandler is required to process POST requests"));
} else {
MultiMap params = req.formAttributes();
String username = params.get(usernameParam);
String password = params.get(passwordParam);
if (username == null || password == null) {
handler.handle(Future.failedFuture(BAD_REQUEST));
} else {
authProvider.authenticate(new UsernamePasswordCredentials(username, password), authn -> {
if (authn.failed()) {
handler.handle(Future.failedFuture(new HttpException(401, authn.cause())));
} else {
handler.handle(authn);
}
});
}
}
}
}
Aggregations