Hi, I'm trying to implement MongoDB CSFLE, I need a way to override the MongoDB settings and the MongoClient.
I created a class implementing AbpMongoDbContext
could you please let me know how can I achieve that? One of the settings that I have to change is: mongoDBSettings.AutoEncryptionOptions
Database and Client are private set, so I can't override it.
- ABP Framework version: 8.0.3
- UI Type: Angular
- Database System: MongoDB
7 Answer(s)
-
0
Hi,
You can configure the
AbpMongoDbContextOptions
Configure<AbpMongoDbContextOptions>(options => { options.MongoClientSettingsConfigurer = settings => { settings.AutoEncryptionOptions = .... }; });
-
0
To be able to build the
AutoEncryptionOptions
I need to fetch the collection to grab the encryption key, how can I achieve that in the DBModule if I don't have the MongoClient just yet? -
0
You can check this: https://stackoverflow.com/questions/68659436/how-to-encrypt-a-class-property-using-mongodb-csfle-in-dot-net-core
-
0
I'm not talking about the CSFLE implementation, that part is done, my question is how to override the MongoClient in the
AbpMongoDbContext
, because I need to fetch the keys from the DB, create theAutoEncryptionOptions
and then override the client config -
0
-
0
Found a solution which worked:
public override void InitializeDatabase(IMongoDatabase database, IMongoClient client, IClientSessionHandle sessionHandle) { var clientSettings = client.Settings.Clone(); clientSettings.AutoEncryptionOptions = autoEncryptionOptions; client = new MongoClient(clientSettings); database = client.GetDatabase(database.DatabaseNamespace.DatabaseName); base.InitializeDatabase(database, client, sessionHandle); }
-
0
Good to see you find a way