Skip to content

Commit e3d4cbb

Browse files
committed
JAVA-691: Always acquire write privileges for now.
1 parent 68ce179 commit e3d4cbb

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ protected void close(){
304304
_socket = null;
305305
}
306306

307-
void checkAuth(DB db, final boolean writePrivilegesRequired) throws IOException {
307+
void checkAuth(DB db) throws IOException {
308308
// TODO: add support for retry when credentials ticket times out
309309
if (db.getMongo().getCredentials() != null) {
310310
if (!globallyAuthed) {
@@ -314,14 +314,14 @@ void checkAuth(DB db, final boolean writePrivilegesRequired) throws IOException
314314
new GSSAPIAuthenticator(this, db.getMongo()).authenticate();
315315
globallyAuthed = true;
316316
}
317-
saslAquireDatabasePrivileges(db, writePrivilegesRequired);
317+
saslAcquirePrivilegeForDatabase(db);
318318
}
319319
else {
320320
DB.AuthenticationCredentials credentials = db.getAuthenticationCredentials();
321321
if (credentials == null) {
322322
if (db._name.equals("admin"))
323323
return;
324-
checkAuth(db._mongo.getDB("admin"), writePrivilegesRequired);
324+
checkAuth(db._mongo.getDB("admin"));
325325
return;
326326
}
327327
if (_authed.containsKey(db))
@@ -337,24 +337,15 @@ void checkAuth(DB db, final boolean writePrivilegesRequired) throws IOException
337337
}
338338
}
339339

340-
private void saslAquireDatabasePrivileges(final DB db, final boolean writePrivilegesRequired) throws IOException {
340+
private void saslAcquirePrivilegeForDatabase(final DB db) throws IOException {
341341
BasicDBObject acquirePrivilegeCmd = new BasicDBObject("acquirePrivilege", 1).
342-
append("principal", db.getMongo().getCredentials().getUserName()).append("resource", db.getName());
343-
if (writePrivilegesRequired) {
344-
if (_saslWriteAuthed.get(db) == null) {
345-
acquirePrivilegeCmd.append("actions", Arrays.asList("oldWrite"));
346-
CommandResult res = runCommand(db.getSisterDB("admin"), acquirePrivilegeCmd);
347-
res.throwOnError();
348-
_saslWriteAuthed.put(db, true);
349-
_saslReadAuthed.put(db, true);
350-
}
351-
} else {
352-
if (_saslReadAuthed.get(db) == null) {
353-
acquirePrivilegeCmd.append("actions", Arrays.asList("oldRead"));
354-
CommandResult res = runCommand(db.getSisterDB("admin"), acquirePrivilegeCmd);
355-
res.throwOnError();
356-
_saslReadAuthed.put(db, true);
357-
}
342+
append("principal", db.getMongo().getCredentials().getUserName()).
343+
append("resource", db.getName());
344+
if (_saslAuthed.get(db) == null) {
345+
acquirePrivilegeCmd.append("actions", Arrays.asList("oldWrite"));
346+
CommandResult res = runCommand(db.getSisterDB("admin"), acquirePrivilegeCmd);
347+
res.throwOnError();
348+
_saslAuthed.put(db, true);
358349
}
359350
}
360351

@@ -381,8 +372,7 @@ public DBPortPool getPool() {
381372
private boolean _processingResponse;
382373

383374
private Map<DB,Boolean> _authed = new ConcurrentHashMap<DB, Boolean>( );
384-
private Map<DB,Boolean> _saslReadAuthed = new ConcurrentHashMap<DB, Boolean>( );
385-
private Map<DB,Boolean> _saslWriteAuthed = new ConcurrentHashMap<DB, Boolean>( );
375+
private Map<DB,Boolean> _saslAuthed = new ConcurrentHashMap<DB, Boolean>( );
386376
int _lastThread;
387377
long _calls = 0;
388378
private volatile ActiveState _activeState;

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern , ServerAddr
177177
DBPort port = mp.get( true , ReadPreference.primary(), hostNeeded );
178178

179179
try {
180-
port.checkAuth( db, true);
180+
port.checkAuth( db );
181181
port.say( m );
182182
if ( concern.callGetLastError() ){
183183
return _checkWriteError( db , port , concern );
@@ -282,7 +282,7 @@ private Response innerCall(final DB db, final DBCollection coll, final OutMessag
282282
Response res = null;
283283
boolean retry = false;
284284
try {
285-
port.checkAuth( db, false);
285+
port.checkAuth( db );
286286
res = port.call( m , coll, decoder );
287287
if ( res._responseTo != m.getId() )
288288
throw new MongoException( "ids don't match" );

0 commit comments

Comments
 (0)