Example usage for com.mongodb AuthenticationMechanism fromMechanismName

List of usage examples for com.mongodb AuthenticationMechanism fromMechanismName

Introduction

In this page you can find the example usage for com.mongodb AuthenticationMechanism fromMechanismName.

Prototype

public static AuthenticationMechanism fromMechanismName(final String mechanismName) 

Source Link

Document

Gets the mechanism by its name.

Usage

From source file:org.apache.calcite.adapter.mongodb.MongoSchemaFactory.java

License:Apache License

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://w  ww  . j  ava2 s .c  o  m
        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);
}