本文整理汇总了Java中com.mongodb.MongoCredential.createMongoX509Credential方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCredential.createMongoX509Credential方法的具体用法?Java MongoCredential.createMongoX509Credential怎么用?Java MongoCredential.createMongoX509Credential使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.MongoCredential
的用法示例。
在下文中一共展示了MongoCredential.createMongoX509Credential方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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");
}
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}
示例6: createCredential
import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoCredential createCredential(Map<String, String> properties) throws DataServiceFault {
MongoCredential credential = null;
String authenticationType = properties.get(DBConstants.MongoDB.AUTHENTICATION_TYPE);
String username = properties.get(DBConstants.MongoDB.USERNAME);
String password = properties.get(DBConstants.MongoDB.PASSWORD);
String database = properties.get(DBConstants.MongoDB.DATABASE);
if (authenticationType != null) {
switch (authenticationType) {
case DBConstants.MongoDB.MongoAuthenticationTypes.PLAIN:
credential = MongoCredential.createPlainCredential(username, database, password.toCharArray());
break;
case DBConstants.MongoDB.MongoAuthenticationTypes.SCRAM_SHA_1:
credential = MongoCredential.createScramSha1Credential(username, database, password.toCharArray());
break;
case DBConstants.MongoDB.MongoAuthenticationTypes.MONGODB_CR:
credential = MongoCredential.createMongoCRCredential(username, database, password.toCharArray());
break;
case DBConstants.MongoDB.MongoAuthenticationTypes.GSSAPI:
credential = MongoCredential.createGSSAPICredential(username);
break;
case DBConstants.MongoDB.MongoAuthenticationTypes.MONGODB_X509:
credential = MongoCredential.createMongoX509Credential(username);
break;
default:
throw new DataServiceFault("Invalid Authentication type. ");
}
return credential;
} else {
return null;
}
}
示例7: createClient
import com.mongodb.MongoCredential; //导入方法依赖的package包/类
private MongoClient createClient(MongoAuthMechanism mechanism, String host, int port, String username, String password, String authdb) {
MongoClient client;
MongoCredential credential = null;
switch (mechanism) {
case SCRAM_SHA_1:
credential = MongoCredential.createScramSha1Credential(
username,
authdb,
password.toCharArray());
break;
case MONGODB_CR:
credential = MongoCredential.createMongoCRCredential(
username,
authdb,
password.toCharArray());
break;
case MONGO_X509:
credential = MongoCredential.createMongoX509Credential(username);
break;
}
client = new MongoClient(new ServerAddress(host, port),
Arrays.asList(new MongoCredential[]{credential})
);
return client;
}
示例8: credentialFromJson
import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public static MongoCredential credentialFromJson(ObjectNode node) {
String userName = null;
String password = null;
String source = null;
JsonNode xnode = node.get("mechanism");
if (xnode == null) {
throw new IllegalArgumentException("mechanism is required in credentials");
}
String mech = xnode.asText();
xnode = node.get("userName");
if (xnode != null) {
userName = xnode.asText();
}
xnode = node.get("password");
if (xnode != null) {
password = xnode.asText();
}
xnode = node.get("source");
if (xnode != null) {
source = xnode.asText();
}
MongoCredential cr = null;
if (null != mech) {
switch (mech) {
case "GSSAPI_MECHANISM":
cr = MongoCredential.createGSSAPICredential(userName);
break;
case "MONGODB_CR_MECHANISM":
cr = MongoCredential.createMongoCRCredential(userName, source,
password == null ? null : password.toCharArray());
break;
case "MONGODB_X509_MECHANISM":
cr = MongoCredential.createMongoX509Credential(userName);
break;
case "PLAIN_MECHANISM":
cr = MongoCredential.createPlainCredential(userName, source,
password == null ? null : password.toCharArray());
break;
case "SCRAM_SHA_1_MECHANISM":
cr = MongoCredential.createScramSha1Credential(userName,source,
password==null?null:password.toCharArray());
break;
default:
throw new IllegalArgumentException("invalid mechanism:" + mech + ", must be one of "
+ "GSSAPI_MECHANISM, MONGODB_CR_MECHANISM, "
+ "MONGODB_X5090_MECHANISM, SCRAM_SHA_1_MECHANISM or PLAIN_MECHANISM");
}
}
return cr;
}
示例9: CredentialListParser
import com.mongodb.MongoCredential; //导入方法依赖的package包/类
public CredentialListParser(ConnectionString connectionString, JsonObject config) {
List<MongoCredential> connStringCredentials = null;
if (connectionString != null) {
connStringCredentials = connectionString.getCredentialList();
}
if (connStringCredentials != null && !connStringCredentials.isEmpty()) {
credentials = connStringCredentials;
} else {
String username = config.getString("username");
if (username == null) {
credentials = Collections.emptyList();
} else {
credentials = new ArrayList<>();
String passwd = config.getString("password");
char[] password = (passwd == null) ? null : passwd.toCharArray();
// See https://github.com/vert-x3/vertx-mongo-client/issues/46 - 'admin' as default is a security
// concern, use the 'db_name' if none is set.
String authSource = config.getString("authSource",
config.getString("db_name", MongoClientImpl.DEFAULT_DB_NAME));
// AuthMechanism
AuthenticationMechanism mechanism = null;
String authMechanism = config.getString("authMechanism");
if (authMechanism != null) {
mechanism = getAuthenticationMechanism(authMechanism);
}
// MongoCredential
String gssapiServiceName = config.getString("gssapiServiceName");
MongoCredential credential;
if (mechanism == GSSAPI) {
credential = MongoCredential.createGSSAPICredential(username);
credential = getMongoCredential(gssapiServiceName, credential);
} else if (mechanism == PLAIN) {
credential = MongoCredential.createPlainCredential(username, authSource, password);
} else if (mechanism == MONGODB_CR) {
credential = MongoCredential.createMongoCRCredential(username, authSource, password);
} else if (mechanism == MONGODB_X509) {
credential = MongoCredential.createMongoX509Credential(username);
} else if (mechanism == SCRAM_SHA_1) {
credential = MongoCredential.createScramSha1Credential(username, authSource, password);
} else if (mechanism == null) {
credential = MongoCredential.createCredential(username, authSource, password);
} else {
throw new IllegalArgumentException("Unsupported authentication mechanism " + mechanism);
}
credentials.add(credential);
}
}
}