List of usage examples for com.mongodb MongoCredential createMongoCRCredential
@SuppressWarnings("deprecation") @Deprecated public static MongoCredential createMongoCRCredential(final String userName, final String database, final char[] password)
From source file:com.eightkdata.mongowp.client.wrapper.MongoClientWrapper.java
License:Open Source License
private MongoCredential toMongoCredential(MongoAuthenticationConfiguration authConfiguration) { switch (authConfiguration.getMechanism()) { case cr:// www. j ava2s . co m return MongoCredential.createMongoCRCredential(authConfiguration.getUser(), authConfiguration.getSource(), authConfiguration.getPassword().toCharArray()); case scram_sha1: return MongoCredential.createScramSha1Credential(authConfiguration.getUser(), authConfiguration.getSource(), authConfiguration.getPassword().toCharArray()); case negotiate: return MongoCredential.createCredential(authConfiguration.getUser(), authConfiguration.getSource(), authConfiguration.getPassword().toCharArray()); case x509: return MongoCredential.createMongoX509Credential(authConfiguration.getUser()); default: throw new UnsupportedOperationException( "Authentication mechanism " + authConfiguration.getMechanism() + " not supported"); } }
From source file:com.emuneee.camerasyncmanager.util.DatabaseUtil.java
License:Apache License
private void initMongoClient() throws UnknownHostException { sLogger.info("Initializing MongoDB Client"); String dbUrl = mProperties.getProperty("DATABASE_URL"); int port = Integer.parseInt(mProperties.getProperty("DATABASE_PORT")); sLogger.debug("Database URL: " + dbUrl); sLogger.debug("Database Port: " + String.valueOf(port)); // create the mongo client and connect ServerAddress serverAddr = new ServerAddress(mProperties.getProperty("DATABASE_URL"), Integer.parseInt(mProperties.getProperty("DATABASE_PORT"))); MongoCredential credential = MongoCredential.createMongoCRCredential( mProperties.getProperty("DATABASE_USER"), mProperties.getProperty("DATABASE_NAME"), mProperties.getProperty("DATABASE_AUTH").toCharArray()); mMongoClient = new MongoClient(serverAddr, Arrays.asList(credential)); }
From source file:com.foodtruckdata.mongodb.UsersInput.java
public UsersInput(String host, int port, String db, String userName, String passwd) throws UnknownHostException { MongoCredential credential = MongoCredential.createMongoCRCredential(userName, db, passwd.toCharArray()); MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(credential)); mongoDB = mongoClient.getDB(db);//from w w w . j a va 2s . co m }
From source file:com.fpt.xml.hth.db.lib.DAO.MovieDAO.java
private void connection() { try {// w ww . j a v a 2s . c om MongoCredential credential = MongoCredential.createMongoCRCredential(Config.USER_NAME, Config.DATABASE_NAME, Config.PASS_WORD.toCharArray()); ServerAddress address = new ServerAddress(Config.getHost(), Config.getPort()); List<MongoCredential> lst = new ArrayList<MongoCredential>(); lst.add(credential); this.mongoClient = new MongoClient(address, lst); this.cinemaDB = mongoClient.getDB(Config.DATABASE_NAME); this.movieCollection = cinemaDB.getCollection(Config.MOVIE_COLLECTION); this.converter = new MovieTheaterSessionConverter(); } catch (UnknownHostException ex) { Logger.getLogger(MovieDAO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.github.frapontillo.pulse.crowd.data.repository.DBConfig.java
License:Apache License
public List<MongoCredential> getCredentials() { List<MongoCredential> credentialList = new ArrayList<>(1); if (!StringUtil.isNullOrEmpty(getUsername()) && !StringUtil.isNullOrEmpty(getPassword())) { credentialList = Collections.singletonList(MongoCredential.createMongoCRCredential(getUsername(), getDBName(), getPassword().toCharArray())); }/*w w w .java2s.com*/ return credentialList; }
From source file:com.github.maasdi.mongo.wrapper.UsernamePasswordMongoClientWrapper.java
License:Apache License
/** * Create a credentials object//from ww w . j av a 2 s .c om * * @param dbName * the name of the database * @return a configured MongoCredential object */ protected MongoCredential getCredential(MongoDbMeta meta, VariableSpace vars) { return MongoCredential .createMongoCRCredential(vars.environmentSubstitute(meta.getAuthenticationUser()), vars.environmentSubstitute(meta.getDbName()), Encr .decryptPasswordOptionallyEncrypted( vars.environmentSubstitute(meta.getAuthenticationPassword())) .toCharArray()); }
From source file:com.health.smart.util.MongoC.java
private static synchronized MongoClient getClient() throws UnknownHostException { if (client == null) { MongoCredential credential = MongoCredential.createMongoCRCredential("m.smart.health", "comp5527", "comp5527g3".toCharArray()); client = new MongoClient(new ServerAddress("ds031947.mongolab.com", 31947), Arrays.asList(credential)); }/*from ww w . j av a2s . c om*/ return client; }
From source file:com.heisenberg.mongo.MongoWorkflowEngineConfiguration.java
License:Apache License
public MongoWorkflowEngineConfiguration authentication(String userName, String database, char[] password) { if (credentials == null) { credentials = new ArrayList<>(); }//from w w w. java 2s. c o m credentials.add(MongoCredential.createMongoCRCredential(userName, database, password)); return this; }
From source file:com.ibm.haac.hx.engine.tool.mongodb.MongoDBAccess.java
License:Open Source License
public MongoDBAccess() throws Exception { try {// w w w. ja v a 2s. c o m if (mongoUri != null && !mongoUri.trim().equals("")) { System.out.println("Use mongo connection uri"); mongoUri = mongoUri.trim(); // http://stackoverflow.com/questions/15052074/connecting-a-mongodb-created-in-mongolab-through-a-java-application MongoClientURI uri = new MongoClientURI(mongoUri); this.mongoClient = new MongoClient(uri); int index = mongoUri.lastIndexOf("/"); dbName = mongoUri.substring(index + 1); } else { System.out.println("Use mongo database connection properties"); MongoCredential credential = MongoCredential.createMongoCRCredential(userName, dbName, pwd.toCharArray()); // connect to the server this.mongoClient = new MongoClient(new ServerAddress(serverIP, serverPort), Arrays.asList(credential)); } // attach to the database this.db = this.mongoClient.getDB(dbName); morphia = new Morphia(); if (morphiaDatastore == null) morphiaDatastore = morphia.createDatastore(this.mongoClient, dbName); ensureEntities(); this.mongoConnected = true; } catch (MongoException e) { throw new Exception("MongoDB exception: " + e.getMessage()); } catch (UnknownHostException e) { throw new Exception("MongoDB UnknownHostException exception: " + e.getMessage()); } }
From source file:com.images3.data.impl.MongoDBAccessProvider.java
License:Apache License
private void initMongoClient() { String url = config.getProperty("mongodb.url"); int port = Integer.valueOf(config.getProperty("mongodb.port")); String username = config.getProperty("mongodb.username"); String password = config.getProperty("mongodb.password"); try {//from w w w . j a v a 2 s . com if (username.trim().length() == 0) { this.mongoClient = new MongoClient(new ServerAddress(url, port)); } else { MongoCredential credential = MongoCredential.createMongoCRCredential(username, DBNAME, password.toCharArray()); this.mongoClient = new MongoClient(new ServerAddress(url, port), Arrays.asList(credential)); } } catch (UnknownHostException e) { throw new RuntimeException(e); } }