summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2013-09-20 19:38:40 -0400
committerSpencer T Brody <spencer@10gen.com>2013-09-23 11:42:10 -0400
commit9eb13c83ea429762c6a3d3c011fee23c81a720e2 (patch)
tree249fa3f9b792e841230621ab0c38eec27c2fa470
parentfc8201aec8acb3ee46fde6915702f1269b448c6c (diff)
downloadmongo-9eb13c83ea429762c6a3d3c011fee23c81a720e2.tar.gz
SERVER-9517 Implement generic insert, update, and remove methods in AuthzManagerExternalState
-rw-r--r--src/mongo/db/auth/authorization_manager_test.cpp3
-rw-r--r--src/mongo/db/auth/authz_manager_external_state.cpp58
-rw-r--r--src/mongo/db/auth/authz_manager_external_state.h13
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_d.cpp176
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_d.h15
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_mock.cpp6
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_mock.h3
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_s.cpp175
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_s.h15
9 files changed, 227 insertions, 237 deletions
diff --git a/src/mongo/db/auth/authorization_manager_test.cpp b/src/mongo/db/auth/authorization_manager_test.cpp
index e53a10a9e99..71f1272241d 100644
--- a/src/mongo/db/auth/authorization_manager_test.cpp
+++ b/src/mongo/db/auth/authorization_manager_test.cpp
@@ -403,7 +403,8 @@ namespace {
BSONObj()));
ASSERT_NOT_OK(authzManager->upgradeAuthCollections());
validateV1AdminUserData(usersCollectionName);
- ASSERT_OK(externalState->remove(versionCollectionName, BSONObj(), BSONObj()));
+ int numRemoved;
+ ASSERT_OK(externalState->remove(versionCollectionName, BSONObj(), BSONObj(), &numRemoved));
ASSERT_OK(authzManager->upgradeAuthCollections());
validateV1AdminUserData(backupUsersCollectionName);
validateV2UserData();
diff --git a/src/mongo/db/auth/authz_manager_external_state.cpp b/src/mongo/db/auth/authz_manager_external_state.cpp
index 88f326a18e8..c7dd09eb7be 100644
--- a/src/mongo/db/auth/authz_manager_external_state.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state.cpp
@@ -108,4 +108,62 @@ namespace mongo {
return _findUser(usersNamespace, query, &userBSONObj).isOK();
}
+
+ Status AuthzManagerExternalState::insertPrivilegeDocument(const string& dbname,
+ const BSONObj& userObj,
+ const BSONObj& writeConcern) {
+ Status status = insert(NamespaceString("admin.system.users"), userObj, writeConcern);
+ if (status.isOK()) {
+ return status;
+ }
+ if (status.code() == ErrorCodes::DuplicateKey) {
+ std::string name = userObj[AuthorizationManager::USER_NAME_FIELD_NAME].String();
+ std::string source = userObj[AuthorizationManager::USER_SOURCE_FIELD_NAME].String();
+ return Status(ErrorCodes::DuplicateKey,
+ mongoutils::str::stream() << "User \"" << name << "@" << source <<
+ "\" already exists");
+ }
+ if (status.code() == ErrorCodes::UnknownError) {
+ return Status(ErrorCodes::UserModificationFailed, status.reason());
+ }
+ return status;
+ }
+
+ Status AuthzManagerExternalState::updatePrivilegeDocument(
+ const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) {
+ Status status = updateOne(
+ NamespaceString("admin.system.users"),
+ BSON(AuthorizationManager::USER_NAME_FIELD_NAME << user.getUser() <<
+ AuthorizationManager::USER_SOURCE_FIELD_NAME << user.getDB()),
+ updateObj,
+ false,
+ writeConcern);
+ if (status.isOK()) {
+ return status;
+ }
+ if (status.code() == ErrorCodes::NoMatchingDocument) {
+ return Status(ErrorCodes::UserNotFound,
+ mongoutils::str::stream() << "User " << user.getFullName() <<
+ " not found");
+ }
+ if (status.code() == ErrorCodes::UnknownError) {
+ return Status(ErrorCodes::UserModificationFailed, status.reason());
+ }
+ return status;
+ }
+
+ Status AuthzManagerExternalState::removePrivilegeDocuments(const BSONObj& query,
+ const BSONObj& writeConcern,
+ int* numRemoved) {
+ Status status = remove(NamespaceString("admin.system.users"),
+ query,
+ writeConcern,
+ numRemoved);
+ if (status.code() == ErrorCodes::UnknownError) {
+ return Status(ErrorCodes::UserModificationFailed, status.reason());
+ }
+ return status;
+ }
+
+
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_manager_external_state.h b/src/mongo/db/auth/authz_manager_external_state.h
index be06ee3d08e..f75c49b416b 100644
--- a/src/mongo/db/auth/authz_manager_external_state.h
+++ b/src/mongo/db/auth/authz_manager_external_state.h
@@ -69,18 +69,18 @@ namespace mongo {
// TODO(spencer): remove dbname argument once users are only written into the admin db
virtual Status insertPrivilegeDocument(const std::string& dbname,
const BSONObj& userObj,
- const BSONObj& writeConcern) = 0;
+ const BSONObj& writeConcern);
// Updates the given user object with the given update modifier.
virtual Status updatePrivilegeDocument(const UserName& user,
const BSONObj& updateObj,
- const BSONObj& writeConcern) = 0;
+ const BSONObj& writeConcern);
// Removes users for the given database matching the given query.
// Writes into *numRemoved the number of user documents that were modified.
virtual Status removePrivilegeDocuments(const BSONObj& query,
const BSONObj& writeConcern,
- int* numRemoved) = 0;
+ int* numRemoved);
/**
* Puts into the *dbnames vector the name of every database in the cluster.
@@ -115,6 +115,7 @@ namespace mongo {
/**
* Inserts "document" into "collectionName".
+ * If there is a duplicate key error, returns a Status with code DuplicateKey.
*/
virtual Status insert(const NamespaceString& collectionName,
const BSONObj& document,
@@ -125,6 +126,9 @@ namespace mongo {
*
* If "upsert" is true and no document matches "query", inserts one using "query" as a
* template.
+ * If "upsert" is false and no document matches "query", return a Status with the code
+ * NoMatchingDocument. The Status message in that case is not very descriptive and should
+ * not be displayed to the end user.
*/
virtual Status updateOne(const NamespaceString& collectionName,
const BSONObj& query,
@@ -137,7 +141,8 @@ namespace mongo {
*/
virtual Status remove(const NamespaceString& collectionName,
const BSONObj& query,
- const BSONObj& writeConcern) = 0;
+ const BSONObj& writeConcern,
+ int* numRemoved) = 0;
/**
* Creates an index with the given pattern on "collectionName".
diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp
index f0967d919a2..8066e3c6a82 100644
--- a/src/mongo/db/auth/authz_manager_external_state_d.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp
@@ -51,11 +51,62 @@ namespace {
AuthzManagerExternalStateMongod::AuthzManagerExternalStateMongod() {}
AuthzManagerExternalStateMongod::~AuthzManagerExternalStateMongod() {}
- Status AuthzManagerExternalStateMongod::insertPrivilegeDocument(const string& dbname,
- const BSONObj& userObj,
- const BSONObj& writeConcern) {
+ Status AuthzManagerExternalStateMongod::_findUser(const string& usersNamespace,
+ const BSONObj& query,
+ BSONObj* result) {
+ Client::GodScope gs;
+ Client::ReadContext ctx(usersNamespace);
+
+ if (!Helpers::findOne(usersNamespace, query, *result)) {
+ return userNotFoundStatus;
+ }
+ return Status::OK();
+ }
+
+ Status AuthzManagerExternalStateMongod::query(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ const boost::function<void(const BSONObj&)>& resultProcessor) {
+ try {
+ DBDirectClient client;
+ Client::GodScope gs;
+ client.query(resultProcessor, collectionName.ns(), query);
+ return Status::OK();
+ } catch (const DBException& e) {
+ return e.toStatus();
+ }
+ }
+
+ Status AuthzManagerExternalStateMongod::getAllDatabaseNames(
+ std::vector<std::string>* dbnames) {
+ Lock::GlobalWrite lk;
+ getDatabaseNames(*dbnames);
+ return Status::OK();
+ }
+
+ Status AuthzManagerExternalStateMongod::getAllV1PrivilegeDocsForDB(
+ const std::string& dbname, std::vector<BSONObj>* privDocs) {
+ std::string usersNamespace = dbname + ".system.users";
+
+ Client::GodScope gs;
+ Client::ReadContext ctx(usersNamespace);
+
+ *privDocs = Helpers::findAll(usersNamespace, BSONObj());
+ return Status::OK();
+ }
+
+ Status AuthzManagerExternalStateMongod::findOne(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ BSONObj* result) {
+ fassertFailed(17091);
+ }
+
+ Status AuthzManagerExternalStateMongod::insert(
+ const NamespaceString& collectionName,
+ const BSONObj& document,
+ const BSONObj& writeConcern) {
try {
- const std::string userNS = "admin.system.users";
DBDirectClient client;
{
Client::GodScope gs;
@@ -64,7 +115,7 @@ namespace {
// WriteContext below
Lock::GlobalWrite w;
// Client::WriteContext ctx(userNS);
- client.insert(userNS, userObj);
+ client.insert(collectionName, document);
}
// Handle write concern
@@ -78,22 +129,21 @@ namespace {
return Status::OK();
}
if (res.hasField("code") && res["code"].Int() == ASSERT_ID_DUPKEY) {
- std::string name = userObj[AuthorizationManager::USER_NAME_FIELD_NAME].String();
- std::string source = userObj[AuthorizationManager::USER_SOURCE_FIELD_NAME].String();
- return Status(ErrorCodes::DuplicateKey,
- mongoutils::str::stream() << "User \"" << name << "@" << source <<
- "\" already exists");
+ return Status(ErrorCodes::DuplicateKey, errstr);
}
- return Status(ErrorCodes::UserModificationFailed, errstr);
+ return Status(ErrorCodes::UnknownError, errstr);
} catch (const DBException& e) {
return e.toStatus();
}
}
- Status AuthzManagerExternalStateMongod::updatePrivilegeDocument(
- const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) {
+ Status AuthzManagerExternalStateMongod::updateOne(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ const BSONObj& updatePattern,
+ bool upsert,
+ const BSONObj& writeConcern) {
try {
- const std::string userNS = "admin.system.users";
DBDirectClient client;
{
Client::GodScope gs;
@@ -102,10 +152,7 @@ namespace {
// WriteContext below
Lock::GlobalWrite w;
// Client::WriteContext ctx(userNS);
- client.update(userNS,
- QUERY(AuthorizationManager::USER_NAME_FIELD_NAME << user.getUser() <<
- AuthorizationManager::USER_SOURCE_FIELD_NAME << user.getDB()),
- updateObj);
+ client.update(collectionName, query, updatePattern, upsert);
}
// Handle write concern
@@ -116,15 +163,13 @@ namespace {
client.runCommand("admin", gleBuilder.done(), res);
string err = client.getLastErrorString(res);
if (!err.empty()) {
- return Status(ErrorCodes::UserModificationFailed, err);
+ return Status(ErrorCodes::UnknownError, err);
}
int numUpdated = res["n"].numberInt();
dassert(numUpdated <= 1 && numUpdated >= 0);
if (numUpdated == 0) {
- return Status(ErrorCodes::UserNotFound,
- mongoutils::str::stream() << "User " << user.getFullName() <<
- " not found");
+ return Status(ErrorCodes::NoMatchingDocument, "No document found");
}
return Status::OK();
@@ -133,11 +178,12 @@ namespace {
}
}
- Status AuthzManagerExternalStateMongod::removePrivilegeDocuments(const BSONObj& query,
- const BSONObj& writeConcern,
- int* numRemoved) {
+ Status AuthzManagerExternalStateMongod::remove(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ const BSONObj& writeConcern,
+ int* numRemoved) {
try {
- const std::string userNS = "admin.system.users";
DBDirectClient client;
{
Client::GodScope gs;
@@ -146,7 +192,7 @@ namespace {
// WriteContext below
Lock::GlobalWrite w;
// Client::WriteContext ctx(userNS);
- client.remove(userNS, query);
+ client.remove(collectionName, query);
}
// Handle write concern
@@ -157,7 +203,7 @@ namespace {
client.runCommand("admin", gleBuilder.done(), res);
string errstr = client.getLastErrorString(res);
if (!errstr.empty()) {
- return Status(ErrorCodes::UserModificationFailed, errstr);
+ return Status(ErrorCodes::UnknownError, errstr);
}
*numRemoved = res["n"].numberInt();
@@ -167,80 +213,6 @@ namespace {
}
}
- Status AuthzManagerExternalStateMongod::_findUser(const string& usersNamespace,
- const BSONObj& query,
- BSONObj* result) {
- Client::GodScope gs;
- Client::ReadContext ctx(usersNamespace);
-
- if (!Helpers::findOne(usersNamespace, query, *result)) {
- return userNotFoundStatus;
- }
- return Status::OK();
- }
-
- Status AuthzManagerExternalStateMongod::query(
- const NamespaceString& collectionName,
- const BSONObj& query,
- const boost::function<void(const BSONObj&)>& resultProcessor) {
- try {
- DBDirectClient client;
- Client::GodScope gs;
- client.query(resultProcessor, collectionName.ns(), query);
- return Status::OK();
- } catch (const DBException& e) {
- return e.toStatus();
- }
- }
-
- Status AuthzManagerExternalStateMongod::getAllDatabaseNames(
- std::vector<std::string>* dbnames) {
- Lock::GlobalWrite lk;
- getDatabaseNames(*dbnames);
- return Status::OK();
- }
-
- Status AuthzManagerExternalStateMongod::getAllV1PrivilegeDocsForDB(
- const std::string& dbname, std::vector<BSONObj>* privDocs) {
- std::string usersNamespace = dbname + ".system.users";
-
- Client::GodScope gs;
- Client::ReadContext ctx(usersNamespace);
-
- *privDocs = Helpers::findAll(usersNamespace, BSONObj());
- return Status::OK();
- }
-
- Status AuthzManagerExternalStateMongod::findOne(
- const NamespaceString& collectionName,
- const BSONObj& query,
- BSONObj* result) {
- fassertFailed(17091);
- }
-
- Status AuthzManagerExternalStateMongod::insert(
- const NamespaceString& collectionName,
- const BSONObj& document,
- const BSONObj& writeConcern) {
- fassertFailed(17092);
- }
-
- Status AuthzManagerExternalStateMongod::updateOne(
- const NamespaceString& collectionName,
- const BSONObj& query,
- const BSONObj& updatePattern,
- bool upsert,
- const BSONObj& writeConcern) {
- fassertFailed(17093);
- }
-
- Status AuthzManagerExternalStateMongod::remove(
- const NamespaceString& collectionName,
- const BSONObj& query,
- const BSONObj& writeConcern) {
- fassertFailed(17094);
- }
-
Status AuthzManagerExternalStateMongod::createIndex(
const NamespaceString& collectionName,
const BSONObj& pattern,
diff --git a/src/mongo/db/auth/authz_manager_external_state_d.h b/src/mongo/db/auth/authz_manager_external_state_d.h
index ab7e1dd384d..d6ee4a445d3 100644
--- a/src/mongo/db/auth/authz_manager_external_state_d.h
+++ b/src/mongo/db/auth/authz_manager_external_state_d.h
@@ -49,18 +49,6 @@ namespace mongo {
AuthzManagerExternalStateMongod();
virtual ~AuthzManagerExternalStateMongod();
- virtual Status insertPrivilegeDocument(const std::string& dbname,
- const BSONObj& userObj,
- const BSONObj& writeConcern);
-
- virtual Status updatePrivilegeDocument(const UserName& user,
- const BSONObj& updateObj,
- const BSONObj& writeConcern);
-
- virtual Status removePrivilegeDocuments(const BSONObj& query,
- const BSONObj& writeConcern,
- int* numRemoved);
-
virtual Status getAllDatabaseNames(std::vector<std::string>* dbnames);
virtual Status getAllV1PrivilegeDocsForDB(const std::string& dbname,
@@ -82,7 +70,8 @@ namespace mongo {
const BSONObj& writeConcern);
virtual Status remove(const NamespaceString& collectionName,
const BSONObj& query,
- const BSONObj& writeConcern);
+ const BSONObj& writeConcern,
+ int* numRemoved);
virtual Status createIndex(const NamespaceString& collectionName,
const BSONObj& pattern,
bool unique,
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp
index f62f8243a08..d0b8cd659e9 100644
--- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp
@@ -185,11 +185,15 @@ namespace mongo {
Status AuthzManagerExternalStateMock::remove(
const NamespaceString& collectionName,
const BSONObj& query,
- const BSONObj&) {
+ const BSONObj&,
+ int* numRemoved) {
+ int n = 0;
BSONObjCollection::iterator iter;
while (_findOneIter(collectionName, query, &iter).isOK()) {
_documents[collectionName].erase(iter);
+ ++n;
}
+ *numRemoved = n;
return Status::OK();
}
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.h b/src/mongo/db/auth/authz_manager_external_state_mock.h
index c26152a8c74..ed1bcfe8534 100644
--- a/src/mongo/db/auth/authz_manager_external_state_mock.h
+++ b/src/mongo/db/auth/authz_manager_external_state_mock.h
@@ -97,7 +97,8 @@ namespace mongo {
const BSONObj& writeConcern);
virtual Status remove(const NamespaceString& collectionName,
const BSONObj& query,
- const BSONObj& writeConcern);
+ const BSONObj& writeConcern,
+ int* numRemoved);
virtual Status createIndex(const NamespaceString& collectionName,
const BSONObj& pattern,
bool unique,
diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp
index c6f31ab37c5..fa033d81420 100644
--- a/src/mongo/db/auth/authz_manager_external_state_s.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp
@@ -98,14 +98,61 @@ namespace {
}
}
- Status AuthzManagerExternalStateMongos::insertPrivilegeDocument(const string& dbname,
- const BSONObj& userObj,
- const BSONObj& writeConcern) {
+ Status AuthzManagerExternalStateMongos::getAllDatabaseNames(
+ std::vector<std::string>* dbnames) {
+ try {
+ scoped_ptr<ScopedDbConnection> conn(
+ getConnectionForAuthzCollection(DatabaseType::ConfigNS));
+ auto_ptr<DBClientCursor> c = conn->get()->query(DatabaseType::ConfigNS, Query());
+
+ while (c->more()) {
+ DatabaseType dbInfo;
+ std::string errmsg;
+ if (!dbInfo.parseBSON( c->nextSafe(), &errmsg) || !dbInfo.isValid( &errmsg )) {
+ return Status(ErrorCodes::FailedToParse, errmsg);
+ }
+ dbnames->push_back(dbInfo.getName());
+ }
+ conn->done();
+ dbnames->push_back("config"); // config db isn't listed in config.databases
+ return Status::OK();
+ } catch (const DBException& e) {
+ return e.toStatus();
+ }
+ }
+
+ Status AuthzManagerExternalStateMongos::getAllV1PrivilegeDocsForDB(
+ const std::string& dbname, std::vector<BSONObj>* privDocs) {
+ try {
+ std::string usersNamespace = dbname + ".system.users";
+ scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(usersNamespace));
+ auto_ptr<DBClientCursor> c = conn->get()->query(usersNamespace, Query());
+
+ while (c->more()) {
+ privDocs->push_back(c->nextSafe().getOwned());
+ }
+ conn->done();
+ return Status::OK();
+ } catch (const DBException& e) {
+ return e.toStatus();
+ }
+ }
+
+ Status AuthzManagerExternalStateMongos::findOne(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ BSONObj* result) {
+ fassertFailed(17101);
+ }
+
+ Status AuthzManagerExternalStateMongos::insert(
+ const NamespaceString& collectionName,
+ const BSONObj& document,
+ const BSONObj& writeConcern) {
try {
- const std::string userNS = "admin.system.users";
- scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(userNS));
+ scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(collectionName));
- conn->get()->insert(userNS, userObj);
+ conn->get()->insert(collectionName, document);
// Handle write concern
BSONObjBuilder gleBuilder;
@@ -120,29 +167,24 @@ namespace {
return Status::OK();
}
if (res.hasField("code") && res["code"].Int() == ASSERT_ID_DUPKEY) {
- std::string name = userObj[AuthorizationManager::USER_NAME_FIELD_NAME].String();
- std::string source = userObj[AuthorizationManager::USER_SOURCE_FIELD_NAME].String();
- return Status(ErrorCodes::DuplicateKey,
- mongoutils::str::stream() << "User \"" << name << "@" << source <<
- "\" already exists");
+ return Status(ErrorCodes::DuplicateKey, errstr);
}
- return Status(ErrorCodes::UserModificationFailed, errstr);
+ return Status(ErrorCodes::UnknownError, errstr);
} catch (const DBException& e) {
return e.toStatus();
}
}
- Status AuthzManagerExternalStateMongos::updatePrivilegeDocument(
- const UserName& user, const BSONObj& updateObj, const BSONObj& writeConcern) {
+ Status AuthzManagerExternalStateMongos::updateOne(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ const BSONObj& updatePattern,
+ bool upsert,
+ const BSONObj& writeConcern) {
try {
- const std::string userNS = "admin.system.users";
- scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(userNS));
+ scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(collectionName));
- conn->get()->update(
- userNS,
- QUERY(AuthorizationManager::USER_NAME_FIELD_NAME << user.getUser() <<
- AuthorizationManager::USER_SOURCE_FIELD_NAME << user.getDB()),
- updateObj);
+ conn->get()->update(collectionName, query, updatePattern, upsert);
// Handle write concern
BSONObjBuilder gleBuilder;
@@ -154,15 +196,13 @@ namespace {
conn->done();
if (!err.empty()) {
- return Status(ErrorCodes::UserModificationFailed, err);
+ return Status(ErrorCodes::UnknownError, err);
}
int numUpdated = res["n"].numberInt();
dassert(numUpdated <= 1 && numUpdated >= 0);
if (numUpdated == 0) {
- return Status(ErrorCodes::UserNotFound,
- mongoutils::str::stream() << "User " << user.getFullName() <<
- " not found");
+ return Status(ErrorCodes::NoMatchingDocument, "No document found");
}
return Status::OK();
@@ -171,14 +211,15 @@ namespace {
}
}
- Status AuthzManagerExternalStateMongos::removePrivilegeDocuments(const BSONObj& query,
- const BSONObj& writeConcern,
- int* numRemoved) {
+ Status AuthzManagerExternalStateMongos::remove(
+ const NamespaceString& collectionName,
+ const BSONObj& query,
+ const BSONObj& writeConcern,
+ int* numRemoved) {
try {
- string userNS = "admin.system.users";
- scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(userNS));
+ scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(collectionName));
- conn->get()->remove(userNS, query);
+ conn->get()->remove(collectionName, query);
// Handle write concern
BSONObjBuilder gleBuilder;
@@ -190,7 +231,7 @@ namespace {
conn->done();
if (!err.empty()) {
- return Status(ErrorCodes::UserModificationFailed, err);
+ return Status(ErrorCodes::UnknownError, err);
}
*numRemoved = res["n"].numberInt();
@@ -200,76 +241,6 @@ namespace {
}
}
- Status AuthzManagerExternalStateMongos::getAllDatabaseNames(
- std::vector<std::string>* dbnames) {
- try {
- scoped_ptr<ScopedDbConnection> conn(
- getConnectionForAuthzCollection(DatabaseType::ConfigNS));
- auto_ptr<DBClientCursor> c = conn->get()->query(DatabaseType::ConfigNS, Query());
-
- while (c->more()) {
- DatabaseType dbInfo;
- std::string errmsg;
- if (!dbInfo.parseBSON( c->nextSafe(), &errmsg) || !dbInfo.isValid( &errmsg )) {
- return Status(ErrorCodes::FailedToParse, errmsg);
- }
- dbnames->push_back(dbInfo.getName());
- }
- conn->done();
- dbnames->push_back("config"); // config db isn't listed in config.databases
- return Status::OK();
- } catch (const DBException& e) {
- return e.toStatus();
- }
- }
-
- Status AuthzManagerExternalStateMongos::getAllV1PrivilegeDocsForDB(
- const std::string& dbname, std::vector<BSONObj>* privDocs) {
- try {
- std::string usersNamespace = dbname + ".system.users";
- scoped_ptr<ScopedDbConnection> conn(getConnectionForAuthzCollection(usersNamespace));
- auto_ptr<DBClientCursor> c = conn->get()->query(usersNamespace, Query());
-
- while (c->more()) {
- privDocs->push_back(c->nextSafe().getOwned());
- }
- conn->done();
- return Status::OK();
- } catch (const DBException& e) {
- return e.toStatus();
- }
- }
-
- Status AuthzManagerExternalStateMongos::findOne(
- const NamespaceString& collectionName,
- const BSONObj& query,
- BSONObj* result) {
- fassertFailed(17101);
- }
-
- Status AuthzManagerExternalStateMongos::insert(
- const NamespaceString& collectionName,
- const BSONObj& document,
- const BSONObj& writeConcern) {
- fassertFailed(17102);
- }
-
- Status AuthzManagerExternalStateMongos::updateOne(
- const NamespaceString& collectionName,
- const BSONObj& query,
- const BSONObj& updatePattern,
- bool upsert,
- const BSONObj& writeConcern) {
- fassertFailed(17103);
- }
-
- Status AuthzManagerExternalStateMongos::remove(
- const NamespaceString& collectionName,
- const BSONObj& query,
- const BSONObj& writeConcern) {
- fassertFailed(17104);
- }
-
Status AuthzManagerExternalStateMongos::createIndex(
const NamespaceString& collectionName,
const BSONObj& pattern,
diff --git a/src/mongo/db/auth/authz_manager_external_state_s.h b/src/mongo/db/auth/authz_manager_external_state_s.h
index d9f67956266..00e6e123120 100644
--- a/src/mongo/db/auth/authz_manager_external_state_s.h
+++ b/src/mongo/db/auth/authz_manager_external_state_s.h
@@ -51,18 +51,6 @@ namespace mongo {
AuthzManagerExternalStateMongos();
virtual ~AuthzManagerExternalStateMongos();
- virtual Status insertPrivilegeDocument(const std::string& dbname,
- const BSONObj& userObj,
- const BSONObj& writeConcern);
-
- virtual Status updatePrivilegeDocument(const UserName& user,
- const BSONObj& updateObj,
- const BSONObj& writeConcern);
-
- virtual Status removePrivilegeDocuments(const BSONObj& query,
- const BSONObj& writeConcern,
- int* numRemoved);
-
virtual Status getAllDatabaseNames(std::vector<std::string>* dbnames);
virtual Status getAllV1PrivilegeDocsForDB(const std::string& dbname,
@@ -84,7 +72,8 @@ namespace mongo {
const BSONObj& writeConcern);
virtual Status remove(const NamespaceString& collectionName,
const BSONObj& query,
- const BSONObj& writeConcern);
+ const BSONObj& writeConcern,
+ int* numRemoved);
virtual Status createIndex(const NamespaceString& collectionName,
const BSONObj& pattern,
bool unique,