diff options
author | Spencer T Brody <spencer@10gen.com> | 2013-06-01 03:40:00 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2013-06-01 03:40:00 -0400 |
commit | f87c096e7d78c30f1e7c660fe4ad718d9b821217 (patch) | |
tree | 38a1489661827fede6b525ff43cff158a9f1e174 /src/mongo/db | |
parent | 661a68e0bd5d9679afa6a1fc9f371bb17a15129e (diff) | |
download | mongo-f87c096e7d78c30f1e7c660fe4ad718d9b821217.tar.gz |
Revert "Add pointer to AuthorizationManager to AuthzSessionExternalState"
This reverts commit 661a68e0bd5d9679afa6a1fc9f371bb17a15129e.
Diffstat (limited to 'src/mongo/db')
16 files changed, 53 insertions, 152 deletions
diff --git a/src/mongo/db/auth/authorization_manager.cpp b/src/mongo/db/auth/authorization_manager.cpp index f7f6209330f..5ab155ebb17 100644 --- a/src/mongo/db/auth/authorization_manager.cpp +++ b/src/mongo/db/auth/authorization_manager.cpp @@ -34,11 +34,11 @@ namespace mongo { bool AuthorizationManager::_doesSupportOldStylePrivileges = true; bool AuthorizationManager::_authEnabled = false; - AuthorizationManager::AuthorizationManager(AuthzManagerExternalState* externalState) : - _externalState(externalState) {} + AuthorizationManager::AuthorizationManager(AuthzManagerExternalState* globalExternalState) : + _globalExternalState(globalExternalState) {} AuthzManagerExternalState* AuthorizationManager::getExternalState() const { - return _externalState.get(); + return _globalExternalState.get(); } void AuthorizationManager::setSupportOldStylePrivilegeDocuments(bool enabled) { @@ -57,14 +57,4 @@ namespace mongo { return _authEnabled; } - Status AuthorizationManager::getPrivilegeDocument(const std::string& dbname, - const UserName& userName, - BSONObj* result) { - return _externalState->getPrivilegeDocument(dbname, userName, result); - } - - bool AuthorizationManager::hasPrivilegeDocument(const std::string& dbname) const { - return _externalState->hasPrivilegeDocument(dbname); - } - } // namespace mongo diff --git a/src/mongo/db/auth/authorization_manager.h b/src/mongo/db/auth/authorization_manager.h index 68d148cdb48..eea50c699ce 100644 --- a/src/mongo/db/auth/authorization_manager.h +++ b/src/mongo/db/auth/authorization_manager.h @@ -20,10 +20,7 @@ #include <string> #include "mongo/base/disallow_copying.h" -#include "mongo/base/status.h" #include "mongo/db/auth/authz_manager_external_state.h" -#include "mongo/db/auth/user_name.h" -#include "mongo/db/jsobj.h" namespace mongo { @@ -79,17 +76,6 @@ namespace mongo { AuthzManagerExternalState* getExternalState() const; - // Gets the privilege information document for "userName" on "dbname". - // - // On success, returns Status::OK() and stores a shared-ownership copy of the document into - // "result". - Status getPrivilegeDocument(const std::string& dbname, - const UserName& userName, - BSONObj* result); - - // Returns true if there exists at least one privilege document in the given database. - bool hasPrivilegeDocument(const std::string& dbname) const; - private: static bool _doesSupportOldStylePrivileges; @@ -99,7 +85,7 @@ namespace mongo { // This is a config setting, set at startup and not changing after initialization. static bool _authEnabled; - scoped_ptr<AuthzManagerExternalState> _externalState; + scoped_ptr<AuthzManagerExternalState> _globalExternalState; }; } // namespace mongo diff --git a/src/mongo/db/auth/authorization_session_test.cpp b/src/mongo/db/auth/authorization_session_test.cpp index d1532de0d87..aa741523bdb 100644 --- a/src/mongo/db/auth/authorization_session_test.cpp +++ b/src/mongo/db/auth/authorization_session_test.cpp @@ -19,7 +19,6 @@ #include "mongo/base/status.h" #include "mongo/db/auth/authz_session_external_state_mock.h" -#include "mongo/db/auth/authz_manager_external_state_mock.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/jsobj.h" @@ -39,16 +38,13 @@ namespace { actions.addAction(ActionType::insert); Privilege writePrivilege("test", actions); Privilege allDBsWritePrivilege("*", actions); - AuthzManagerExternalStateMock* managerExternalState = new AuthzManagerExternalStateMock(); - AuthorizationManager authManager(managerExternalState); - AuthzSessionExternalStateMock* sessionExternalState = new AuthzSessionExternalStateMock( - &authManager); - AuthorizationSession authzSession(sessionExternalState); + AuthzSessionExternalStateMock* externalState = new AuthzSessionExternalStateMock(); + AuthorizationSession authzSession(externalState); ASSERT_FALSE(authzSession.checkAuthorization("test", ActionType::insert)); - sessionExternalState->setReturnValueForShouldIgnoreAuthChecks(true); + externalState->setReturnValueForShouldIgnoreAuthChecks(true); ASSERT_TRUE(authzSession.checkAuthorization("test", ActionType::insert)); - sessionExternalState->setReturnValueForShouldIgnoreAuthChecks(false); + externalState->setReturnValueForShouldIgnoreAuthChecks(false); ASSERT_FALSE(authzSession.checkAuthorization("test", ActionType::insert)); ASSERT_EQUALS(ErrorCodes::UserNotFound, @@ -506,9 +502,6 @@ namespace { class AuthExternalStateImplictPriv : public AuthzSessionExternalStateMock { public: - AuthExternalStateImplictPriv(AuthorizationManager* authzManager) : - AuthzSessionExternalStateMock(authzManager) {} - virtual bool _findUser(const string& usersNamespace, const BSONObj& query, BSONObj* result) const { @@ -544,13 +537,11 @@ namespace { class ImplicitPriviligesTest : public ::mongo::unittest::Test { public: AuthExternalStateImplictPriv* state; - scoped_ptr<AuthorizationSession> authzSession; - scoped_ptr<AuthorizationManager> authzManager; + scoped_ptr<AuthorizationSession> authman; void setUp() { - authzManager.reset(new AuthorizationManager(new AuthzManagerExternalStateMock())); - state = new AuthExternalStateImplictPriv(authzManager.get()); - authzSession.reset(new AuthorizationSession(state)); + state = new AuthExternalStateImplictPriv; + authman.reset(new AuthorizationSession(state)); } }; @@ -569,37 +560,37 @@ namespace { "roles" << BSON_ARRAY("clusterAdmin") << "otherDBRoles" << BSON("test3" << BSON_ARRAY("dbAdmin")))); - ASSERT(!authzSession->checkAuthorization("test.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("test.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("test.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("test2.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("test2.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("test2.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("test3.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("test3.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("test3.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("$SERVER", ActionType::shutdown)); + ASSERT(!authman->checkAuthorization("test.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("test.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("test.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("test2.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("test2.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("test2.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("test3.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("test3.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("test3.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("$SERVER", ActionType::shutdown)); Principal* principal = new Principal(UserName("andy", "test")); principal->setImplicitPrivilegeAcquisition(true); - authzSession->addAuthorizedPrincipal(principal); - - ASSERT(authzSession->checkAuthorization("test.foo", ActionType::find)); - ASSERT(authzSession->checkAuthorization("test.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("test.foo", ActionType::collMod)); - ASSERT(authzSession->checkAuthorization("test2.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("test2.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("test2.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("test3.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("test3.foo", ActionType::insert)); - ASSERT(authzSession->checkAuthorization("test3.foo", ActionType::collMod)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::find)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::insert)); - ASSERT(!authzSession->checkAuthorization("admin.foo", ActionType::collMod)); - ASSERT(authzSession->checkAuthorization("$SERVER", ActionType::shutdown)); + authman->addAuthorizedPrincipal(principal); + + ASSERT(authman->checkAuthorization("test.foo", ActionType::find)); + ASSERT(authman->checkAuthorization("test.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("test.foo", ActionType::collMod)); + ASSERT(authman->checkAuthorization("test2.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("test2.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("test2.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("test3.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("test3.foo", ActionType::insert)); + ASSERT(authman->checkAuthorization("test3.foo", ActionType::collMod)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::find)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::insert)); + ASSERT(!authman->checkAuthorization("admin.foo", ActionType::collMod)); + ASSERT(authman->checkAuthorization("$SERVER", ActionType::shutdown)); } } // namespace diff --git a/src/mongo/db/auth/authz_manager_external_state.cpp b/src/mongo/db/auth/authz_manager_external_state.cpp index ebc448757f7..cf63a4d1e14 100644 --- a/src/mongo/db/auth/authz_manager_external_state.cpp +++ b/src/mongo/db/auth/authz_manager_external_state.cpp @@ -83,7 +83,7 @@ namespace mongo { return Status::OK(); } - bool AuthzManagerExternalState::hasPrivilegeDocument(const std::string& dbname) const { + bool AuthzManagerExternalState::_hasPrivilegeDocument(const std::string& dbname) const { std::string usersNamespace = dbname + ".system.users"; BSONObj userBSONObj; diff --git a/src/mongo/db/auth/authz_manager_external_state.h b/src/mongo/db/auth/authz_manager_external_state.h index 83a07bd7944..39a9b27e91b 100644 --- a/src/mongo/db/auth/authz_manager_external_state.h +++ b/src/mongo/db/auth/authz_manager_external_state.h @@ -45,10 +45,6 @@ namespace mongo { const UserName& userName, BSONObj* result); - - // Returns true if there exists at least one privilege document in the given database. - bool hasPrivilegeDocument(const std::string& dbname) const; - protected: AuthzManagerExternalState(); // This class should never be instantiated directly. @@ -58,6 +54,8 @@ namespace mongo { const BSONObj& query, BSONObj* result) const = 0; + // Returns true if there exists at least one privilege document in the given database. + bool _hasPrivilegeDocument(const std::string& dbname) const; }; } // namespace mongo diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.h b/src/mongo/db/auth/authz_manager_external_state_mock.h deleted file mode 100644 index eb0640dff37..00000000000 --- a/src/mongo/db/auth/authz_manager_external_state_mock.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (C) 2012 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/>. -*/ - -#pragma once - -#include <string> - -#include "mongo/base/disallow_copying.h" -#include "mongo/db/auth/authz_manager_external_state.h" -#include "mongo/db/jsobj.h" - -namespace mongo { - - /** - * Mock of the AuthzManagerExternalState class used only for testing. - */ - class AuthzManagerExternalStateMock : public AuthzManagerExternalState { - MONGO_DISALLOW_COPYING(AuthzManagerExternalStateMock); - - public: - - AuthzManagerExternalStateMock() {}; - - virtual bool _findUser(const std::string& usersNamespace, - const BSONObj& query, - BSONObj* result) const { - return false; - } - }; - -} // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state.cpp b/src/mongo/db/auth/authz_session_external_state.cpp index 040fbfd1561..e887cec0a72 100644 --- a/src/mongo/db/auth/authz_session_external_state.cpp +++ b/src/mongo/db/auth/authz_session_external_state.cpp @@ -23,8 +23,7 @@ namespace mongo { - AuthzSessionExternalState::AuthzSessionExternalState(AuthorizationManager* authzManager) : - _authzManager(authzManager) {} + AuthzSessionExternalState::AuthzSessionExternalState() {} AuthzSessionExternalState::~AuthzSessionExternalState() {} Status AuthzSessionExternalState::getPrivilegeDocument(const std::string& dbname, diff --git a/src/mongo/db/auth/authz_session_external_state.h b/src/mongo/db/auth/authz_session_external_state.h index bc6768eb8a6..d3e7f10b3af 100644 --- a/src/mongo/db/auth/authz_session_external_state.h +++ b/src/mongo/db/auth/authz_session_external_state.h @@ -21,7 +21,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" #include "mongo/client/dbclientinterface.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/user_name.h" namespace mongo { @@ -70,8 +69,7 @@ namespace mongo { virtual void onLogoutDatabase(const std::string& dbname) = 0; protected: - // This class should never be instantiated directly. - AuthzSessionExternalState(AuthorizationManager* authzManager); + AuthzSessionExternalState(); // This class should never be instantiated directly. // Queries the userNamespace with the given query and returns the privilegeDocument found // in *result. Returns true if it finds a document matching the query, or false if not. @@ -83,8 +81,6 @@ namespace mongo { // Returns true if there exists at least one privilege document in the given database. // TODO: remove this in favor of using the AuthzManagerExternalState bool _hasPrivilegeDocument(const std::string& dbname) const; - - AuthorizationManager* _authzManager; }; } // namespace mongo diff --git a/src/mongo/db/auth/authz_session_external_state_d.cpp b/src/mongo/db/auth/authz_session_external_state_d.cpp index 4046140ea8a..e53270508df 100644 --- a/src/mongo/db/auth/authz_session_external_state_d.cpp +++ b/src/mongo/db/auth/authz_session_external_state_d.cpp @@ -18,7 +18,6 @@ #include "mongo/base/status.h" #include "mongo/client/dbclientinterface.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/client.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/d_concurrency.h" @@ -28,9 +27,7 @@ namespace mongo { - AuthzSessionExternalStateMongod::AuthzSessionExternalStateMongod( - AuthorizationManager* authzManager) : - AuthzSessionExternalStateServerCommon(authzManager) {} + AuthzSessionExternalStateMongod::AuthzSessionExternalStateMongod() {} AuthzSessionExternalStateMongod::~AuthzSessionExternalStateMongod() {} void AuthzSessionExternalStateMongod::startRequest() { diff --git a/src/mongo/db/auth/authz_session_external_state_d.h b/src/mongo/db/auth/authz_session_external_state_d.h index 2872a2725e3..ee5295f5c80 100644 --- a/src/mongo/db/auth/authz_session_external_state_d.h +++ b/src/mongo/db/auth/authz_session_external_state_d.h @@ -18,7 +18,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authz_session_external_state_server_common.h" namespace mongo { @@ -30,7 +29,7 @@ namespace mongo { MONGO_DISALLOW_COPYING(AuthzSessionExternalStateMongod); public: - AuthzSessionExternalStateMongod(AuthorizationManager* authzManager); + AuthzSessionExternalStateMongod(); virtual ~AuthzSessionExternalStateMongod(); virtual bool shouldIgnoreAuthChecks() const; diff --git a/src/mongo/db/auth/authz_session_external_state_mock.h b/src/mongo/db/auth/authz_session_external_state_mock.h index 2fe79a4f258..a081eab45bd 100644 --- a/src/mongo/db/auth/authz_session_external_state_mock.h +++ b/src/mongo/db/auth/authz_session_external_state_mock.h @@ -18,7 +18,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authz_session_external_state.h" namespace mongo { @@ -30,8 +29,7 @@ namespace mongo { MONGO_DISALLOW_COPYING(AuthzSessionExternalStateMock); public: - AuthzSessionExternalStateMock(AuthorizationManager* authzManager) : - AuthzSessionExternalState(authzManager), _returnValue(false) {} + AuthzSessionExternalStateMock() : _returnValue(false) {} virtual bool shouldIgnoreAuthChecks() const { return _returnValue; diff --git a/src/mongo/db/auth/authz_session_external_state_s.cpp b/src/mongo/db/auth/authz_session_external_state_s.cpp index 1ddaca5914f..25caed2667f 100644 --- a/src/mongo/db/auth/authz_session_external_state_s.cpp +++ b/src/mongo/db/auth/authz_session_external_state_s.cpp @@ -20,15 +20,12 @@ #include "mongo/base/status.h" #include "mongo/client/dbclientinterface.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/jsobj.h" #include "mongo/s/grid.h" namespace mongo { - AuthzSessionExternalStateMongos::AuthzSessionExternalStateMongos( - AuthorizationManager* authzManager) : - AuthzSessionExternalStateServerCommon(authzManager) {} + AuthzSessionExternalStateMongos::AuthzSessionExternalStateMongos() {} AuthzSessionExternalStateMongos::~AuthzSessionExternalStateMongos() {} void AuthzSessionExternalStateMongos::onAddAuthorizedPrincipal(Principal*) { } diff --git a/src/mongo/db/auth/authz_session_external_state_s.h b/src/mongo/db/auth/authz_session_external_state_s.h index 0daaaf92c58..bbddf9d5e51 100644 --- a/src/mongo/db/auth/authz_session_external_state_s.h +++ b/src/mongo/db/auth/authz_session_external_state_s.h @@ -18,7 +18,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authz_session_external_state_server_common.h" namespace mongo { @@ -30,7 +29,7 @@ namespace mongo { MONGO_DISALLOW_COPYING(AuthzSessionExternalStateMongos); public: - AuthzSessionExternalStateMongos(AuthorizationManager* authzManager); + AuthzSessionExternalStateMongos(); virtual ~AuthzSessionExternalStateMongos(); virtual void startRequest(); diff --git a/src/mongo/db/auth/authz_session_external_state_server_common.cpp b/src/mongo/db/auth/authz_session_external_state_server_common.cpp index 7f75bae23aa..200eeb6f0e5 100644 --- a/src/mongo/db/auth/authz_session_external_state_server_common.cpp +++ b/src/mongo/db/auth/authz_session_external_state_server_common.cpp @@ -31,10 +31,8 @@ namespace { // NOTE: we default _allowLocalhost to true under the assumption that _checkShouldAllowLocalhost // will always be called before any calls to shouldIgnoreAuthChecks. If this is not the case, // it could cause a security hole. - AuthzSessionExternalStateServerCommon::AuthzSessionExternalStateServerCommon( - AuthorizationManager* authzManager) : - AuthzSessionExternalState(authzManager), - _allowLocalhost(true) {} + AuthzSessionExternalStateServerCommon::AuthzSessionExternalStateServerCommon() : + _allowLocalhost(true) {} AuthzSessionExternalStateServerCommon::~AuthzSessionExternalStateServerCommon() {} void AuthzSessionExternalStateServerCommon::_checkShouldAllowLocalhost() { diff --git a/src/mongo/db/auth/authz_session_external_state_server_common.h b/src/mongo/db/auth/authz_session_external_state_server_common.h index 794024eeb78..cde8d3f1919 100644 --- a/src/mongo/db/auth/authz_session_external_state_server_common.h +++ b/src/mongo/db/auth/authz_session_external_state_server_common.h @@ -18,7 +18,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" -#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authz_session_external_state.h" namespace mongo { @@ -35,7 +34,7 @@ namespace mongo { virtual bool shouldIgnoreAuthChecks() const; protected: - AuthzSessionExternalStateServerCommon(AuthorizationManager* authzManager); + AuthzSessionExternalStateServerCommon(); // Checks whether or not localhost connections should be given full access and stores the // result in _allowLocalhost. Currently localhost connections are only given full access diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index e64c2cf5088..79d5a9992b5 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -30,7 +30,6 @@ #include "mongo/base/status.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" -#include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/authz_session_external_state_d.h" #include "mongo/db/auth/privilege.h" @@ -133,8 +132,7 @@ namespace mongo { Client *c = new Client( fullDesc, mp ); currentClient.reset(c); mongo::lastError.initThread(); - c->setAuthorizationSession(new AuthorizationSession(new AuthzSessionExternalStateMongod( - getGlobalAuthorizationManager()))); + c->setAuthorizationSession(new AuthorizationSession(new AuthzSessionExternalStateMongod())); return *c; } |