Interface JwksSource
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Where
JwtAuthenticator gets an issuer's JSON Web Key Set (RFC 7517) from. The application
configures the source; a token can never choose it.
Implement it to fetch the document some other way, or in tests to inject a key set without a network:
JwksSource fixed = maxBytes -> jwksJson.getBytes(StandardCharsets.UTF_8);
url(URI) and file(Path) are the supplied sources. Both read at most the
requested number of bytes and fail with an IOException otherwise. An implementation is
called by one thread at a time per authenticator, may block, and must return within a bounded
time.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]fetch(int maxBytes) Reads the key set document.static JwksSourceReads the key set from a file, for example one a deployment tool refreshes.static JwksSourceFetches the key set over HTTPS with a 5 second timeout.static JwksSourceFetches the key set withjava.net.http.
-
Method Details
-
fetch
Reads the key set document.- Parameters:
maxBytes- the longest document the caller accepts; an implementation should stop reading beyond it and fail (a longer result is rejected by the caller anyway)- Returns:
- the document, UTF-8 JSON
- Throws:
IOException- if the document cannot be read within the bounds
-
url
Fetches the key set over HTTPS with a 5 second timeout.- Parameters:
uri- anhttpsURI, orhttpto a loopback address for development- Returns:
- the source
- Throws:
IllegalArgumentException- for another scheme, user information, a fragment or no host- See Also:
-
url
Fetches the key set withjava.net.http. Redirects are never followed, so a response cannot send the client to another host: a 3xx status is a failure. Only status 200 with aapplication/jsonorapplication/jwk-set+jsoncontent type is accepted. The body is read incrementally and the exchange is abandoned as soon as it exceeds the byte limit or the timeout, which covers connecting, the response head and the whole body. No credentials, cookies or proxy authentication are sent; the connection uses the JVM's default TLS trust and proxy settings.- Parameters:
uri- anhttpsURI, orhttpto a loopback address for developmenttimeout- 100 milliseconds to 60 seconds for the whole exchange- Returns:
- the source, which owns one HTTP client for its lifetime
- Throws:
IllegalArgumentException- for another scheme, user information, a fragment, no host or a timeout out of range
-
file
Reads the key set from a file, for example one a deployment tool refreshes.- Parameters:
path- a regular file- Returns:
- the source; the file is read afresh on every fetch
-