当前位置: 首页>>代码示例>>Java>>正文


Java DB.authenticate方法代码示例

本文整理汇总了Java中com.mongodb.DB.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Java DB.authenticate方法的具体用法?Java DB.authenticate怎么用?Java DB.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.DB的用法示例。


在下文中一共展示了DB.authenticate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDB

import com.mongodb.DB; //导入方法依赖的package包/类
public DB getDB(String database, String username, String password) {

        if(log.isDebugEnabled()) {
            log.debug("username: " + username+", password: " + password+", database: " + database);
        }
        DB db = mongo.getDB(database);
        boolean authenticated = db.isAuthenticated();

        if(!authenticated) {
            if(username != null && password != null && username.length() > 0 && password.length() > 0) {
                authenticated = db.authenticate(username, password.toCharArray());
            }
        }
        if(log.isDebugEnabled()) {
            log.debug("authenticated: " + authenticated);
        }
        return db;
    }
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:19,代码来源:MongoDB.java

示例2: MongoLog

import com.mongodb.DB; //导入方法依赖的package包/类
public MongoLog( String sessionID, String dbName ) throws UnknownHostException {
    mongo = new Mongo( HOST_IP_ADDRESS, PORT );

    // All sessions are stored in the same DB.  Having a separate DB for
    // each uses an excessive amount of disk space.
    DB database = mongo.getDB( dbName );

    // Authenticate.
    try {
        boolean auth = database.authenticate( "phetsimclient", ( MER + SimSharingManager.MONGO_PASSWORD + "" + ( 2 * 2 * 2 ) + "ss0O88723otbubaoue" ).toCharArray() );
        if ( !auth ) {
            new RuntimeException( "Authentication failed" ).printStackTrace();
        }
    }

    //A MongoException.Network indicates a failure to reach mongo for the authentication attempt, and hence there is probably no internet connection.  See #3304
    catch ( MongoException.Network exception ) {
        LOGGER.warning( "Failed to connect to mongo during authentication.  Perhaps there is no internet connection." );
    }

    //One collection per session, lets us easily iterate and add messages per session.
    collection = database.getCollection( sessionID );

    /*
     * Mongo logs entire stack traces when failure occur, which is incredibly annoying.
     * Turn off Mongo logging here by interrogating the LogManager.
     * Do this at the end of the constructor, so that Mongo loggers have been instantiated.
     */
    LOGGER.info( "turning off MongoDB loggers" );
    Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
    while ( names.hasMoreElements() ) {
        String name = names.nextElement();
        if ( name.startsWith( "com.mongodb" ) ) {
            LogManager.getLogManager().getLogger( name ).setLevel( Level.OFF );
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:38,代码来源:MongoLog.java

示例3: main

import com.mongodb.DB; //导入方法依赖的package包/类
public static void main( String[] args ) throws UnknownHostException {
    Mongo m = new Mongo( MongoLog.HOST_IP_ADDRESS, MongoLog.PORT );
    DB db = m.getDB( MongoLoadTester.LOAD_TESTING_DB_NAME );
    boolean authenticated = db.authenticate( MongoLoadTester.DB_USER_NAME,
                                             ( MongoLoadTester.MER + SimSharingManager.MONGO_PASSWORD + "" + ( 2 * 2 * 2 ) + "ss0O88723otbubaoue" ).toCharArray() );

    System.out.println( "authenticated = " + authenticated );
    if ( !authenticated ) {
        System.out.println( "Authentication failed, aborting test." );
        return;
    }
    DBCollection collection = db.getCollection( MongoLoadTester.DB_COLLECTION );
    long count = collection.getCount();
    System.out.println( "count = " + count );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:MongoLoadTesterReader.java

示例4: MongoPojoCache

import com.mongodb.DB; //导入方法依赖的package包/类
public MongoPojoCache(String bucket) {
    MongoClient mongo;
    try {
        mongo = new MongoClient(mongodb_host, mongodb_port);
        DB db = mongo.getDB(dbname);
        db.authenticate("username", "password".toCharArray()); //FIXME: load from config file
        gridfs = new GridFS(db, bucket);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}
 
开发者ID:oaqa,项目名称:LiveQA,代码行数:12,代码来源:MongoPojoCache.java


注:本文中的com.mongodb.DB.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。