Class JdbcClientRegistrationRepository

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.clients.JdbcClientRegistrationRepository
All Implemented Interfaces:
ClientRegistrationRepository

@Repository public class JdbcClientRegistrationRepository extends Object implements ClientRegistrationRepository
ClientRegistrationRepository over Spring Authorization Server's RegisteredClientRepository (the JDBC one), which reads and writes the oauth2_registered_client table. The operations that repository does not offer (listing, deleting, replacing a secret) run directly on that table. The conversion between both models belongs to the RegisteredClientMapper.
  • Field Details

    • CLIENT_ROW_ID

      private static final String CLIENT_ROW_ID
      Sub-query selecting the internal id of a client by its client id.
      See Also:
    • DELETE_AUTHORIZATIONS

      private static final String DELETE_AUTHORIZATIONS
      Statement deleting the authorizations of a client.
      See Also:
    • DELETE_CONSENTS

      private static final String DELETE_CONSENTS
      Statement deleting the consents granted to a client.
      See Also:
    • registeredClientRepository

      private final org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository registeredClientRepository
      Repository that maps registered clients to rows.
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC client used for the operations the registered client repository lacks.
    • registeredClientMapper

      private final RegisteredClientMapper registeredClientMapper
      Maps between registrations and registered clients.
  • Constructor Details

    • JdbcClientRegistrationRepository

      public JdbcClientRegistrationRepository()
  • Method Details

    • findByClientId

      public Optional<ClientRegistration> findByClientId(String clientId)
      Description copied from interface: ClientRegistrationRepository
      Finds a client by its identifier.
      Specified by:
      findByClientId in interface ClientRegistrationRepository
      Parameters:
      clientId - public identifier of the client.
      Returns:
      the client, or an empty optional when it is not registered.
    • findAll

      public List<ClientRegistration> findAll()
      Description copied from interface: ClientRegistrationRepository
      Finds every registered client.
      Specified by:
      findAll in interface ClientRegistrationRepository
      Returns:
      the clients; empty when there are none.
    • save

      public void save(ClientRegistration registration, String encodedSecret)
      Description copied from interface: ClientRegistrationRepository
      Inserts a client, or replaces the settings of the stored client that has the same identifier.
      Specified by:
      save in interface ClientRegistrationRepository
      Parameters:
      registration - the client.
      encodedSecret - the encoded client secret, or null to keep the stored one (a public client has none).
    • deleteByClientId

      public void deleteByClientId(String clientId)
      Deletes a client.

      The authorizations (with their consumed refresh tokens, by cascade) and the consents granted to the client reference it by its internal id without a foreign key, so they are deleted first, in the same transaction: otherwise loading one of them later fails because its client is gone. The transaction is the caller's: use cases demarcate transactions, never the adapters.

      Specified by:
      deleteByClientId in interface ClientRegistrationRepository
      Parameters:
      clientId - public identifier of the client.
    • updateSecret

      public void updateSecret(String clientId, String encodedSecret)
      Description copied from interface: ClientRegistrationRepository
      Replaces the secret of a client.
      Specified by:
      updateSecret in interface ClientRegistrationRepository
      Parameters:
      clientId - public identifier of the client.
      encodedSecret - the new encoded secret.