@Override public void connect() { try { mongoClient = new MongoClient(hostName); db = mongoClient.getDB(dataBase); if (userName != null && passWord != null) { db.authenticate(userName, passWord.toCharArray()); } } catch (UnknownHostException ex) { throw new RuntimeException("creating mongodb client", ex); } }
@Override public void connect() { try { mongoClient = new MongoClient(hostName); db = mongoClient.getDB(dataBase); if (userName != null && passWord != null) { db.authenticate(userName, passWord.toCharArray()); } } catch (UnknownHostException ex) { throw new RuntimeException("creating mongodb client", ex); } }
// import com.mongodb.MongoClient; // import com.mongodb.DBObject; MongoClient mongoClient = new MongoClient("URL", PORT); DB db = mongoClient.getDB("dbName"); boolean auth = db.authenticate("username", password.toCharArray());
MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("journaldev"); boolean auth = db.authenticate("pankaj", "pankaj123".toCharArray());
MongoClient mClient = new MongoClient(); //MongoClient mClient = new MongoClient("127.0.0.1", 27017); DB db = mClient.getDB("mms"); System.out.println("Connect success"); boolean auth = db.authenticate("user1", "passw0rd".toCharArray()); DBCollection coll = db.getCollection("tgps");
@Override public void beginWindow(long windowId) { try { mongoClient = new MongoClient(hostName); db = mongoClient.getDB(dataBase); if (userName != null && passWord != null) { db.authenticate(userName, passWord.toCharArray()); } } catch (UnknownHostException ex) { logger.debug(ex.toString()); } }
public DB getDB(String database, String username, String password) { if(log.isDebugEnabled()) { log.debug("username: " + username+", password: " + password+", database: " + database); } 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); } return db; }
@Override public void beginWindow(long windowId) { try { mongoClient = new MongoClient(hostName); db = mongoClient.getDB(dataBase); if (userName != null && passWord != null) { db.authenticate(userName, passWord.toCharArray()); } } catch (UnknownHostException ex) { logger.debug(ex.toString()); } }
public DatastoreImpl(Morphia morphia, Mongo mongo, String dbName, String username, char[] password) { this(morphia.getMapper(), mongo, dbName); if (username != null) if (!this.db.authenticate(username, password)) throw new AuthenticationException("User '" + username + "' cannot be authenticated with the given password for database '" + dbName + "'"); }
/** * @param morphia * @param mongo * @param dbName * @param username * @param password */ public DatastoreImpl(Morphia morphia, Mongo mongo, String dbName, String username, char[] password) { this(morphia.getMapper(), mongo, dbName); if (username != null) if (!this.db.authenticate(username, password)) throw new AuthenticationException("User '" + username + "' cannot be authenticated with the given password for database '" + dbName + "'"); }
public MongoTable(String host, String port, String dbName, String dbUser, String dbPasswd, String collectionName) { try { this.db = new Mongo(host, Integer.valueOf(port)).getDB(dbName); boolean auth = false; if(dbUser != null && !"".equals(dbUser.trim())) auth = db.authenticate(dbUser, dbPasswd.toCharArray()); if(!auth){ throw new RuntimeException("database auth failed with user:" + dbUser + " and passwd:" + dbPasswd); } this.collection = db.getCollection(collectionName); } catch (UnknownHostException e) { e.printStackTrace(); } catch (MongoException e) { e.printStackTrace(); } }
Mongo mongo = new Mongo("ds047037.mongolab.com", 47037); DB db = mongo.getDB("db_test_01"); db.authenticate(user, password);
public DB connect() throws IOException { ServerAddress server = new ServerAddress(host, port); Mongo mongo = new Mongo(server); DB database = mongo.getDB(db); database.authenticate(user, passwd != null ? passwd.get(): new char[]{}); return database; } }
MongoClient mongo = new MongoClient(ip, port); DB db = mongo.getDB("myDatabase"); boolean auth = db.authenticate(username, password); if (auth) { DBCollection collection = db.getCollection("myCollection"); DBObject jsonData = (DBObject) JSON.parse(jsonString); collection.insert(jsonData); }
@Override public void setup(Context.OperatorContext context) { super.setup(context); try { mongoClient = new MongoClient(hostName); db = mongoClient.getDB(dataBase); if (userName != null && passWord != null) { if (!db.authenticate(userName, passWord.toCharArray())) { throw new IllegalArgumentException("MongoDB authentication failed. Illegal username and password for MongoDB!!"); } } dbCollection = db.getCollection(collection); } catch (UnknownHostException ex) { logger.debug(ex.toString()); } }
private final DB buildDbSession(String dbname) { db = mongo.getDB(dbname); if (consistentRequest) { db.requestStart(); db.requestEnsureConnection(); } if (secureMode) { db.authenticate(dbUsername, dbPassword.toCharArray()); } return db; } }
private DB getMongoDB(){ try{ if(mongo != null){ String dbName = PropertyUtils.getPropertyString(bundleResourceString, "mongo.db.name"); String userName = PropertyUtils.getPropertyString(bundleResourceString, "mongo.db.user"); String password = PropertyUtils.getPropertyString(bundleResourceString,"mongo.db.pass"); DB db= mongo.getDB(dbName); db.authenticate(userName, password.toCharArray()); return db; } }catch(Exception e){ logger.error("getMongoDB occur error",e); } return null; }
private void authenticate(MongoConfiguration mongoConfiguration) { if(mongoConfiguration.getUser() != null && mongoConfiguration.getUser().length() > 0) { if(mongoConfiguration.getPw() != null && mongoConfiguration.getPw().length() > 0) { Boolean auth = db.authenticate(mongoConfiguration.getUser(), mongoConfiguration.getPw().toCharArray()); if (!auth) throw new MongoConfigRuntimeException("Mongo Authentication Failed"); } } }
public static DBCollection getCollection( MongoURI uri ){ 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." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ 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." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }