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


Java MongoCredential.createMongoCRCredential方法代码示例

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


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

示例1: initMongoClient

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
protected void initMongoClient() {
	String host = configuration.getProperty("db.host");
	Integer port = configuration.getPropertyAsInteger("db.port",27017);
	String user = configuration.getProperty("db.username");
	String pwd = configuration.getProperty("db.password");
	
	db = configuration.getProperty("db.database","step");

	ServerAddress address = new ServerAddress(host, port);
	List<MongoCredential> credentials = new ArrayList<>();
	if(user!=null) {
		MongoCredential credential = MongoCredential.createMongoCRCredential(user, db, pwd.toCharArray());
		credentials.add(credential);
	}
	
	mongoClient = new MongoClient(address, credentials);
}
 
开发者ID:denkbar,项目名称:step,代码行数:18,代码来源:MongoClientSession.java

示例2: activateService

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public void activateService()
    throws Exception
{
    loadConfiguration();

    // Create Mongo driver and open the database
    MongoClientOptions options = MongoClientOptions.builder().writeConcern( writeConcern ).build();
    if( username.isEmpty() )
    {
        mongo = new MongoClient( serverAddresses, options );
    }
    else
    {
        MongoCredential credential = MongoCredential.createMongoCRCredential( username, databaseName, password );
        mongo = new MongoClient( serverAddresses, Collections.singletonList( credential ), options );
    }
    db = mongo.getDatabase( databaseName );

    // Create index if needed
    MongoCollection<Document> entities = db.getCollection( collectionName );
    if( !entities.listIndexes().iterator().hasNext() )
    {
        entities.createIndex( new BasicDBObject( IDENTITY_COLUMN, 1 ) );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:27,代码来源:MongoDBEntityStoreMixin.java

示例3: 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

示例4: conectar

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private static DB conectar() {
	MongoClient mongoClient = null;
	MongoCredential mongoCredential = MongoCredential
			.createMongoCRCredential("trivialuser", "trivial",
					"4btrivialmongouser".toCharArray());
	try {
		mongoClient = new MongoClient(new ServerAddress(
				"ds062797.mongolab.com", 62797),
				Arrays.asList(mongoCredential));
	} catch (UnknownHostException e) {
		e.printStackTrace();
	}

	DB db = mongoClient.getDB("trivial");
	System.out.println("Conexion creada con la base de datos");
	return db;
}
 
开发者ID:Arquisoft,项目名称:Trivial4b,代码行数:18,代码来源:TrivialAPI.java

示例5: getDBInstance

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public static DB getDBInstance() {
	try {
		if (mongo == null) {
			if (LODVaderProperties.MONGODB_DB == null)
				new LODVaderProperties().loadProperties();
			if (LODVaderProperties.MONGODB_SECURE_MODE) {
				MongoCredential credential = MongoCredential.createMongoCRCredential(
						LODVaderProperties.MONGODB_USERNAME, LODVaderProperties.MONGODB_DB,
						LODVaderProperties.MONGODB_PASSWORD.toCharArray());
				mongo = new MongoClient(new ServerAddress(LODVaderProperties.MONGODB_HOST),
						Arrays.asList(credential));
			} else {
				mongo = new MongoClient(LODVaderProperties.MONGODB_HOST, LODVaderProperties.MONGODB_PORT);
			}
			db = mongo.getDB(LODVaderProperties.MONGODB_DB);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return db;
}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:22,代码来源:DBSuperClass2.java

示例6: 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

示例7: convert

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
public MongoCredential convert(MongoCredentialRepresentation value) {
    MongoCredential credential;
    switch (value.getType()) {
        case PLAIN:
            credential = MongoCredential.createPlainCredential(value.getUsername(), value.getSource(), value.getPassword().toCharArray());
            break;
        case GSSAPI:
            credential = MongoCredential.createGSSAPICredential(value.getUsername());
            break;
        case X509:
            credential = MongoCredential.createMongoX509Credential(value.getUsername());
            break;
        case CR:
        default:
            credential = MongoCredential.createMongoCRCredential(value.getUsername(), value.getDatabase(), value.getPassword().toCharArray());
    }
    for (Map.Entry<String,Object> entry : value.getProperties().entrySet()) {
        credential = credential.withMechanismProperty(entry.getKey(), entry.getValue());
    }
    return credential;
}
 
开发者ID:acu-dev,项目名称:dropwizard-mongodb,代码行数:23,代码来源:MongoCredentialConverter.java

示例8: getDb

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public static DB getDb() {
	if (db == null) {
		LOGGER.info("init singleton");
		MongoClient mongoClient;
		ApplicationResourcesLoader arl = new ApplicationResourcesLoader();
		try {
			MongoCredential credentials = MongoCredential
					.createMongoCRCredential(arl.getMongoUsername(), arl
							.getMongoDatabase(), arl.getMongoPassword()
							.toCharArray());
			mongoClient = new MongoClient(
					new ServerAddress(arl.getMongoUrl(),
							Integer.parseInt(arl.getMongoPort())),
					Arrays.asList(credentials));
			db = mongoClient.getDB(arl.getMongoDatabase());

		} catch (UnknownHostException e) {
			LOGGER.error("error get collection:" + e.getMessage());
		}
	}
	return db;
}
 
开发者ID:Biobanques,项目名称:ebiobanques-dataloader,代码行数:23,代码来源:MongoSingleton.java

示例9: createCredentials

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoCredential createCredentials(Map<String, Object> map) {
  final String authMechanismName = (String) map.get("authMechanism");
  final AuthenticationMechanism authenticationMechanism =
      AuthenticationMechanism.fromMechanismName(authMechanismName);
  final String username = (String) map.get("username");
  final String authDatabase = (String) map.get("authDatabase");
  final String password = (String) map.get("password");

  switch (authenticationMechanism) {
  case PLAIN:
    return MongoCredential.createPlainCredential(username, authDatabase,
        password.toCharArray());
  case SCRAM_SHA_1:
    return MongoCredential.createScramSha1Credential(username, authDatabase,
        password.toCharArray());
  case GSSAPI:
    return MongoCredential.createGSSAPICredential(username);
  case MONGODB_CR:
    return MongoCredential.createMongoCRCredential(username, authDatabase,
        password.toCharArray());
  case MONGODB_X509:
    return MongoCredential.createMongoX509Credential(username);
  }
  throw new IllegalArgumentException("Unsupported authentication mechanism "
      + authMechanismName);
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:MongoSchemaFactory.java

示例10: createCredentials

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private static MongoCredential createCredentials(MongoDataSourceConfiguration fileConfig) {
    MongoCredential credential;
    switch (fileConfig.getAuthenticationMethodEnum()) {
    case SCRAM_SHA_1:
        credential = MongoCredential.createScramSha1Credential(fileConfig.getUsername(), fileConfig.getDatabase(),
                fileConfig.getPassword().toCharArray());
        break;
    case MONGODB_CR:
        credential = MongoCredential.createMongoCRCredential(fileConfig.getUsername(), fileConfig.getDatabase(),
                fileConfig.getPassword().toCharArray());
    case LDAP_PLAIN:
        credential = MongoCredential.createPlainCredential(fileConfig.getUsername(), fileConfig.getAuthSource(),
                fileConfig.getPassword().toCharArray());
    case X_509:
        credential = MongoCredential.createMongoX509Credential(fileConfig.getUsername());
    case GSSAPI:
        credential = MongoCredential.createGSSAPICredential(fileConfig.getUsername());
    case DEFAULT:
    default:
        credential = MongoCredential.createCredential(fileConfig.getUsername(), fileConfig.getDatabase(),
                fileConfig.getPassword().toCharArray());
    }
    return credential;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:25,代码来源:MongoDataSourceReaderUtil.java

示例11: CredentialState

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public CredentialState(Resource parent, ResourceState resourceState) throws Exception {
    super(parent);

    String username = resourceState.getProperty(USERNAME, false, String.class);
    String password = resourceState.getProperty(PASSWORD, false, String.class);
    String mechanism = resourceState.getProperty(MECHANISM, false, String.class);
    String database = resourceState.getProperty(DB, false, String.class);

    if (username != null && !username.isEmpty()) {

        MongoCredential credential;
        if (mechanism.equals(MongoCredential.MONGODB_CR_MECHANISM)) {
            credential = MongoCredential.createMongoCRCredential(username, database, password.toCharArray());
        } else {
            credential = MongoCredential.createGSSAPICredential(username);
        }

        this.mongoCredential = credential;
    } else {
        this.mongoCredential = null;
    }
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:23,代码来源:CredentialState.java

示例12: connectToDatabase

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public GridFS connectToDatabase(ServerAddress server) {
	MongoCredential credential = MongoCredential.createMongoCRCredential("hive-dataserver", "admin", "hive-dataserver".toCharArray());
	MongoClient mongoClient = new MongoClient(server, Arrays.asList(credential));
	logger.info("got client");
	DB db = mongoClient.getDB("hive-dataserver");
	logger.info("Got DB");
	return new GridFS(db);
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:9,代码来源:DataManager.java

示例13: getMongoClient

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public MongoClient getMongoClient() {
	ServerAddress address = new ServerAddress(host, port);
	List<MongoCredential> credentials = new ArrayList<>();
	if(user!=null) {
		MongoCredential credential = MongoCredential.createMongoCRCredential(user, db, pwd.toCharArray());
		credentials.add(credential);
	}
	return new MongoClient(address, credentials);
}
 
开发者ID:denkbar,项目名称:step,代码行数:10,代码来源:MongoDBAccessorHelper.java

示例14: mongo

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
@Override
@Bean
public Mongo mongo() throws Exception {
    String host = System.getenv("OPENSHIFT_MONGODB_DB_HOST");
    //if(host==null) return new MongoClient("192.168.0.4");
    if(host==null) return new MongoClient("127.0.0.1");
    int port = Integer.parseInt(System.getenv("OPENSHIFT_MONGODB_DB_PORT"));
    String mongodb_username=System.getenv("OPENSHIFT_MONGODB_DB_USERNAME");
    String mongodb_password=System.getenv("OPENSHIFT_MONGODB_DB_PASSWORD");
    MongoCredential credential = MongoCredential.createMongoCRCredential(mongodb_username, getDatabaseName(), mongodb_password.toCharArray());
    return new MongoClient(new ServerAddress(host,port) , Arrays.asList(credential));
}
 
开发者ID:jvalenciag,项目名称:VaadinSpringShiroMongoDB,代码行数:13,代码来源:SpringMongoConfig.java

示例15: crearConexion

import com.mongodb.MongoCredential; //导入方法依赖的package包/类
/**
	 * Crear conexion.
	 */
	private static void crearConexion() {
		try {
//			mongo = new MongoClient("localhost", 27017);
			
			char[] pass={'1','2','3','4'};
			MongoCredential credential = MongoCredential.createMongoCRCredential("trivial1a", "trivial1a", pass);
			mongo = new MongoClient(new ServerAddress("ds029541.mongolab.com:29541"), Arrays.asList(credential));
			
		} catch (UnknownHostException e) {
			throw new RuntimeException(
					"No ha sido posible establecer la conexión con "
							+ "la Base de Datos. Error: " + e.getMessage());
		}
	}
 
开发者ID:Arquisoft,项目名称:Trivial1a,代码行数:18,代码来源:DBHelper.java


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