Example usage for com.mongodb MongoCredential createPlainCredential

List of usage examples for com.mongodb MongoCredential createPlainCredential

Introduction

In this page you can find the example usage for com.mongodb MongoCredential createPlainCredential.

Prototype

public static MongoCredential createPlainCredential(final String userName, final String source,
        final char[] password) 

Source Link

Document

Creates a MongoCredential instance for the PLAIN SASL mechanism.

Usage

From source file:org.wso2.carbon.datasource.reader.mongo.MongoDataSourceReaderUtil.java

License:Open Source License

private static MongoCredential createCredentials(MongoDataSourceConfiguration fileConfig) {
    MongoCredential credential;//from www.  ja  va 2s.  c om
    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;
}