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

    Fields
    Modifier and Type
    Field
    Description
    private final com.github.benmanes.caffeine.cache.Cache<String,org.springframework.security.oauth2.jwt.JwtDecoder>
    Decoders by client and settings hash.
    private static final String
    Algorithm of the settings hash.
    private static final Duration
    Time an unused decoder is kept.
    static final String
    Name of the custom client setting that holds the registered public JWK set as JSON.
    private static final long
    Most decoders kept.
    Records the use of an assertion and checks its lifetime.
    private static final char
    Separator of the fields hashed into a cache key.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private org.springframework.security.oauth2.jwt.JwtDecoder
    build(org.springframework.security.oauth2.server.authorization.client.RegisteredClient registeredClient)
    Builds a decoder.
    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.
    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.
    private static org.springframework.security.oauth2.core.OAuth2AuthenticationException
    invalidClient(String description)
    Builds the invalid_client error.
    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 the jti) for an assertion that passed every default check.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • JWKS_SETTING

      public static final String 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_DECODERS
      Most decoders kept.
      See Also:
    • IDLE

      private static final Duration IDLE
      Time an unused decoder is kept.
    • SEPARATOR

      private static final char SEPARATOR
      Separator of the fields hashed into a cache key.
      See Also:
    • HASH_ALGORITHM

      private static final String HASH_ALGORITHM
      Algorithm of the settings hash.
      See Also:
    • replayValidator

      private final ReplayRejectingJwtValidator 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> decoders
      Decoders 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:
      createDecoder in interface org.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_client if 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 the jti) 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 the invalid_client error.
      Parameters:
      description - what is wrong.
      Returns:
      the exception.