Package com.mongodb

Examples of com.mongodb.DB.authenticate()


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

    DB db = mongo.getDB(uri.getDatabase());

    // if there's a username and password
    if (uri.getUsername() != null && uri.getPassword() != null
        && !db.isAuthenticated()) {
      boolean auth = db
          .authenticate(uri.getUsername(), uri.getPassword());
      if (auth) {
        log.info("Sucessfully authenticated with collection.");
      } else {
        throw new IllegalArgumentException(
View Full Code Here

    }
    DB db = mongo.getDB(uri.getDatabase());
   
    //if there's a username and password
        if(uri.getUsername() != null && uri.getPassword() != null && !db.isAuthenticated()){
            boolean auth = db.authenticate(uri.getUsername(), uri.getPassword());
            if(auth) {
                log.info("Sucessfully authenticated with collection.");
            }
            else {
                throw new IllegalArgumentException("Unable to connect to collection. You have to check your username and password" );
View Full Code Here

        try {
            Mongo mongo = mongos.connect( uri );
            DB myDb = mongo.getDB(uri.getDatabase());
            //if there's a username and password
            if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) {
                boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword());
                if(auth) {
                    log.info("Sucessfully authenticated with collection.");
                }
                else {
                    throw new IllegalArgumentException( "Unable to connect to collection." );
View Full Code Here

      if ( usernameObject != null ) {
        DB admin = this.mongo.getDB( "admin" );
        String username = usernameObject.toString();
        Object passwordObject = this.cfg.get( Environment.MONGODB_PASSWORD );
        String password = passwordObject != null ? passwordObject.toString() : "";
        boolean auth = admin.authenticate( username, password.toCharArray() );
        if ( !auth ) {
          throw log.authenticationFailed( username );
        }
      }
      if ( !this.mongo.getDatabaseNames().contains( dbName ) ) {
View Full Code Here

        }
        DB db = mongo_.getDB(dbName);
        if (c.containsKey(PREFIX + "username") && c.containsKey(PREFIX + "password")) {
            String username = c.getProperty(PREFIX + "username");
            String password = c.getProperty(PREFIX + "password");
            if (!db.isAuthenticated() && !db.authenticate(username, password.toCharArray())) {
                throw new RuntimeException("MongoDB authentication failed: " + dbName);
            }
        }

        String loggerClass = c.getProperty("morphia.logger");
View Full Code Here

            String username = "kunderaUser";
            String password  = "kunderapassword";
            DB db = m.getDB(dbname);
            db.addUser(username, password.toCharArray());
            db.requestDone();
            if (db.authenticate(username, password.toCharArray()))
            {
                m.close();
                emf = Persistence.createEntityManagerFactory(pu);
                Assert.assertNotNull(emf);
                EntityManager em = emf.createEntityManager();
View Full Code Here

   * @return MongoDB 数据访问借口
   */
  public MongoDao getDao(String dbname) {
    DB db = mongo.getDB(dbname);
    if (user != null)
      db.authenticate(user, password.toCharArray());
    return new MongoDao(db);
  }

  /**
   * 注销一个 MongoDB 的连接
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.