Announcement Announcement Module
Collapse
No announcement yet.
MongoException: unauthorized Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoException: unauthorized

    first time to use spring mongo but not successful:

    22:23:13 013 [main] ERROR org.springframework.web.context.ContextLoader:220 - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clickLogRepository': FactoryBean threw exception on object creation; nested exception is com.mongodb.MongoException: unauthorized
    ......
    Caused by: com.mongodb.MongoException: unauthorized
    at com.mongodb.CommandResult.getException(CommandResu lt.java:82)
    at com.mongodb.CommandResult.throwOnError(CommandResu lt.java:116)
    at com.mongodb.DBTCPConnector._checkWriteError(DBTCPC onnector.java:131)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :153)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :137)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa yer.java:255)
    at com.mongodb.DBApiLayer$MyCollection.createIndex(DB ApiLayer.java:347)
    at com.mongodb.DBCollection.ensureIndex(DBCollection. java:437)
    at org.springframework.data.document.mongodb.mapping. MongoPersistentEntityIndexCreator.ensureIndex(Mong oPersistentEntityIndexCreator.java:164)
    at org.springframework.data.document.mongodb.mapping. MongoPersistentEntityIndexCreator$1.doWithPersiste ntProperty(MongoPersistentEntityIndexCreator.java: 117)
    at org.springframework.data.mapping.BasicPersistentEn tity.doWithProperties(BasicPersistentEntity.java:1 12)
    at org.springframework.data.document.mongodb.mapping. MongoPersistentEntityIndexCreator.checkForIndexes( MongoPersistentEntityIndexCreator.java:99)
    at org.springframework.data.document.mongodb.mapping. MongoPersistentEntityIndexCreator.onApplicationEve nt(MongoPersistentEntityIndexCreator.java:73)
    at org.springframework.data.document.mongodb.mapping. MongoPersistentEntityIndexCreator.onApplicationEve nt(MongoPersistentEntityIndexCreator.java:50)
    at org.springframework.context.event.SimpleApplicatio nEventMulticaster.multicastEvent(SimpleApplication EventMulticaster.java:97)
    at org.springframework.context.support.AbstractApplic ationContext.publishEvent(AbstractApplicationConte xt.java:303)
    at org.springframework.data.mapping.AbstractMappingCo ntext.addPersistentEntity(AbstractMappingContext.j ava:214)
    at org.springframework.data.mapping.AbstractMappingCo ntext.getPersistentEntity(AbstractMappingContext.j ava:133)
    at org.springframework.data.mapping.AbstractMappingCo ntext.getPersistentEntity(AbstractMappingContext.j ava:114)
    at org.springframework.data.mapping.AbstractMappingCo ntext.getPersistentEntity(AbstractMappingContext.j ava:58)
    at org.springframework.data.document.mongodb.reposito ry.MongoRepositoryFactoryBean$EntityInformationCre ator.getEntityInformation(MongoRepositoryFactoryBe an.java:252)
    at org.springframework.data.document.mongodb.reposito ry.MongoRepositoryFactoryBean$MongoRepositoryFacto ry.getEntityInformation(MongoRepositoryFactoryBean .java:232)
    at org.springframework.data.document.mongodb.reposito ry.MongoRepositoryFactoryBean$MongoRepositoryFacto ry.getTargetRepository(MongoRepositoryFactoryBean. java:154)
    at org.springframework.data.repository.support.Reposi toryFactorySupport.getRepository(RepositoryFactory Support.java:133)
    at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:107)
    at org.springframework.data.repository.support.Reposi toryFactoryBeanSupport.getObject(RepositoryFactory BeanSupport.java:36)
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:142)
    ... 34 more


    configuration:
    <bean id="mongoDbFactory" class="org.springframework.data.document.mongodb.S impleMongoDbFactory">
    <constructor-arg name="mongo">
    <bean class="com.mongodb.Mongo">
    <constructor-arg value="localhost"/>
    <constructor-arg value="27017"/>
    </bean>
    </constructor-arg>
    <constructor-arg name="databaseName" value="test"/>
    </bean>

    <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.M ongoTemplate">
    <constructor-arg ref="mongoDbFactory"/>
    </bean>

    all to default, and output from the mongodb log:

    Thu Jun 16 22:22:19 BackgroundJob starting: DataFileSync
    Thu Jun 16 22:22:19 versionCmpTest passed
    Thu Jun 16 22:22:19 must specify both start and end of balancing window: { start: 1 }
    Thu Jun 16 22:22:19 must specify both start and end of balancing window: { stop: 1 }
    Thu Jun 16 22:22:19 cannot parse active window (use hh:mm 24hs format): { start: "21:30", stop: "28:35" }
    Thu Jun 16 22:22:19 BalancingWidowObjTest passed
    Thu Jun 16 22:22:19 shardObjTest passed
    Thu Jun 16 22:22:19 shardKeyTest passed
    Thu Jun 16 22:22:19 isInRangeTest passed
    Thu Jun 16 22:22:19 [initandlisten] MongoDB starting : pid=14001 port=27017 dbpath=/Users/lunzhong/tisproperty/db/mongo/data 64-bit
    Thu Jun 16 22:22:19 [initandlisten] db version v1.8.1, pdfile version 4.5
    Thu Jun 16 22:22:19 [initandlisten] git version: a429cd4f535b2499cc4130b06ff7c26f41c00f04
    Thu Jun 16 22:22:19 [initandlisten] build sys info: Darwin erh2.10gen.cc 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40
    Thu Jun 16 22:22:19 [initandlisten] query: local.system.namespaces{ name: /^local.temp./ }
    Thu Jun 16 22:22:19 [initandlisten] Accessing: local for the first time
    Thu Jun 16 22:22:19 [initandlisten] query local.system.namespaces reslen:36 nreturned:0 2ms
    Thu Jun 16 22:22:19 [initandlisten] enter repairDatabases (to check pdfile version #)
    Thu Jun 16 22:22:19 [initandlisten] test
    Thu Jun 16 22:22:19 [initandlisten] Accessing: test for the first time
    Thu Jun 16 22:22:19 [initandlisten] tisproperty
    Thu Jun 16 22:22:19 [initandlisten] Accessing: tisproperty for the first time
    Thu Jun 16 22:22:19 [initandlisten] done repairDatabases
    Thu Jun 16 22:22:19 BackgroundJob starting: snapshot
    Thu Jun 16 22:22:19 [initandlisten] waiting for connections on port 27017
    Thu Jun 16 22:22:19 BackgroundJob starting: ClientCursorMonitor
    Thu Jun 16 22:22:19 [initandlisten] fd limit hard:9223372036854775807 soft:256 max conn: 204
    Thu Jun 16 22:22:19 [websvr] web admin interface listening on port 28017
    Thu Jun 16 22:22:19 [websvr] fd limit hard:9223372036854775807 soft:256 max conn: 204
    Thu Jun 16 22:23:13 [initandlisten] connection accepted from 192.168.10.2:52980 #1
    Thu Jun 16 22:23:13 [conn1] query: admin.$cmd{ isMaster: 1 }
    Thu Jun 16 22:23:13 [conn1] run command admin.$cmd { isMaster: 1 }
    Thu Jun 16 22:23:13 [conn1] query admin.$cmd ntoreturn:1 command: { isMaster: 1 } reslen:87 0ms
    Thu Jun 16 22:23:13 [conn1] insert 0ms
    Thu Jun 16 22:23:13 [conn1] query: test.$cmd{ getlasterror: 1, w: 1, wtimeout: 0 }
    Thu Jun 16 22:23:13 [conn1] run command test.$cmd { getlasterror: 1, w: 1, wtimeout: 0 }
    Thu Jun 16 22:23:13 [conn1] query test.$cmd ntoreturn:1 command: { getlasterror: 1, w: 1, wtimeout: 0 } reslen:100 0ms
    Thu Jun 16 22:23:19 [DataFileSync] flushing mmap took 0ms for 1 files


    my mongodb i can access from command line without any problem.

  • #2
    ooooops, it seems mongodb java driver not working with security?! if i run the database (mongod process) WITHOUT the --auth, it is ok:

    public static void main(String[] args) throws UnknownHostException {
    Mongo mongo = new Mongo("localhost", 27017);
    DB db = mongo.getDB("test");
    Set<String> collNames = db.getCollectionNames();
    for (String n : collNames)
    System.out.print(n);
    }

    Comment


    • #3
      To use authentication you should specify UserCredentials when you configure the SimpleMongoDbFactory for the MongoTemplate.

      Comment

      Working...
      X