Search in sources :

Example 1 with SyncMongoClient

use of com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient in project mongo-java-driver by mongodb.

the class ClientEncryptionDataKeyAndDoubleEncryptionTest method setUp.

@Before
public void setUp() {
    assumeTrue(serverVersionAtLeast(4, 2));
    assumeTrue("Has encryption tests", hasEncryptionTestsEnabled());
    // Step 1: create unencrypted client
    commandListener = new TestCommandListener();
    client = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().addCommandListener(commandListener).build()));
    client.getDatabase("keyvault").getCollection("datakeys").drop();
    client.getDatabase("db").getCollection("coll").drop();
    // Step 2: Create encrypted client and client encryption
    Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {

        {
            put("aws", new HashMap<String, Object>() {

                {
                    put("accessKeyId", System.getProperty("org.mongodb.test.awsAccessKeyId"));
                    put("secretAccessKey", System.getProperty("org.mongodb.test.awsSecretAccessKey"));
                }
            });
            put("azure", new HashMap<String, Object>() {

                {
                    put("tenantId", System.getProperty("org.mongodb.test.azureTenantId"));
                    put("clientId", System.getProperty("org.mongodb.test.azureClientId"));
                    put("clientSecret", System.getProperty("org.mongodb.test.azureClientSecret"));
                }
            });
            put("gcp", new HashMap<String, Object>() {

                {
                    put("email", System.getProperty("org.mongodb.test.gcpEmail"));
                    put("privateKey", System.getProperty("org.mongodb.test.gcpPrivateKey"));
                }
            });
            put("local", new HashMap<String, Object>() {

                {
                    put("key", "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBM" + "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk");
                }
            });
        }
    };
    HashMap<String, BsonDocument> schemaMap = new HashMap<String, BsonDocument>() {

        {
            put("db.coll", BsonDocument.parse("{" + "  \"bsonType\": \"object\"," + "  \"properties\": {" + "    \"encrypted_placeholder\": {" + "      \"encrypt\": {" + "        \"keyId\": \"/placeholder\"," + "        \"bsonType\": \"string\"," + "        \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"" + "      }" + "    }" + "  }" + "}"));
        }
    };
    String keyVaultNamespace = "keyvault.datakeys";
    clientEncrypted = new SyncMongoClient(MongoClients.create(getMongoClientSettingsBuilder().autoEncryptionSettings(AutoEncryptionSettings.builder().keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProviders).schemaMap(schemaMap).build()).build()));
    clientEncryption = ClientEncryptions.create(ClientEncryptionSettings.builder().keyVaultMongoClientSettings(getMongoClientSettingsBuilder().addCommandListener(commandListener).build()).keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProviders).build());
}
Also used : SyncMongoClient(com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient) BsonDocument(org.bson.BsonDocument) HashMap(java.util.HashMap) TestCommandListener(com.mongodb.internal.connection.TestCommandListener) BsonString(org.bson.BsonString) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

TestCommandListener (com.mongodb.internal.connection.TestCommandListener)1 SyncMongoClient (com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 Before (org.junit.Before)1