diff options
author | Spencer T Brody <spencer@10gen.com> | 2013-06-27 17:10:39 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2013-07-01 17:41:53 -0400 |
commit | 90f1d8947a26b330accfaf69dc25ee1d892891d1 (patch) | |
tree | 320cfc0363fbbbb09b85f1743b200cb76cd0949b /src/mongo/db/auth/authz_manager_external_state_mock.cpp | |
parent | d15b27260f62349d9d9aac0b53d60eaf284492c3 (diff) | |
download | mongo-90f1d8947a26b330accfaf69dc25ee1d892891d1.tar.gz |
SERVER-9518 Initial implementation of acquire/releaseUser methods in AuthorizationManager
Diffstat (limited to 'src/mongo/db/auth/authz_manager_external_state_mock.cpp')
-rw-r--r-- | src/mongo/db/auth/authz_manager_external_state_mock.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp new file mode 100644 index 00000000000..7e2e97d824b --- /dev/null +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -0,0 +1,68 @@ +/* +* Copyright (C) 2013 10gen Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "mongo/db/auth/authz_manager_external_state_mock.h" + +#include <string> + +#include "mongo/base/status.h" +#include "mongo/db/jsobj.h" +#include "mongo/db/matcher/expression_parser.h" +#include "mongo/db/namespacestring.h" +#include "mongo/platform/unordered_map.h" + +namespace mongo { + + Status AuthzManagerExternalStateMock::insertPrivilegeDocument(const std::string& dbname, + const BSONObj& userObj) const { + return Status::OK(); + } + + Status AuthzManagerExternalStateMock::updatePrivilegeDocument(const UserName& user, + const BSONObj& updateObj) const { + return Status::OK(); + } + + Status AuthzManagerExternalStateMock::insertPrivilegeDocument(const std::string& dbname, + const BSONObj& userObj) { + _userDocuments.insert(make_pair(dbname, userObj)); + return Status::OK(); + } + + void AuthzManagerExternalStateMock::clearPrivilegeDocuments() { + _userDocuments.clear(); + } + + bool AuthzManagerExternalStateMock::_findUser(const std::string& usersNamespace, + const BSONObj& query, + BSONObj* result) const { + StatusWithMatchExpression parseResult = MatchExpressionParser::parse(query); + if (!parseResult.isOK()) { + return false; + } + MatchExpression* matcher = parseResult.getValue(); + + for (unordered_map<std::string, BSONObj>::const_iterator it = _userDocuments.begin(); + it != _userDocuments.end(); ++it) { + if (nsToDatabase(usersNamespace) == it->first && matcher->matchesBSON(it->second)) { + *result = it->second; + return true; + } + } + return false; + } + +} // namespace mongo |