Package com.mongodb

Examples of com.mongodb.DB.authenticate()


    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(MONGO_MAP_COLLECTION);
      DBObject indexObj = new BasicDBObject();
      indexObj.put("element_id", 1);
      collectionMap.ensureIndex(indexObj);
View Full Code Here


            }
            DB database = mongo.getDB(databaseName);
           
            if (userName != null && userName.trim().length() > 0)
            {
                if (!database.authenticate(userName, password.toCharArray()))
                {
                    throw new RuntimeException("Unable to authenticate with MongoDB server.");
                }
               
                // Allow password to be GCed
View Full Code Here

        }

        // get the DB and optionaly authenticate
        DB db = mongo.getDB(dbConnectionSettings.getDatabase());
        if (username!=null && password!=null) {
          db.authenticate(username, password.toCharArray());
        }
        return db;
    }

    /**
 
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

  @Test
  public void test(){
   
   
     DB testDB=mongo.getDB("skyline");
     testDB.authenticate("skyline", "skyline".toCharArray());
     long beginTime=System.currentTimeMillis();
     @SuppressWarnings("unused")
     DBCollection collection=testDB.getCollection("skyline")
     long endTime=System.currentTimeMillis();
     collection.toString();
View Full Code Here

             
              System.out.println(endTime-beginTime);
              /** 
               * 如果test数据库没有设定用户权限认证,则无需下面的验证 
               */ 
              boolean loginSuccess=testDB.authenticate(USER, PASSWORD.toCharArray());  
              if(!loginSuccess){  
                  throw new Exception("登录"+DB_NAME+"验证失败,请确认用户名和密码");  
              }  
              testDB=conn.getDB(DB_NAME);//取得test数据库  
              /** 
View Full Code Here

                mongoDb = new Mongo(hostname).getDB(databaseName);
            } else {
                mongoDb = new Mongo(hostname, port).getDB(databaseName);
            }
            if (username != null) {
                mongoDb.authenticate(username, password);
            }

            if (tableDefs == null || tableDefs.length == 0) {
                return new MongoDbDataContext(mongoDb);
            }
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

  private static void initThread() {
    try {
      MongoClient client = new MongoClient(Config.mgHost, Config.mgPort);
      DB db = client.getDB(Config.mgDb);
      if (db.authenticate(Config.mgUser, Config.mgPassword.toCharArray())) {
        clientLocal.set(client);
        dbLocal.set(db);
      }
    } catch (UnknownHostException e) {
      LOG.error(e.getMessage(), e);
View Full Code Here

                mongoDb = new Mongo(hostname).getDB(databaseName);
            } else {
                mongoDb = new Mongo(hostname, port).getDB(databaseName);
            }
            if (username != null) {
                mongoDb.authenticate(username, password);
            }
            return new MongoDbDataContext(mongoDb);
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
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.