Package org.saidone.repository
Class EncryptedMongoNodeRepositoryImpl
java.lang.Object
org.saidone.component.BaseComponent
org.saidone.repository.MongoNodeRepositoryImpl
org.saidone.repository.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 Summary
ConstructorsConstructorDescriptionEncryptedMongoNodeRepositoryImpl
(org.springframework.data.mongodb.core.MongoOperations mongoOperations, SecretService secretService, CryptoService cryptoService) Constructs an EncryptedMongoNodeRepositoryImpl with the given MongoOperations and CryptoService. -
Method Summary
Modifier and TypeMethodDescriptionorg.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.@NonNull Optional
<NodeWrapper> Finds a node by its ID and decrypts its JSON content if it is encrypted.<S extends NodeWrapper>
Ssave
(S entity) Saves the given node entity after encrypting its JSON content.Methods inherited from class org.saidone.repository.MongoNodeRepositoryImpl
count, count, delete, deleteAll, deleteAll, deleteAllById, deleteById, exists, existsById, findAll, findAll, findAll, findAll, findAll, findAll, findAllById, findBy, findByKv, findByNtx, findOne, init, insert, insert, saveAll
Methods inherited from class org.saidone.component.BaseComponent
setApplicationContext, shutDown, stop
-
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 instancesecretService
- service providing encryption materialcryptoService
- the service used for encryption and decryption
-
-
Method Details
-
save
Saves the given node entity after encrypting its JSON content.- Specified by:
save
in interfaceorg.springframework.data.repository.CrudRepository<NodeWrapper,
String> - Overrides:
save
in classMongoNodeRepositoryImpl
- Type Parameters:
S
- the type of the node entity- Parameters:
entity
- the node entity to save- Returns:
- the saved node entity
-
findById
Finds a node by its ID and decrypts its JSON content if it is encrypted.- Specified by:
findById
in interfaceorg.springframework.data.repository.CrudRepository<NodeWrapper,
String> - Overrides:
findById
in classMongoNodeRepositoryImpl
- 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
andto
arenull
, this method delegates toMongoNodeRepositoryImpl.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 classMongoNodeRepositoryImpl
- 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
-