summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/authz_session_external_state_s.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2013-05-30 17:00:12 -0400
committerSpencer T Brody <spencer@10gen.com>2013-05-31 17:17:06 -0400
commited8e8bde125c38db215e1fe5dfbdc2ad560ced4e (patch)
tree38a1489661827fede6b525ff43cff158a9f1e174 /src/mongo/db/auth/authz_session_external_state_s.cpp
parent0f97e5ee12313038cc9f0d62184cd98fa80fa790 (diff)
downloadmongo-ed8e8bde125c38db215e1fe5dfbdc2ad560ced4e.tar.gz
Rename Auth[Global,Session]ExternalState
Diffstat (limited to 'src/mongo/db/auth/authz_session_external_state_s.cpp')
-rw-r--r--src/mongo/db/auth/authz_session_external_state_s.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/mongo/db/auth/authz_session_external_state_s.cpp b/src/mongo/db/auth/authz_session_external_state_s.cpp
new file mode 100644
index 00000000000..25caed2667f
--- /dev/null
+++ b/src/mongo/db/auth/authz_session_external_state_s.cpp
@@ -0,0 +1,63 @@
+/**
+* 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/>.
+*/
+
+#include "mongo/db/auth/authz_session_external_state_s.h"
+
+#include <string>
+
+#include "mongo/base/status.h"
+#include "mongo/client/dbclientinterface.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/s/grid.h"
+
+namespace mongo {
+
+ AuthzSessionExternalStateMongos::AuthzSessionExternalStateMongos() {}
+ AuthzSessionExternalStateMongos::~AuthzSessionExternalStateMongos() {}
+
+ void AuthzSessionExternalStateMongos::onAddAuthorizedPrincipal(Principal*) { }
+
+ void AuthzSessionExternalStateMongos::onLogoutDatabase(const std::string&) { }
+
+ void AuthzSessionExternalStateMongos::startRequest() {
+ _checkShouldAllowLocalhost();
+ }
+
+ namespace {
+ ScopedDbConnection* getConnectionForUsersCollection(const std::string& ns) {
+ //
+ // Note: The connection mechanism here is *not* ideal, and should not be used elsewhere.
+ // If the primary for the collection moves, this approach may throw rather than handle
+ // version exceptions.
+ //
+
+ DBConfigPtr config = grid.getDBConfig(ns);
+ Shard s = config->getShard(ns);
+
+ return new ScopedDbConnection(s.getConnString(), 30.0);
+ }
+ }
+
+ bool AuthzSessionExternalStateMongos::_findUser(const string& usersNamespace,
+ const BSONObj& query,
+ BSONObj* result) const {
+ scoped_ptr<ScopedDbConnection> conn(getConnectionForUsersCollection(usersNamespace));
+ *result = conn->get()->findOne(usersNamespace, query).getOwned();
+ conn->done();
+ return !result->isEmpty();
+ }
+
+} // namespace mongo