Interface TokenCheck
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
jti), issued to a suspended account, and so on.
var seen = new ConcurrentHashMap<String, Instant>(); // pruned by a scheduled task
JwtAuthenticator.builder()...
.tokenCheck(claims -> claims.id().map(id -> seen.putIfAbsent(id, claims.expiresAt()) == null).orElse(false))
.tokenCheck(claims -> !revokedSubjects.contains(claims.subject()))
.build();
Returning false makes the authenticator answer 401 invalid_token, like any
other invalid token, without telling the client why. An IllegalArgumentException, for
example from a JwtClaims accessor on a claim of the wrong type, counts the same way. Any
other exception propagates (a 500 over HTTP): a check that cannot decide, such as an unreachable
revocation store, must not let the token through, and the operator should see it.
Implementations are shared by all requests and must be thread-safe. Checks run in registration
order and stop at the first rejection, so a check with side effects (recording a jti)
should be registered last. Each request runs its checks on its own thread; blocking calls are
acceptable but count against the request deadline.
-
Method Summary
-
Method Details
-
accept
Decides whether a verified token is acceptable.- Parameters:
claims- the verified claims- Returns:
- true to accept the token, false to reject it with 401
invalid_token
-