當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。