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 node data before saving to MongoDB and decrypts it when retrieving. 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, CryptoService cryptoService)
      Constructs an EncryptedMongoNodeRepositoryImpl with the given MongoOperations and CryptoService.
      Parameters:
      mongoOperations - the MongoDB operations instance
      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 s)
      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:
      s - the ID of the node to find
      Returns:
      an Optional containing the found node, or empty if not found