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 Summary
ConstructorsConstructorDescriptionVertxJwksHandler(io.vertx.core.Vertx vertx, io.vertx.core.http.HttpServer httpServer, String host, int port, String basePath, boolean withTokenBuilder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static VertxJwksHandlerFactory method to create a new VertxJwksHandler.Return the base URL that the JwksHandler is listening on.intgetPort()Get the port that the handler is listening on.voidhandle(io.vertx.ext.web.RoutingContext exchange) voidsetKeyCache(com.google.common.cache.Cache<String, AlgorithmAndKeyPair> keyCache) Set the key cache that the JwksHandler should use.voidstart()Start listening.
-
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
Description copied from interface:JwksHandlerSet 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:
setKeyCachein interfaceJwksHandler- Parameters:
keyCache- the key cache that the JwksHandler should use.
-
getBaseUrl
Description copied from interface:JwksHandlerReturn the base URL that the JwksHandler is listening on. This value may be used directly as the issuer claim in a token.- Specified by:
getBaseUrlin interfaceJwksHandler- 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 andHttpServer. If this factory method is used thenstart()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:JwksHandlerStart listening.- Specified by:
startin interfaceJwksHandler
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
handle
public void handle(io.vertx.ext.web.RoutingContext exchange) - Specified by:
handlein interfaceio.vertx.core.Handler<io.vertx.ext.web.RoutingContext>
-