Search in sources :

Example 1 with ServerAddress

use of com.mongodb.ServerAddress in project cas by apereo.

the class MongoDbCloudConfigBootstrapConfiguration method mongo.

@Override
public Mongo mongo() throws Exception {
    final MongoCredential credential = MongoCredential.createCredential(mongoClientUri().getUsername(), getDatabaseName(), mongoClientUri().getPassword());
    final String hostUri = mongoClientUri().getHosts().get(0);
    final String[] host = hostUri.split(":");
    return new MongoClient(new ServerAddress(host[0], host.length > 1 ? Integer.parseInt(host[1]) : DEFAULT_PORT), Collections.singletonList(credential), mongoClientOptions());
}
Also used : MongoClient(com.mongodb.MongoClient) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress)

Example 2 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class AuthenticatingConnectionTest method setUp.

@Before
public void setUp() throws Exception {
    userName = System.getProperty("org.mongodb.test.userName", "bob");
    password = System.getProperty("org.mongodb.test.password", "pwd123");
    source = System.getProperty("org.mongodb.test.source", "admin");
    serverAddress = new ServerAddress(System.getProperty("org.mongodb.test.serverAddress", getPrimary().toString()));
    InternalConnectionFactory internalConnectionFactory = new InternalStreamConnectionFactory(new SocketStreamFactory(SocketSettings.builder().build(), getSslSettings()), Collections.<MongoCredential>emptyList(), new NoOpConnectionListener(), null, null);
    internalConnection = internalConnectionFactory.create(new ServerId(new ClusterId(), serverAddress));
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 3 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class PlainAuthenticatorTest method setUp.

@Before
public void setUp() throws Exception {
    String host = System.getProperty("org.mongodb.test.host");
    userName = System.getProperty("org.mongodb.test.userName");
    source = System.getProperty("org.mongod.test.source");
    password = System.getProperty("org.mongodb.test.password");
    internalConnection = new InternalStreamConnectionFactory(streamFactory, Collections.<MongoCredential>emptyList(), new NoOpConnectionListener(), null, null).create(new ServerId(new ClusterId(), new ServerAddress(host)));
    connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 4 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class X509AuthenticatorNoUserNameTest method before.

@Before
public void before() {
    connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
    connectionDescriptionThreeTwo = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), new ServerVersion(3, 2), ServerType.STANDALONE, 1000, 16000, 48000);
    connectionDescriptionThreeFour = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), new ServerVersion(3, 4), ServerType.STANDALONE, 1000, 16000, 48000);
    credential = MongoCredential.createMongoX509Credential("CN=client,OU=kerneluser,O=10Gen,L=New York City,ST=New York,C=US");
    subject = new X509Authenticator(this.credential);
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 5 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class X509AuthenticatorUnitTest method before.

@Before
public void before() {
    connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
    connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
    credential = MongoCredential.createMongoX509Credential("CN=client,OU=kerneluser,O=10Gen,L=New York City,ST=New York,C=US");
    subject = new X509Authenticator(this.credential);
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Aggregations

ServerAddress (com.mongodb.ServerAddress)201 Test (org.junit.Test)49 MongoClient (com.mongodb.MongoClient)48 ArrayList (java.util.ArrayList)31 Test (org.junit.jupiter.api.Test)31 MongoCredential (com.mongodb.MongoCredential)30 ClusterSettings (com.mongodb.connection.ClusterSettings)20 ClusterId (com.mongodb.connection.ClusterId)19 MongoClientSettings (com.mongodb.MongoClientSettings)18 BsonDocument (org.bson.BsonDocument)18 Before (org.junit.Before)18 ClusterDescription (com.mongodb.connection.ClusterDescription)15 Document (org.bson.Document)14 ServerDescription (com.mongodb.connection.ServerDescription)13 List (java.util.List)12 RepeatedTest (org.junit.jupiter.api.RepeatedTest)12 ConnectionString (com.mongodb.ConnectionString)10 MongoClient (com.mongodb.client.MongoClient)9 MongoDatabase (com.mongodb.client.MongoDatabase)9 ServerId (com.mongodb.connection.ServerId)8