class AuthenticationUtils {

  public static void getUser(
      final Optional<AuthenticationService> authenticationService,
      final String token,
      final Handler<Optional<User>> handler) {
    try {
      if (authenticationService.isEmpty()) {
        handler.handle(Optional.empty());
      } else {
        authenticationService
            .get()
            .getJwtAuthProvider()
            .authenticate(
                new JsonObject().put("jwt", token),
                (r) -> {
                  if (r.succeeded()) {
                    final Optional<User> user = Optional.ofNullable(r.result());
                    validateExpiryExists(user);
                    handler.handle(user);
                  } else {
                    LOG.debug("Invalid JWT token", r.cause());
                    handler.handle(Optional.empty());
                  }
                });
      }
    } catch (Exception e) {
      handler.handle(Optional.empty());
    }
  }

}