[JAVA-625] SlaveOk Query fails with auth error even after logging in Created: 20/Aug/12  Updated: 25/Jun/13  Resolved: 21/Aug/12

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.8.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates JAVA-397 authentication for replica set fails ... Closed

 Description   

Copy and pasted from a user's comment on SERVER-6117:

I tested it on v2.2.0-rc1 and could reproduce the error.
Java code (using java-driver v2.8.0):

ArrayList<ServerAddress> servers = new ArrayList<ServerAddress>();
servers.add(new ServerAddress("s231", 20050));
servers.add(new ServerAddress("s231", 20051));
servers.add(new ServerAddress("s231", 20052));
 
Mongo m = new Mongo(servers);
 
m.setReadPreference(ReadPreference.SECONDARY);
final BasicDBObject query = new BasicDBObject();
final BasicDBObject fields = new BasicDBObject();
 
query.put("_id", new BasicDBObject("$gte", Integer.valueOf(1)));
fields.put("_id", Long.valueOf(1));
 
final DB db = m.getDB("offerStore");
boolean ok = db.authenticate("user", "pw".toCharArray());
System.out.println("ok: " + ok);
final DBCursor c = db.getCollection("offer").find(query, fields).limit(10);
 
while(c.hasNext()) {
DBObject offer = c.next();
System.out.println(offer);
}
c.close();

Output after several runs:

ok: false
Exception in thread "main" com.mongodb.MongoException: unauthorized db:offerStore ns:offerStore.offer lock type:0 client:192.x.y.z
        at com.mongodb.MongoException.parse(MongoException.java:82)
        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:317)
        at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:298)
        at com.mongodb.DBCursor._check(DBCursor.java:369)
        at com.mongodb.DBCursor._hasNext(DBCursor.java:492)
        at com.mongodb.DBCursor.hasNext(DBCursor.java:517)
        at de.idealo.offerstore.mongo.TempTest.authenticationTest(TempTest.java:507)
        at de.idealo.offerstore.mongo.TempTest.main(TempTest.java:716)


Generated at Thu Feb 08 08:52:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.