Class SecureElasticRepositoryBase<TEntity>
- Namespace
- Excalibur.Data.ElasticSearch
- Assembly
- Excalibur.Data.ElasticSearch.dll
Security-enhanced base class for Elasticsearch repositories with comprehensive data protection, access controls, audit logging, and threat detection capabilities.
public abstract class SecureElasticRepositoryBase<TEntity> : ElasticRepositoryBase<TEntity>, IInitializeElasticIndex, IElasticRepositoryBase<TEntity>, IElasticRepositoryBaseQuery<TEntity> where TEntity : class
Type Parameters
TEntityThe type of entity managed by this repository.
- Inheritance
-
ElasticRepositoryBase<TEntity>SecureElasticRepositoryBase<TEntity>
- Implements
-
IElasticRepositoryBase<TEntity>IElasticRepositoryBaseQuery<TEntity>
- Inherited Members
Remarks
Initializes a new instance of the SecureElasticRepositoryBase<TEntity> class.
Constructors
SecureElasticRepositoryBase(ElasticsearchClient, IElasticsearchFieldEncryptor, IElasticsearchSecurityAuditor, IElasticsearchSecurityMonitor, IOptions<ElasticsearchSecurityOptions>, ILogger<SecureElasticRepositoryBase<TEntity>>)
Security-enhanced base class for Elasticsearch repositories with comprehensive data protection, access controls, audit logging, and threat detection capabilities.
protected SecureElasticRepositoryBase(ElasticsearchClient client, IElasticsearchFieldEncryptor fieldEncryptor, IElasticsearchSecurityAuditor securityAuditor, IElasticsearchSecurityMonitor securityMonitor, IOptions<ElasticsearchSecurityOptions> securityOptions, ILogger<SecureElasticRepositoryBase<TEntity>> logger)
Parameters
clientElasticsearchClientThe Elasticsearch client for data operations.
fieldEncryptorIElasticsearchFieldEncryptorThe field encryption service for sensitive data protection.
securityAuditorIElasticsearchSecurityAuditorThe security auditing service for compliance and monitoring.
securityMonitorIElasticsearchSecurityMonitorThe security monitoring service for threat detection.
securityOptionsIOptions<ElasticsearchSecurityOptions>The security configuration options.
loggerILogger<SecureElasticRepositoryBase<TEntity>>The logger for security and operational events.
Remarks
Initializes a new instance of the SecureElasticRepositoryBase<TEntity> class.
Exceptions
- ArgumentNullException
Thrown when required dependencies are null.
Methods
GetCurrentSourceIpAddress()
Gets the current source IP address from the request context.
protected abstract string? GetCurrentSourceIpAddress()
Returns
Remarks
Implement this method to provide the source IP from your application's HTTP context
(e.g., IHttpContextAccessor.HttpContext.Connection.RemoteIpAddress).
Exceptions
- ArgumentNullException
Thrown when required dependencies are null.
GetCurrentUserId()
Gets the current user identifier from the security context.
protected abstract string? GetCurrentUserId()
Returns
Remarks
Implement this method to provide user identity from your application's authentication context
(e.g., ClaimsPrincipal, IHttpContextAccessor, or a custom identity provider).
Exceptions
- ArgumentNullException
Thrown when required dependencies are null.
IsIpInRange(string, string)
Checks whether an IP address falls within a configured range or matches it exactly.
protected virtual bool IsIpInRange(string ipAddress, string rangeOrIp)
Parameters
ipAddressstringThe IP address to check.
rangeOrIpstringThe CIDR range or literal address to match against.
Returns
Remarks
The default handles both forms used in the whitelist and blacklist: CIDR notation
(10.0.0.0/24, 2001:db8::/32) and a single literal address, for IPv4 and IPv6 alike.
Addresses are compared parsed rather than as text, so equivalent spellings of the same address
match. Override only for a matching rule the framework cannot express — a correct override is
harder than it looks, and this predicate decides whether a caller is blocked.
An entry that cannot be parsed does not match, and is logged as a warning: a malformed blacklist entry would otherwise silently fail to block, with nothing to show for it.
Only called when NetworkSecurity is enabled.
Exceptions
- ArgumentNullException
Thrown when required dependencies are null.
SecureDeleteAsync(string, CancellationToken)
Securely deletes a document with comprehensive audit logging.
public Task<DeleteResponse> SecureDeleteAsync(string id, CancellationToken cancellationToken)
Parameters
idstringThe document identifier to delete.
cancellationTokenCancellationTokenThe cancellation token to monitor for cancellation requests.
Returns
- Task<DeleteResponse>
A task representing the asynchronous deletion operation with security enhancements applied.
Exceptions
- SecurityException
Thrown when security validation fails or access is denied.
- ArgumentException
SecureGetByIdAsync(string, CancellationToken)
Securely retrieves a document by ID with decryption and access logging.
[RequiresUnreferencedCode("Field-level encryption decrypts the stored document, which deserializes it reflectively over its members; trimming may remove them.")]
[RequiresDynamicCode("Field-level encryption decrypts the stored document, which deserializes it reflectively, generating serialization code for its type at run time.")]
public Task<TEntity?> SecureGetByIdAsync(string id, CancellationToken cancellationToken)
Parameters
idstringThe document identifier to retrieve.
cancellationTokenCancellationTokenThe cancellation token to monitor for cancellation requests.
Returns
- Task<TEntity>
The decrypted document if found and accessible, null otherwise.
Exceptions
- SecurityException
Thrown when security validation fails or access is denied.
- ArgumentException
SecureIndexAsync(TEntity, CancellationToken)
Securely indexes a document with field-level encryption and comprehensive audit logging.
[RequiresUnreferencedCode("Field-level encryption encrypts the document's fields, which serializes it reflectively over its members; trimming may remove them.")]
[RequiresDynamicCode("Field-level encryption encrypts the document's fields, which serializes it reflectively, generating serialization code for its type at run time.")]
public Task<IndexResponse> SecureIndexAsync(TEntity document, CancellationToken cancellationToken)
Parameters
documentTEntityThe document to index with security processing.
cancellationTokenCancellationTokenThe cancellation token to monitor for cancellation requests.
Returns
- Task<IndexResponse>
A task representing the asynchronous indexing operation with security enhancements applied.
Exceptions
- SecurityException
Thrown when security validation fails or access is denied.
SecureSearchAsync(Action<SearchRequestDescriptor<TEntity>>, CancellationToken)
Performs a secure search operation with result decryption and access logging.
[RequiresUnreferencedCode("Field-level encryption decrypts each hit, which deserializes it reflectively over its members; trimming may remove them.")]
[RequiresDynamicCode("Field-level encryption decrypts each hit, which deserializes it reflectively, generating serialization code for its type at run time.")]
public Task<SearchResponse<TEntity>> SecureSearchAsync(Action<SearchRequestDescriptor<TEntity>> searchRequest, CancellationToken cancellationToken)
Parameters
searchRequestAction<SearchRequestDescriptor<TEntity>>The search request configuration.
cancellationTokenCancellationTokenThe cancellation token to monitor for cancellation requests.
Returns
- Task<SearchResponse<TEntity>>
The search results with decrypted documents if encryption is enabled.
Exceptions
- SecurityException
Thrown when security validation fails or access is denied.
SecureUpdateAsync(string, TEntity, CancellationToken)
Securely updates a document with encryption and comprehensive audit logging.
[RequiresUnreferencedCode("Field-level encryption encrypts the document's fields, which serializes it reflectively over its members; trimming may remove them.")]
[RequiresDynamicCode("Field-level encryption encrypts the document's fields, which serializes it reflectively, generating serialization code for its type at run time.")]
public Task<UpdateResponse<TEntity>> SecureUpdateAsync(string id, TEntity document, CancellationToken cancellationToken)
Parameters
idstringThe document identifier to update.
documentTEntityThe updated document data.
cancellationTokenCancellationTokenThe cancellation token to monitor for cancellation requests.
Returns
- Task<UpdateResponse<TEntity>>
A task representing the asynchronous update operation with security enhancements applied.
Exceptions
- SecurityException
Thrown when security validation fails or access is denied.
- ArgumentException