diff options
author | Spencer T Brody <spencer@10gen.com> | 2013-09-20 19:38:40 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2013-09-23 11:42:10 -0400 |
commit | 9eb13c83ea429762c6a3d3c011fee23c81a720e2 (patch) | |
tree | 249fa3f9b792e841230621ab0c38eec27c2fa470 /src/mongo/db/auth/authz_manager_external_state.cpp | |
parent | fc8201aec8acb3ee46fde6915702f1269b448c6c (diff) | |
download | mongo-9eb13c83ea429762c6a3d3c011fee23c81a720e2.tar.gz |
SERVER-9517 Implement generic insert, update, and remove methods in AuthzManagerExternalState
Diffstat (limited to 'src/mongo/db/auth/authz_manager_external_state.cpp')
-rw-r--r-- | src/mongo/db/auth/authz_manager_external_state.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
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 |