Class EncryptedMongoNodeRepositoryImpl

All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.data.mongodb.repository.MongoRepository<NodeWrapper,String>, org.springframework.data.repository.CrudRepository<NodeWrapper,String>, org.springframework.data.repository.ListCrudRepository<NodeWrapper,String>, org.springframework.data.repository.ListPagingAndSortingRepository<NodeWrapper,String>, org.springframework.data.repository.PagingAndSortingRepository<NodeWrapper,String>, org.springframework.data.repository.query.QueryByExampleExecutor<NodeWrapper>, org.springframework.data.repository.Repository<NodeWrapper,String>

@Repository @ConditionalOnProperty(name={"application.service.vault.encryption.enabled","application.service.vault.encryption.metadata"}, havingValue="true") public class EncryptedMongoNodeRepositoryImpl extends MongoNodeRepositoryImpl
Repository implementation that encrypts NodeWrapper data before persisting it to MongoDB and decrypts it on retrieval.

Encryption keys are supplied by SecretService and the actual cryptographic operations are delegated to CryptoService.

The bean is activated only when both application.service.vault.encryption.enabled and application.service.vault.encryption.metadata are set to true in the application properties.

  • Constructor Details

    • EncryptedMongoNodeRepositoryImpl

      public EncryptedMongoNodeRepositoryImpl(org.springframework.data.mongodb.core.MongoOperations mongoOperations, SecretService secretService, CryptoService cryptoService)
      Constructs an EncryptedMongoNodeRepositoryImpl with the given MongoOperations and CryptoService.
      Parameters:
      mongoOperations - the MongoDB operations instance
      secretService - service providing encryption material
      cryptoService - the service used for encryption and decryption
  • Method Details

    • save

      @NonNull public <S extends NodeWrapper> S save(@NonNull S entity)
      Saves the given node entity after encrypting its JSON content.
      Specified by:
      save in interface org.springframework.data.repository.CrudRepository<NodeWrapper,String>
      Overrides:
      save in class MongoNodeRepositoryImpl
      Type Parameters:
      S - the type of the node entity
      Parameters:
      entity - the node entity to save
      Returns:
      the saved node entity
    • findById

      @NonNull public @NonNull Optional<NodeWrapper> findById(@NonNull @NonNull String id)
      Finds a node by its ID and decrypts its JSON content if it is encrypted.
      Specified by:
      findById in interface org.springframework.data.repository.CrudRepository<NodeWrapper,String>
      Overrides:
      findById in class MongoNodeRepositoryImpl
      Parameters:
      id - the ID of the node to find
      Returns:
      an Optional containing the found node, or empty if not found
    • findByArchiveDateRange

      public org.springframework.data.domain.Page<NodeWrapper> findByArchiveDateRange(Instant from, Instant to, org.springframework.data.domain.Pageable pageable)
      Retrieves node wrappers archived within the specified date range using pagination.

      When both from and to are null, this method delegates to MongoNodeRepositoryImpl.findAll(Pageable).

      If the supplied Pageable does not define a sort order, results are ordered by archive date in ascending order.

      The resulting nodes are decrypted before being returned.

      Overrides:
      findByArchiveDateRange in class MongoNodeRepositoryImpl
      Parameters:
      from - lower bound of the archive date range, inclusive. null for no lower bound.
      to - upper bound of the archive date range, inclusive. null for no upper bound.
      pageable - pagination information
      Returns:
      page of matching nodes