Package com.mongodb

Examples of com.mongodb.DB.authenticate()


            try {
                // Hack. Checking server connectivity status by fetching collection names on selected db
                db.getCollectionNames();//this line will throw exception in two cases.1)On Invalid mongo host Address,2)Invalid authorization to fetch collection names
                loginStatus = true;
            } catch (MongoException me) {
                loginStatus = db.authenticate(username, password.toCharArray());//login using given username and password.This line will throw exception if invalid mongo host address
            }
            if (loginStatus) {
                connectionDetails.addToAuthenticatedDbNames(dbName);
            }
        }
View Full Code Here


    public static Mongo getTestMongoInstance() {
        try {
            Mongo mongo = new Mongo(getMongoHost(), getMongoPort());
            DB adminDB = mongo.getDB("admin");
            adminDB.authenticate(getMongoUsername(), getMongoPassword().toCharArray());
            return mongo;
        } catch (Exception e) {
            logger.error("Couldn't create a test mongo instance", e);
            throw new RuntimeException("Couldn't create a test mongo instance", e);
        }
View Full Code Here

  private DB extractDatabase() {
    try {
      if ( config.getUsername() != null ) {
        DB admin = this.mongo.getDB( "admin" );
        boolean auth = admin.authenticate( config.getUsername(), config.getPassword().toCharArray() );
        if ( !auth ) {
          throw log.authenticationFailed( config.getUsername() );
        }
      }
      if ( !this.mongo.getDatabaseNames().contains( config.getDatabaseName() ) ) {
View Full Code Here

    preferenceIsString = true;
    Mongo mongoDDBB = new Mongo(mongoHost, mongoPort);
    DB db = mongoDDBB.getDB(mongoDB);
    mongoTimestamp = new Date(0);
    FastByIDMap<Collection<Preference>> userIDPrefMap = new FastByIDMap<Collection<Preference>>();
    if (!mongoAuth || db.authenticate(mongoUsername, mongoPassword.toCharArray())) {
      collection = db.getCollection(mongoCollection);
      collectionMap = db.getCollection(mongoMapCollection);
      DBObject indexObj = new BasicDBObject();
      indexObj.put("element_id", 1);
      collectionMap.ensureIndex(indexObj);
View Full Code Here

    preferenceIsString = true;
    Mongo mongoDDBB = new Mongo(mongoHost, mongoPort);
    DB db = mongoDDBB.getDB(mongoDB);
    mongoTimestamp = new Date(0);
    FastByIDMap<Collection<Preference>> userIDPrefMap = new FastByIDMap<Collection<Preference>>();
    if (!mongoAuth || (mongoAuth && db.authenticate(mongoUsername, mongoPassword.toCharArray()))) {
      collection = db.getCollection(mongoCollection);
      collectionMap = db.getCollection(mongoMapCollection);
      DBObject indexObj = new BasicDBObject();
      indexObj.put("element_id", 1);
      collectionMap.ensureIndex(indexObj);
View Full Code Here

    {
    return;
    }
 
    //exec auth
  if( db.authenticate( username, passwd.toCharArray() ) )
    {
    MDataManager.getInstance().getActionThreadPool().addCommand( action );
    }
  else
    {
View Full Code Here

      if (credentialsGiven && !authDb.isAuthenticated()) {

        String username = credentials.getUsername();
        String password = credentials.hasPassword() ? credentials.getPassword() : null;

        if (!authDb.authenticate(username, password == null ? null : password.toCharArray())) {
          throw new CannotGetMongoDbConnectionException("Failed to authenticate to database [" + databaseName + "], "
              + credentials.toString(), databaseName, credentials);
        }
      }
    }
View Full Code Here

  }

  @Override
  public DB getObject() throws Exception {
    DB db = mongoUri.connectDB();
    db.authenticate(mongoUri.getUsername(), mongoUri.getPassword());

    return db;
  }

  @Override
View Full Code Here

            mongo = new Mongo(mongoURI);
            DB db = mongo.getDB(database);
            String username = mongoURI.getUsername();
            char[] password = mongoURI.getPassword();
            if (username != null && password != null)
                db.authenticate(username, password);
            eventsCollection = db.getCollection(collection);
            super.start();
        } catch (Exception exception) {
            addError("Error connecting to MongoDB URI: " + uri, exception);
        }
View Full Code Here

  private DB extractDatabase() {
    try {
      if ( config.getUsername() != null ) {
        DB admin = this.mongo.getDB( "admin" );
        boolean auth = admin.authenticate( config.getUsername(), config.getPassword().toCharArray() );
        if ( !auth ) {
          throw log.authenticationFailed( config.getUsername() );
        }
      }
      String databaseName = config.getDatabaseName();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.