List of usage examples for com.mongodb MongoCredential SCRAM_SHA_1_MECHANISM
String SCRAM_SHA_1_MECHANISM
To view the source code for com.mongodb MongoCredential SCRAM_SHA_1_MECHANISM.
Click Source Link
From source file:me.konglong.momei.mongodb.config.MongoCredentialPropertyEditor.java
License:Apache License
@Override public void setAsText(String text) throws IllegalArgumentException { if (!StringUtils.hasText(text)) { return;//w w w . j a va 2 s. co m } List<MongoCredential> credentials = new ArrayList<MongoCredential>(); for (String credentialString : extractCredentialsString(text)) { String[] userNameAndPassword = extractUserNameAndPassword(credentialString); String database = extractDB(credentialString); Properties options = extractOptions(credentialString); if (!options.isEmpty()) { if (options.containsKey(AUTH_MECHANISM_KEY)) { String authMechanism = options.getProperty(AUTH_MECHANISM_KEY); if (MongoCredential.GSSAPI_MECHANISM.equals(authMechanism)) { verifyUserNamePresent(userNameAndPassword); credentials.add(MongoCredential.createGSSAPICredential(userNameAndPassword[0])); } else if (MongoCredential.MONGODB_CR_MECHANISM.equals(authMechanism)) { verifyUsernameAndPasswordPresent(userNameAndPassword); verifyDatabasePresent(database); credentials.add(MongoCredential.createMongoCRCredential(userNameAndPassword[0], database, userNameAndPassword[1].toCharArray())); } else if (MongoCredential.MONGODB_X509_MECHANISM.equals(authMechanism)) { verifyUserNamePresent(userNameAndPassword); credentials.add(MongoCredential.createMongoX509Credential(userNameAndPassword[0])); } else if (MongoCredential.PLAIN_MECHANISM.equals(authMechanism)) { verifyUsernameAndPasswordPresent(userNameAndPassword); verifyDatabasePresent(database); credentials.add(MongoCredential.createPlainCredential(userNameAndPassword[0], database, userNameAndPassword[1].toCharArray())); } else if (MongoCredential.SCRAM_SHA_1_MECHANISM.equals(authMechanism)) { verifyUsernameAndPasswordPresent(userNameAndPassword); verifyDatabasePresent(database); credentials.add(MongoCredential.createScramSha1Credential(userNameAndPassword[0], database, userNameAndPassword[1].toCharArray())); } else { throw new IllegalArgumentException(String.format( "Cannot create MongoCredentials for unknown auth mechanism '%s'!", authMechanism)); } } } else { verifyUsernameAndPasswordPresent(userNameAndPassword); verifyDatabasePresent(database); credentials.add(MongoCredential.createCredential(userNameAndPassword[0], database, userNameAndPassword[1].toCharArray())); } } setValue(credentials); }