/** * Gets the username. * * @return the username */ @Nullable public String getUsername() { return proxied.getUsername(); }
/** * Gets the username. * * @return the username */ @Nullable public String getUsername() { return proxied.getUsername(); }
@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(); }
public DB create() { try { mongoClient = new MongoClient(uri); mongoClient.setWriteConcern(WriteConcern.ACKNOWLEDGED); return mongoClient.getDB(uri.getDatabase()); } catch (Exception e) { LOGGER.error(format("Cannot connect to MongoDB on hosts %s using username: '%s'", uri.getHosts(), uri.getUsername()), e); throw new CouldNotProvideMongoException(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 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); } }
userName = mongoClientURI.getUsername(); if (mongoClientURI.getPassword() != null) { password = new String(mongoClientURI.getPassword());
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]); } } }
operationalInfo.put("mongoUser", uri.getUsername());
/** * 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"); }
public RealMongoDBExtendedStoreConnection(MongoURI mongoURI) { MongoClientURI mongoClientUri = null; try { mongoClientUri = new MongoClientURI(mongoURI.getValue()); } catch (Exception e) { throw new BaseException("can not parse:\"" + mongoURI.getValue() + "\" " + MongoParamParser.EXPECTED_PARAMS, e); } Frame frame = new Frame(); frame.add("USE MONGO DB"); frame.add("mongo db has be up and running"); frame.add("uri: " + mongoURI.getValue()); frame.add(" -> database:" + mongoClientUri.getDatabase()); frame.add(" -> user:" + mongoClientUri.getUsername()); mongoClientUri.getHosts().forEach(host -> { frame.add(" -> host:" + host); } ); frame.add(" -> ssl:" + mongoClientUri.getOptions().isSslEnabled()); LOGGER.info(frame.toString()); MongoClient mongoClient = new MongoClient(mongoClientUri); database = mongoClient.getDatabase(mongoClientUri.getDatabase()); databaseDeprecated = mongoClient.getDB(mongoClientUri.getDatabase()); }