0

I am trying to connect to MongoDB using mongoX509. I am using mongo java driver 3.3.0 jar. In api reference I can see MongoCredential to pass subject name and authenticate but i am not able to import this in my code. When I decompile the jar I am not able to see MongoCredential as well.

Am I missing any dependencies. Is there any easy way to connect to Mongodb without using MongoCredential? The details i have is server, port and certificate subject name?

I can post the code I am trying if anyone wants to take a look at it as well

Thanks in Advance

Code - I am using SoapUI to run this code

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

try{
    def subjectName="CN=xx,OU=xx,O=xx,C=US,ST=CA,L=xx"
    MongoCredential credential = MongoCredential.createMongoX509Credential(subjectName);
    def URI = "mongodb://server1:27017,server2:27017,server3:27017/<<database>>?replicaSet=<<XYZ>>&amp;authMechanism=MONGODB-X509&amp;ssl=true"
    MongoClientURI uri = new MongoClientURI(URI)
    MongoClient client = new MongoClient(uri, Arrays.asList(credential));
    DB database = client.getDB(<<database>>);
    collection = database.isAuthenticated();
    log.info collection
    }
catch (Exception e){
    log.info e
    }
Sujith Shajee
  • 175
  • 5
  • 18

1 Answers1

0

The issue was because of incorrect jar that I was using. I got the correct version and it worked.

Sujith Shajee
  • 175
  • 5
  • 18