本文整理匯總了Java中com.mongodb.MongoCredential.createScramSha1Credential方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoCredential.createScramSha1Credential方法的具體用法?Java MongoCredential.createScramSha1Credential怎麽用?Java MongoCredential.createScramSha1Credential使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.MongoCredential
的用法示例。
在下文中一共展示了MongoCredential.createScramSha1Credential方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildMongoClientFactoryBean
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
/**
* 生成mongoClientFacotryBean
*
* @param mythMongoConfig 配置信息
* @return bean
*/
private MongoClientFactoryBean buildMongoClientFactoryBean(MythMongoConfig mythMongoConfig) {
MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
MongoCredential credential = MongoCredential.createScramSha1Credential(mythMongoConfig.getMongoUserName(),
mythMongoConfig.getMongoDbName(),
mythMongoConfig.getMongoUserPwd().toCharArray());
clientFactoryBean.setCredentials(new MongoCredential[]{
credential
});
List<String> urls = Splitter.on(",").trimResults().splitToList(mythMongoConfig.getMongoDbUrl());
final ServerAddress[] sds = urls.stream().map(url -> {
List<String> adds = Splitter.on(":").trimResults().splitToList(url);
InetSocketAddress address = new InetSocketAddress(adds.get(0), Integer.parseInt(adds.get(1)));
return new ServerAddress(address);
}).collect(Collectors.toList()).toArray(new ServerAddress[]{});
clientFactoryBean.setReplicaSetSeeds(sds);
return clientFactoryBean;
}
示例2: buildMongoClientFactoryBean
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
/**
* 生成mongoClientFacotryBean
*
* @param config 配置信息
* @return bean
*/
private MongoClientFactoryBean buildMongoClientFactoryBean(TxMongoConfig config) {
MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
MongoCredential credential = MongoCredential.createScramSha1Credential(config.getMongoUserName(),
config.getMongoDbName(),
config.getMongoUserPwd().toCharArray());
clientFactoryBean.setCredentials(new MongoCredential[]{
credential
});
List<String> urls = Splitter.on(",").trimResults().splitToList(config.getMongoDbUrl());
final ServerAddress[] serverAddresses = urls.stream().filter(Objects::nonNull)
.map(url -> {
List<String> adds = Splitter.on(":").trimResults().splitToList(url);
return new ServerAddress(adds.get(0), Integer.valueOf(adds.get(1)));
}).collect(Collectors.toList()).toArray(new ServerAddress[urls.size()]);
clientFactoryBean.setReplicaSetSeeds(serverAddresses);
return clientFactoryBean;
}
示例3: buildMongoClientFactoryBean
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
/**
* 生成mongoClientFacotryBean
*
* @param tccMongoConfig 配置信息
* @return bean
*/
private MongoClientFactoryBean buildMongoClientFactoryBean(TccMongoConfig tccMongoConfig) {
MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
MongoCredential credential = MongoCredential.createScramSha1Credential(tccMongoConfig.getMongoUserName(),
tccMongoConfig.getMongoDbName(),
tccMongoConfig.getMongoUserPwd().toCharArray());
clientFactoryBean.setCredentials(new MongoCredential[]{
credential
});
List<String> urls = Splitter.on(",").trimResults().splitToList(tccMongoConfig.getMongoDbUrl());
ServerAddress[] sds = new ServerAddress[urls.size()];
for (int i = 0; i < sds.length; i++) {
List<String> adds = Splitter.on(":").trimResults().splitToList(urls.get(i));
InetSocketAddress address = new InetSocketAddress(adds.get(0), Integer.parseInt(adds.get(1)));
sds[i] = new ServerAddress(address);
}
clientFactoryBean.setReplicaSetSeeds(sds);
return clientFactoryBean;
}
示例4: 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;
}
示例5: mongo
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
@Override
@Bean
public MongoClient mongo() throws Exception {
ServerAddress serverAddr = new ServerAddress(host, port);
LOGGER.info("Initializing Mongo Client server at: {}", serverAddr);
MongoClient client;
if (StringUtils.isEmpty(userName)) {
client = new MongoClient(serverAddr);
} else {
MongoCredential mongoCredential = MongoCredential.createScramSha1Credential(
userName, databaseName, password.toCharArray());
client = new MongoClient(serverAddr, Collections.singletonList(mongoCredential));
}
LOGGER.info("Connecting to Mongo: {}", client);
return client;
}
示例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");
}
}
示例7: testAuth
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
@Test
public void testAuth()
throws Exception
{
//MongoDB 3.0//
MongoCredential credential = MongoCredential.createScramSha1Credential( _DATABASE_, _USER_, _PASSWORD_.toCharArray() );
MongoClient client = new MongoClient( new ServerAddress( _HOST_, _PORT_ ), Arrays.asList( credential ) );
MongoDatabase db = client.getDatabase( _DATABASE_ );
//MongoDB 2.6//
// DB db = client.getDB( "opensec" );
// db.authenticate( "opensec", "opensec".toCharArray() );
db.getName();
Morphia morphia = new Morphia();
Datastore ds = morphia.createDatastore( client, _DATABASE_ );
ds.toString();
// DefinitionDAO dao = new DefinitionDAO( ds );
// long count = dao.count();
// System.out.println( "# OVAL Definitions: " + count );
}
示例8: 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);
}
示例9: 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;
}
示例10: init
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
/**
* @decription 初始化配置
* @author yi.zhang
* @time 2017年6月2日 下午2:15:57
*/
public void init(String servers,String database,String schema,String username,String password) {
try {
List<ServerAddress> saddress = new ArrayList<ServerAddress>();
if (servers != null && !"".equals(servers)) {
for (String server : servers.split(",")) {
String[] address = server.split(":");
String ip = address[0];
int port = 27017;
if (address != null && address.length > 1) {
port = Integer.valueOf(address[1]);
}
saddress.add(new ServerAddress(ip, port));
}
}
MongoCredential credential = MongoCredential.createScramSha1Credential(username, database,password.toCharArray());
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
credentials.add(credential);
Builder builder = new MongoClientOptions.Builder();
builder.maxWaitTime(MAX_WAIT_TIME);
// 通過連接認證獲取MongoDB連接
MongoClient client = new MongoClient(saddress, credentials, builder.build());
// 連接到數據庫
session = client.getDatabase(schema);
} catch (Exception e) {
logger.error("-----MongoDB Config init Error-----", e);
}
}
示例11: setCredential
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
/**
* @Title setCredential
* @author 00013052
* @Description user login setting
* @param userName user name
* @param database database
* @param password password
* @return user authentication
* @Date 2016.06.21 08:36:42
*/
private List<MongoCredential> setCredential(String userName, String database, String password) {
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
MongoCredential credential = MongoCredential.createScramSha1Credential(
userName,
database,
password.toCharArray()
);
credentials.add(credential);
return credentials;
}
示例12: init
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
public void init() {
try {
MongoCredential credential =
MongoCredential.createScramSha1Credential("mongo", "admin", "im2016".toCharArray());
ServerAddress serverAddress = new ServerAddress("172.16.0.123", 27017);
client = new MongoClient(serverAddress, Arrays.asList(credential));
db = client.getDB("im_message");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例13: FeedsCreator
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
public FeedsCreator(Configuration config) throws Exception {
morphia.map(Feed.class);
this.host = config.getParameter(HOST);
this.db = config.getParameter(DB);
this.username = config.getParameter(USERNAME);
this.password = config.getParameter(PASSWORD);
MongoClient mongoClient;
if(username != null && !username.equals("") && password != null && !password.equals("")) {
MongoClientOptions options = MongoClientOptions.builder().build();
ServerAddress srvAdr = new ServerAddress(host != null ? host : "localhost" , 27017);
MongoCredential credential = MongoCredential.createScramSha1Credential(username, "admin", password.toCharArray());
mongoClient = new MongoClient(srvAdr, Arrays.asList(credential), options);
}
else {
mongoClient = new MongoClient(host);
}
feedsDao = new BasicDAO<>(Feed.class, mongoClient, morphia, db);
// ensure capped collections
feedsDao.getDatastore().ensureCaps();
}
示例14: MorphiaManager
import com.mongodb.MongoCredential; //導入方法依賴的package包/類
private MorphiaManager(String host, int port, String username, String password) {
try {
if (mongoClient == null) {
Builder optionsBuilder = new MongoClientOptions.Builder().socketKeepAlive(true);
ServerAddress srvAdr = new ServerAddress(host != null ? host : "localhost" , port);
MongoCredential credential = MongoCredential.createScramSha1Credential(username, "admin", password.toCharArray());
mongoClient = new MongoClient(srvAdr, Arrays.asList(credential), optionsBuilder.build());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: 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;
}
}