Class RegisteredJwksClientAssertionDecoderFactory
java.lang.Object
com.irurueta.authserver.authorization.api.web.clientauth.RegisteredJwksClientAssertionDecoderFactory
- All Implemented Interfaces:
org.springframework.security.oauth2.jwt.JwtDecoderFactory<org.springframework.security.oauth2.server.authorization.client.RegisteredClient>
public class RegisteredJwksClientAssertionDecoderFactory
extends Object
implements org.springframework.security.oauth2.jwt.JwtDecoderFactory<org.springframework.security.oauth2.server.authorization.client.RegisteredClient>
Creates the decoder of the client assertions of a client. A client with a registered JWK set
(
settings.client.jwks) is verified against those keys; any other client goes through the framework's
factory, which reads the keys of its jwkSetUrl (or the shared secret of client_secret_jwt). Both
add the framework's default assertion validators (issuer, subject, audience including the PAR endpoint, expiry)
and the ReplayRejectingJwtValidator. The framework's own factory caches a decoder per client forever, so
this one caches the decoders itself, per client identifier and a hash of the settings that decide the keys, and a
client whose keys or algorithm were changed is verified against the new ones.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.github.benmanes.caffeine.cache.Cache<String, org.springframework.security.oauth2.jwt.JwtDecoder> Decoders by client and settings hash.private static final StringAlgorithm of the settings hash.private static final DurationTime an unused decoder is kept.static final StringName of the custom client setting that holds the registered public JWK set as JSON.private static final longMost decoders kept.private final ReplayRejectingJwtValidatorRecords the use of an assertion and checks its lifetime.private static final charSeparator of the fields hashed into a cache key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.springframework.security.oauth2.jwt.JwtDecoderbuild(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Builds a decoder.private static StringcacheKey(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Builds the cache key: the client identifier and the hash of everything that decides which keys verify it.org.springframework.security.oauth2.jwt.JwtDecodercreateDecoder(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Returns the decoder of the assertions of a client.private static org.springframework.security.oauth2.core.OAuth2AuthenticationExceptioninvalidClient(String description) Builds theinvalid_clienterror.private org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt> validatorsOf(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Combines the default assertion validators with the replay one, failing fast so the replay validator only runs (and only records thejti) for an assertion that passed every default check.
-
Field Details
-
JWKS_SETTING
Name of the custom client setting that holds the registered public JWK set as JSON.- See Also:
-
MAX_DECODERS
private static final long MAX_DECODERSMost decoders kept.- See Also:
-
IDLE
Time an unused decoder is kept. -
SEPARATOR
private static final char SEPARATORSeparator of the fields hashed into a cache key.- See Also:
-
HASH_ALGORITHM
Algorithm of the settings hash.- See Also:
-
replayValidator
Records the use of an assertion and checks its lifetime. -
decoders
private final com.github.benmanes.caffeine.cache.Cache<String,org.springframework.security.oauth2.jwt.JwtDecoder> decodersDecoders by client and settings hash.
-
-
Constructor Details
-
RegisteredJwksClientAssertionDecoderFactory
public RegisteredJwksClientAssertionDecoderFactory()
-
-
Method Details
-
createDecoder
public org.springframework.security.oauth2.jwt.JwtDecoder createDecoder(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Returns the decoder of the assertions of a client.- Specified by:
createDecoderin interfaceorg.springframework.security.oauth2.jwt.JwtDecoderFactory<org.springframework.security.oauth2.server.authorization.client.RegisteredClient>- Parameters:
registeredClient- the client that authenticates.- Returns:
- the decoder, which also rejects a replayed assertion.
- Throws:
org.springframework.security.oauth2.core.OAuth2AuthenticationException-invalid_clientif the client has registered keys but no signing algorithm, or the keys cannot be read; the framework's factory throws it too when it has no way to find the keys.
-
build
private org.springframework.security.oauth2.jwt.JwtDecoder build(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Builds a decoder.- Parameters:
registeredClient- the client that authenticates.- Returns:
- the decoder.
-
validatorsOf
private org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt> validatorsOf(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Combines the default assertion validators with the replay one, failing fast so the replay validator only runs (and only records thejti) for an assertion that passed every default check.- Parameters:
registeredClient- the client that authenticates.- Returns:
- the validator.
-
cacheKey
private static String cacheKey(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient) Builds the cache key: the client identifier and the hash of everything that decides which keys verify it.- Parameters:
registeredClient- the client that authenticates.- Returns:
- the key.
-
invalidClient
private static org.springframework.security.oauth2.core.OAuth2AuthenticationException invalidClient(String description) Builds theinvalid_clienterror.- Parameters:
description- what is wrong.- Returns:
- the exception.
-