当前位置: 首页>>代码示例>>Java>>正文


Java MongoCredential.createCredential方法代码示例

本文整理汇总了Java中com.mongodb.MongoCredential.createCredential方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCredential.createCredential方法的具体用法?Java MongoCredential.createCredential怎么用?Java MongoCredential.createCredential使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.MongoCredential的用法示例。


在下文中一共展示了MongoCredential.createCredential方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeTest

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public void beforeTest() {
    final MongoCredential credential =
            MongoCredential.createCredential("bench", "benchmark", "bench".toCharArray());
    ServerAddress serverAddress = new ServerAddress("127.0.0.1", 27017);
    mongoClient = new MongoClient(serverAddress, new ArrayList<MongoCredential>() {{ add(credential); }});
    db = mongoClient.getDatabase("benchmark");

    Person[] personList = testHelper.loadData();
    documents = new ArrayList<>();
    ObjectMapper objectMapper = new ObjectMapper();

    for (Person person : personList) {
        StringWriter writer = new StringWriter();
        try {
            objectMapper.writeValue(writer, person);
            Document document = Document.parse(writer.toString());
            documents.add(document);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:24,代码来源:BaseMongoBenchMark.java

示例2: setup

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
/** The mongodb ops. */

	/* (non-Javadoc)
	 * @see co.aurasphere.botmill.core.datastore.adapter.DataAdapter#setup()
	 */
	public void setup() {
		
		MongoCredential credential = MongoCredential.createCredential(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.username"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.password").toCharArray());
		ServerAddress serverAddress = new ServerAddress(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.server"), 
				Integer.valueOf(ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.port")));
		MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
		SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient, ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"));

		MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory);
		this.source = (MongoOperations) mongoTemplate;
	}
 
开发者ID:BotMill,项目名称:botmill-core,代码行数:21,代码来源:MongoDBAdapter.java

示例3: init

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public void init() {
    MongoCredential credential = null;
    if (!Strings.isNullOrEmpty(this.configuration.getUsername())) {
        credential = MongoCredential.createCredential(
                this.configuration.getUsername(),
                this.configuration.getDatabase(),
                Strings.isNullOrEmpty(this.configuration.getPassword()) ? null : this.configuration.getPassword().toCharArray()
        );
    }

    String[] addressSplit = this.configuration.getAddress().split(":");
    String host = addressSplit[0];
    int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : 27017;
    ServerAddress address = new ServerAddress(host, port);

    if (credential == null) {
        this.mongoClient = new MongoClient(address, Collections.emptyList());
    } else {
        this.mongoClient = new MongoClient(address, Collections.singletonList(credential));
    }

    this.database = this.mongoClient.getDatabase(this.configuration.getDatabase());
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:25,代码来源:MongoDao.java

示例4: mongoClient

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Bean
@Profile("!test")
public MongoClient mongoClient(final MongoSettings mongoSettings) throws Exception {
    final List<ServerAddress> serverAddresses = mongoSettings.getServers()
            .stream()
            .map((MongoServer input) -> new ServerAddress(input.getName(), input.getPort()))
            .collect(toList());

    final MongoCredential credential = MongoCredential.createCredential(
            mongoSettings.getUsername(),
            mongoSettings.getDatabase(),
            mongoSettings.getPassword().toCharArray());

    return new MongoClient(
            serverAddresses, newArrayList(credential));
}
 
开发者ID:caelwinner,项目名称:spring-morphia,代码行数:17,代码来源:MongoClientConfiguration.java

示例5: mongoDbFactory

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public MongoDbFactory mongoDbFactory() throws Exception {
	
	if (System.getenv("spring_eg_content_mongo_host") != null) {
    	String host = System.getenv("spring_eg_content_mongo_host");
    	String port = System.getenv("spring_eg_content_mongo_port");
    	String username = System.getenv("spring_eg_content_mongo_username");
    	String password = System.getenv("spring_eg_content_mongo_password");

		 // Set credentials      
	    MongoCredential credential = MongoCredential.createCredential(username, getDatabaseName(), password.toCharArray());
	    ServerAddress serverAddress = new ServerAddress(host, Integer.parseInt(port));

	    // Mongo Client
	    MongoClient mongoClient = new MongoClient(serverAddress,Arrays.asList(credential)); 

	    // Mongo DB Factory
	    return new SimpleMongoDbFactory(mongoClient, getDatabaseName());
	}
	return super.mongoDbFactory();
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:22,代码来源:HypermediaConfigurationTest.java

示例6: initialize

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public void initialize(IMongoClientOptionsHandler optionsHandler, MongoDataSourceCfgMeta cfgMeta) throws Exception {
    __cfgMeta = cfgMeta;
    MongoClientOptions.Builder _builder = null;
    if (optionsHandler != null) {
        _builder = optionsHandler.handler(cfgMeta.getName());
    }
    if (_builder == null) {
        _builder = MongoClientOptions.builder();
    }
    if (StringUtils.isNotBlank(cfgMeta.getConnectionUrl())) {
        __mongoClient = new MongoClient(new MongoClientURI(cfgMeta.getConnectionUrl(), _builder));
    } else {
        String _username = StringUtils.trimToNull(cfgMeta.getUserName());
        String _password = StringUtils.trimToNull(cfgMeta.getPassword());
        if (_username != null && _password != null) {
            if (__cfgMeta.isPasswordEncrypted() && __cfgMeta.getPasswordClass() != null) {
                _password = __cfgMeta.getPasswordClass().newInstance().decrypt(_password);
            }
            MongoCredential _credential = MongoCredential.createCredential(cfgMeta.getUserName(), cfgMeta.getDatabaseName(), _password == null ? null : _password.toCharArray());
            __mongoClient = new MongoClient(cfgMeta.getServers(), Collections.singletonList(_credential), _builder.build());
        } else {
            __mongoClient = new MongoClient(cfgMeta.getServers(), _builder.build());
        }
    }
}
 
开发者ID:suninformation,项目名称:ymate-platform-v2,代码行数:26,代码来源:MongoDataSourceAdapter.java

示例7: findMongoCredential

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoCredential findMongoCredential(String user, String database, char[] pwd, String mechanism) {
    MongoCredential credential = null;
    switch (mechanism) {
        case "scram-sha-1":
            credential = MongoCredential.createScramSha1Credential(user, database, pwd);
            break;
        case "x509":
            credential = MongoCredential.createMongoX509Credential(user);
            break;
        case "cr":
            credential = MongoCredential.createMongoCRCredential(user, database, pwd);
            break;
        case "plain":
            credential = MongoCredential.createPlainCredential(user, database, pwd);
            break;
        case "gssapi":
            credential = MongoCredential.createGSSAPICredential(user);
            break;
        default:
            credential = MongoCredential.createCredential(user, database, pwd);
            break;
    }
    return credential;
}
 
开发者ID:ozlerhakan,项目名称:mongolastic,代码行数:25,代码来源:MongoConfiguration.java

示例8: init

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws UnknownHostException {
    ServerAddress mongoServer = new ServerAddress(dbConfig.host, Integer.valueOf(dbConfig.port));
    MongoCredential credential = MongoCredential.createCredential(
            dbConfig.username,
            dbConfig.name,
            dbConfig.password.toCharArray()
    );

    MongoClient mongoClient = new MongoClient(mongoServer, new ArrayList<MongoCredential>() {{
        add(credential);
    }});
    DB db = mongoClient.getDB(dbConfig.name);

    accountService = new MongoAccountService( db);
}
 
开发者ID:nbsp-team,项目名称:kurve-server,代码行数:17,代码来源:MongoAccountServiceTests.java

示例9: createClientFromParams

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoClient createClientFromParams(PluginTask task)
{
    if (!task.getHosts().isPresent()) {
        throw new ConfigException("'hosts' option's value is required but empty");
    }
    if (!task.getDatabase().isPresent()) {
        throw new ConfigException("'database' option's value is required but empty");
    }

    List<ServerAddress> addresses = new ArrayList<>();
    for (HostTask host : task.getHosts().get()) {
        addresses.add(new ServerAddress(host.getHost(), host.getPort()));
    }

    if (task.getUser().isPresent()) {
        MongoCredential credential = MongoCredential.createCredential(
                task.getUser().get(),
                task.getDatabase().get(),
                task.getPassword().get().toCharArray()
        );
        return new MongoClient(addresses, Arrays.asList(credential));
    }
    else {
        return new MongoClient(addresses);
    }
}
 
开发者ID:hakobera,项目名称:embulk-input-mongodb,代码行数:27,代码来源:MongodbInputPlugin.java

示例10: configure

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public void configure(Binder binder) {
    Logger.info("Configuring MongoDb Module");
    ServerAddress serverAddress = new ServerAddress(MONGO_DB_SERVER, Integer.parseInt(MONGO_DB_PORT));
    MongoCredential credential = MongoCredential.createCredential(MONGO_DB_USER,
            DATABASE,
            MONGO_DB_PASSWORD.toCharArray());
    List<MongoCredential> auths = Collections.singletonList(credential);
    MongoClient client = new MongoClient(serverAddress, auths);
    Dao<String, Category> categoryDao = new MongoDbDao<>(client, DATABASE, Category.class);
    Dao<String, Snippet> snippetDao = new CachingDao<>(new MongoDbDao<>(client, DATABASE, Snippet.class));
    binder.bind(new TypeLiteral<Dao<String, Category>>() {
    }).toInstance(categoryDao);
    binder.bind(new TypeLiteral<Dao<String, Snippet>>() {
    }).toInstance(snippetDao);
}
 
开发者ID:nwillc,项目名称:mysnipserver,代码行数:17,代码来源:MongoDbModule.java

示例11: init

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void init()
{
	if(mongoClient != null) return;
	try {
		MongoCredential credential = MongoCredential.createCredential(
				MongoDBDrive.getInstance().getUsername(),
				MongoDBDrive.getInstance().getDatabase(),
				MongoDBDrive.getInstance().getPassword().toCharArray());
		MongoDBDrive.getInstance().mongoClient = new MongoClient(
				new ServerAddress(MongoDBDrive.getInstance().getUrl()),
				Arrays.asList(credential));
		MongoDBDrive.getInstance().mongoClient.setWriteConcern(WriteConcern.NORMAL);
	} catch (Exception e) {
		return;
	}
	return;
}
 
开发者ID:liyang-bsy,项目名称:LYLab,代码行数:19,代码来源:MongoDBDrive.java

示例12: initDB3

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private com.mongodb.client.MongoDatabase initDB3(String url, Integer port, String dbName,
		String user, String password) throws UnknownHostException,
		MongoException {
	MongoClient mongoClient = null;
	List<ServerAddress> seeds = new ArrayList<ServerAddress>();
	if(StringUtils.isNotEmpty(url)){
		String[] urls = url.split(",");
		for(String ul:urls){
			if(StringUtils.isNotEmpty(ul)){
				seeds.add(new ServerAddress(ul, port != null ? port : 27017));
			}
		}
	}
	MongoCredential credential = MongoCredential.createCredential(user, dbName, password.toCharArray());
	List<MongoCredential> credentials = new ArrayList<MongoCredential>();
	//credentials.add(credential);
	mongoClient = new MongoClient(seeds, credentials);
	return mongoClient.getDatabase(dbName);
}
 
开发者ID:uncodecn,项目名称:uncode-dal-all,代码行数:20,代码来源:MongoDataBase.java

示例13: toMongoCredential

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoCredential toMongoCredential(MongoAuthenticationConfiguration authConfiguration) {
  switch (authConfiguration.getMechanism()) {
    case cr:
      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");
  }
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:19,代码来源:MongoClientWrapper.java

示例14: connectDB

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
protected void connectDB(){
    List<ServerAddress> serverList = new ArrayList<ServerAddress>();
    try{
        serverList.add(new ServerAddress("192.168.0.200", 27017));
        serverList.add(new ServerAddress("192.168.0.200", 27018));
        serverList.add(new ServerAddress("192.168.0.200", 27019));
    }catch(UnknownHostException ex){
        ex.printStackTrace();
    }
    
    List<MongoCredential> credentialList = new ArrayList<MongoCredential>();
    MongoCredential credentialA = MongoCredential.createCredential("test", "test", "test".toCharArray());
    MongoCredential credentialB = MongoCredential.createCredential("test", "test", "test".toCharArray());
    MongoCredential credentialC = MongoCredential.createCredential("test", "test", "test".toCharArray());
    credentialList.add(credentialA);
    credentialList.add(credentialB);
    credentialList.add(credentialC);
    BuguConnection conn = BuguFramework.getInstance().createConnection();
    conn.setServerList(serverList).setCredentialList(credentialList).setDatabase("test").connect();
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:21,代码来源:ReplicaSetBaseTest.java

示例15: connectDBWithOptions

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
protected void connectDBWithOptions(MongoClientOptions options){
    List<ServerAddress> serverList = new ArrayList<ServerAddress>();
    try {
        serverList.add(new ServerAddress("192.168.0.200", 27017));
        serverList.add(new ServerAddress("192.168.0.200", 27018));
        serverList.add(new ServerAddress("192.168.0.200", 27019));
    } catch (UnknownHostException ex) {
        ex.printStackTrace();
    }
    
    List<MongoCredential> credentialList = new ArrayList<MongoCredential>();
    MongoCredential credentialA = MongoCredential.createCredential("test", "test", "test".toCharArray());
    MongoCredential credentialB = MongoCredential.createCredential("test", "test", "test".toCharArray());
    MongoCredential credentialC = MongoCredential.createCredential("test", "test", "test".toCharArray());
    credentialList.add(credentialA);
    credentialList.add(credentialB);
    credentialList.add(credentialC);
    BuguConnection conn = BuguFramework.getInstance().createConnection();
    conn.setOptions(options);
    conn.setServerList(serverList);
    conn.setCredentialList(credentialList);
    conn.setDatabase("test");
    conn.connect();
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:25,代码来源:ReplicaSetBaseTest.java


注:本文中的com.mongodb.MongoCredential.createCredential方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。