Class VertxJwksHandler

java.lang.Object
uk.co.spudsoft.jwtvalidatorvertx.vertx.VertxJwksHandler
All Implemented Interfaces:
io.vertx.core.Handler<io.vertx.ext.web.RoutingContext>, Closeable, AutoCloseable, JwksHandler

public class VertxJwksHandler extends Object implements io.vertx.core.Handler<io.vertx.ext.web.RoutingContext>, JwksHandler
An implementation of JwksHandler as a Vertx Handler<RoutingContext>.
Author:
njt
  • Constructor Details

    • VertxJwksHandler

      public VertxJwksHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpServer httpServer, String host, int port, String basePath, boolean withTokenBuilder)
      Constructor. The URL generated from the host, post and basePath is the issuer that will be used in tokens.
      Parameters:
      vertx - The Vertx instance to be owned by the handler. Pass in null if the lifetime of the Vertx instance is not managed by this handler.
      httpServer - The Vertx server to be owned by the handler. Pass in null if the lifetime of the Vertx server is not managed by this handler.
      host - The hostname to use in URLs generated and provided to clients.
      port - The port to use in URLs generated and provided to clients. Also the port to listen on if the httpServer is managed by this handler. This must not be zero.
      basePath - The path to use in URLs generated and provided to clients.
      withTokenBuilder - If true provide an endpoint for creating test tokens.
  • Method Details

    • setKeyCache

      public void setKeyCache(com.google.common.cache.Cache<String,AlgorithmAndKeyPair> keyCache)
      Description copied from interface: JwksHandler
      Set the key cache that the JwksHandler should use. In production use this method should be called once, in a test environment it may be called repeatedly. A JwksHandler must only access the keyCache (or anything derived from it) whilst serving an HTTP request. Between requests the JwkHandler may only hold a reference to the keyCache.
      Specified by:
      setKeyCache in interface JwksHandler
      Parameters:
      keyCache - the key cache that the JwksHandler should use.
    • getBaseUrl

      public String getBaseUrl()
      Description copied from interface: JwksHandler
      Return the base URL that the JwksHandler is listening on. This value may be used directly as the issuer claim in a token.
      Specified by:
      getBaseUrl in interface JwksHandler
      Returns:
      the base URL that the JwksHandler is listening on.
    • getPort

      public int getPort()
      Get the port that the handler is listening on.
      Returns:
      the port that the handler is listening on.
    • create

      public static VertxJwksHandler create(String host, int port, String basePath, boolean withTokenBuilder) throws IOException
      Factory method to create a new VertxJwksHandler. Note that this differs from the constructor in that it creates a dedicated Vertx instance and HttpServer. If this factory method is used then start() must be called, if the constructor is called directly then the caller may choose to control the lifetime of the HttpServer manually. The URL generated from the host, post and basePath is the issuer that will be used in tokens.
      Parameters:
      host - The hostname to use - typically this will just be localhost.
      port - The port to use - may be 0 to choose a random available port.
      basePath - The path to use - should being with a slash but not end with one.
      withTokenBuilder - If true provide an endpoint for creating test tokens.
      Returns:
      A newly created (but not yet active) VertxJwksHandler.
      Throws:
      IOException - if port <= 0 and unable to find an available port.
    • start

      public void start()
      Description copied from interface: JwksHandler
      Start listening.
      Specified by:
      start in interface JwksHandler
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • handle

      public void handle(io.vertx.ext.web.RoutingContext exchange)
      Specified by:
      handle in interface io.vertx.core.Handler<io.vertx.ext.web.RoutingContext>