/** * Gets the password. * * @return the password */ @Nullable public char[] getPassword() { return proxied.getPassword(); }
/** * Gets the password. * * @return the password */ @Nullable public char[] getPassword() { return proxied.getPassword(); }
@SuppressWarnings("ReplaceAllDot") private String createLogUri(MongoClientURI clientURI) { StringBuilder sb = new StringBuilder(); String password = clientURI.getPassword() == null ? null : new String(clientURI.getPassword()).replaceAll(".", "x"); String username = clientURI.getUsername(); for (String host : clientURI.getHosts()) { sb.append("mongodb://"); if (username != null) { sb.append(username); if (password != null) { sb.append(':').append(password); } sb.append('@'); } sb.append(host).append(" "); } return sb.toString(); }
collection = mongoClientURI.getCollection(); userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) { password = new String(mongoClientURI.getPassword());
public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = new MongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = new MongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
public MongoClientURIBuilder(final MongoClientURI mongoClientURI) { List<String> list = mongoClientURI.getHosts(); for (String s : list) { host(s); } database = mongoClientURI.getDatabase(); collection = mongoClientURI.getCollection(); userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) { password = new String(mongoClientURI.getPassword()); } options = mongoClientURI.getOptions(); String uri = mongoClientURI.getURI(); if (uri.contains("?")) { String query = uri.substring(uri.indexOf('?') + 1); String[] pairs = query.split("&"); for (String pair : pairs) { String[] split = pair.split("="); param(split[0], split[1]); } } }
/** * Get an authenticated DBCollection from a MongodB URI. * @param authURI the URI with which to authenticate * @param uri the MongoDB URI * @return the authenticated DBCollection */ public static DBCollection getCollectionWithAuth(final MongoClientURI uri, final MongoClientURI authURI) { //Make sure auth uri is valid and actually has a username/pw to use if (authURI == null || authURI.getUsername() == null || authURI.getPassword() == null) { throw new IllegalArgumentException("auth URI is empty or does not contain a valid username/password combination."); } DBCollection coll; try { Mongo mongo = getMongoClient(authURI); coll = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection()); return coll; } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
protected void init() { MongoClientURI inputURI = MongoConfigUtil.getInputURI(conf); this.inputCollection = MongoConfigUtil.getCollection(inputURI); DB db = this.inputCollection.getDB(); this.mongo = db.getMongo(); MongoClientURI authURI = MongoConfigUtil.getAuthURI(conf); if (authURI != null) { if (authURI.getUsername() != null && authURI.getPassword() != null) { authDB = mongo.getDB(authURI.getDatabase()); } } }
protected DB getConfigDB() { Mongo mongo; MongoClientURI inputURI = MongoConfigUtil.getInputURI(getConfiguration()); MongoClientURI authURI = MongoConfigUtil.getAuthURI(getConfiguration()); final DBCollection inputCollection; if (authURI != null && authURI.getUsername() != null && authURI.getPassword() != null) { inputCollection = MongoConfigUtil.getCollectionWithAuth(inputURI, authURI); } else { inputCollection = MongoConfigUtil.getCollection(inputURI); } DB db = inputCollection.getDB(); mongo = db.getMongo(); if (authURI != null) { if (authURI.getUsername() != null && authURI.getPassword() != null) { authDB = mongo.getDB(authURI.getDatabase()); } } return mongo.getDB("config"); }