Package com.mongodb

Examples of com.mongodb.DB.authenticate()


      throw new IllegalArgumentException("Cannot connect to MongoDB",e);
    }

    // Authenticate
    if (mongoUri.getUsername() != null && mongoUri.getPassword() != null) {
      db.authenticate(mongoUri.getUsername(), mongoUri.getPassword());
    }

    return db;

  }
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

            oldMongo = m_mongoRef.get();
        } while (!m_mongoRef.compareAndSet(oldMongo, newMongo));
       
        DB db = newMongo.getDB(m_dbName);
        if ((userName != null) && (password != null)) {
            if (!db.authenticate(userName, password.toCharArray())) {
                return false;
            }
        }
       
        return true;
View Full Code Here

    protected DBCollection togglzCollection() {
        DB db = mongoClient.getDB(dbname);
        db.setWriteConcern(writeConcert);
        if (username != null && password != null) {
            db.authenticate(username, password);
        }
        return db.getCollection(collection);
    }

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

                        mongo = new Mongo(servers);
                    }
                }
                db = mongo.getDB(connectionSpec.getDB());
                if ((connectionSpec.getUser() != null) && (connectionSpec.getUser().length() > 0)) {
                    if (!db.authenticate(connectionSpec.getUser(), connectionSpec.getPassword())) {
                        throw new ResourceException("authenticate failed for user: " + connectionSpec.getUser());
                    }
                }
                if (connectionSpec.getOptions() > 0) {
                    db.setOptions(connectionSpec.getOptions());
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

                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

        DB db = mongo.getDB(database);
        boolean authenticated = db.isAuthenticated();

        if(!authenticated) {
            if(username != null && password != null && username.length() > 0 && password.length() > 0) {
                authenticated = db.authenticate(username, password.toCharArray());
            }
        }
        if(log.isDebugEnabled()) {
            log.debug("authenticated: " + authenticated);
        }
View Full Code Here

        try {
            final DB db = this.getMongo().getDB(dbname);
            if (StringUtils.hasText(username)
                    && StringUtils.hasText(password)
                    && !db.isAuthenticated()) {
                if (!db.authenticate(username, password.toCharArray())) {
                    throw this.getError403();
                }
            }
            return db;
        } catch (UnknownHostException t) {
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.